이 프로그램에서 컴파일 및 실행에 성공했습니다. 그러나 일부 문자를 입력하면 프레임에 그 문자가 표시되지 않습니다. 왜 ? 오류는 무엇입니까?이 프로그램의 KeyAdapter 부분에 오류가 있습니다.
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
class frameadapter extends WindowAdapter
{
newframe newthis;
public frameadapter(newframe n)
{
newthis=n;
}
public void windowClosing(WindowEvent we)
{
newthis.setVisible(false);
System.exit(0);
}
}
class keyadapter extends KeyAdapter
{
newframe keythis;
public keyadapter(newframe n1)
{
keythis=n1;
}
public void KeyTyped(KeyEvent ke)
{
keythis.keymsg+=ke.getKeyChar();
System.out.println(keythis.keymsg);
keythis.repaint();
}
}
public class newframe extends Frame implements MouseListener
{
int mouseX;
int mouseY;
String keymsg="This is a Test";
String msg="";
public newframe()
{
addKeyListener(new keyadapter(this));
addWindowListener(new frameadapter(this));
addMouseListener(this);
this.setSize(600,600);
this.setVisible(true);
}
public void paint(Graphics g)
{
g.drawString(keymsg,100,100);
g.drawString(msg, 500, 200);
}
public void mouseClicked(MouseEvent e) {
mouseX=this.getX();
mouseY=this.getY();
msg="MOUSE CLICKED AT";
repaint();
}
public void mousePressed(MouseEvent e) {
mouseX=this.getX();
mouseY=this.getY();
msg="MOUSE PRESSED AT";
repaint();
}
public void mouseReleased(MouseEvent e) {
mouseX=this.getX();
mouseY=this.getY();
msg="MOUSE RELEASED AT";
this.setForeground(Color.WHITE);
this.setBackground(Color.BLACK);
repaint();
}
public void mouseEntered(MouseEvent e) {
mouseX=this.getX();
mouseY=this.getY();
msg="MOUSE ENTERED AT";
repaint();
}
public void mouseExited(MouseEvent e) {
mouseX=this.getX();
mouseY=this.getY();
msg="MOUSE EXITED AT";
repaint();
}
public static void main(String args[])
{
newframe n=new newframe();
}
}
오류는 Keyadapter 클래스에 있습니다.하지만 해결 방법을 찾을 수 없습니다. 그것은에 등록 된 구성 요소가 포커스를 가질 수 및 키보드 포커스를
Frame
을 가진 키 이벤트의 관점에서, 포커스 아니라,이 것이 불가능 그것에 만, 기본있게 때
맞습니다. 어떻게 잊어 버렸습니까? 고마워 Madprogrammer 톤. – user3414734