java KeyTyped问题! 在线等待!
importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;publicclassEx2_3extendsJF...
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Ex2_3 extends JFrame{
private Container container;
private JTextField field;
public Ex2_3()
{
super("我猜猜猜");
field=new JTextField(20);
getContentPane().add(field);
field.setEditable(true);
field.addKeyListener(new KeyListener(){
public void keyPressed(KeyEvent event) {}
public void keyReleased(KeyEvent event){}
public void keyTyped(KeyEvent event)
{String a="Key typed:"+event.getKeyChar();
field.setText(a); }
});
setSize(500,300);
setVisible(true);}
public static void main(String args[])
{
new Ex2_3();
}
}
运行后,当我按u,会出现两个u,也就是 按每个键,都会显示为两个,个人认为是字符与字节的问题,可是如何解决呢? 展开
import java.awt.event.*;
import javax.swing.*;
public class Ex2_3 extends JFrame{
private Container container;
private JTextField field;
public Ex2_3()
{
super("我猜猜猜");
field=new JTextField(20);
getContentPane().add(field);
field.setEditable(true);
field.addKeyListener(new KeyListener(){
public void keyPressed(KeyEvent event) {}
public void keyReleased(KeyEvent event){}
public void keyTyped(KeyEvent event)
{String a="Key typed:"+event.getKeyChar();
field.setText(a); }
});
setSize(500,300);
setVisible(true);}
public static void main(String args[])
{
new Ex2_3();
}
}
运行后,当我按u,会出现两个u,也就是 按每个键,都会显示为两个,个人认为是字符与字节的问题,可是如何解决呢? 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询