还有,怎么判断jtextfield 里的文本 是否是数字?
解决方案 »
- linux crond 定时tomcat ,tomcat乱码问题。
- 在深度为5的二叉树中,度为2的结点最多为?为什么是15?
- 关于ArrayList数组输出的一个问题
- timer在java中怎么使用的
- 太困了,撒分算了!
- 有关java程序在浏览器中显示方面的问题?
- synchronized加在方法前,锁作用范围?
- 呵呵,来备份一个函数 关于 * 匹配文件名的东西(就是在一个文件夹下面找一类文件的东西)。有需要的也可以参考 一下
- 那里可以下载JAVA的类库
- SUN said:C++将要在两年内被JAVA取代,真的吗?
- 一个简单的application编译错误不明白其原因。
- 把ASCII编码转换成为BCD编码
判断backspace你也用getKeyChar()试一试吧。
import java.awt.event.*;
public class TestwindowListener{
public static void main(String args[]){
Frame f = new Frame("Test");
Button btn1 = new Button("press me");
Button btn2 = new Button("press here");
TextArea ta = new TextArea();
Monitor bh = new Monitor();
monitor1 kl = new monitor1();
btn2.setActionCommand("Game over");
ta.addKeyListener(kl);
f.add(btn1,"Center");
f.add(btn2,"North");
f.add(ta,"West");
f.addWindowListener(bh);
f.pack();
f.setVisible(true);
}
}
class monitor1 implements KeyListener{
public void keyTyped(KeyEvent e){
System.out.println(e.KEY_EVENT_MASK);
}
public void keyPressed(KeyEvent e){
System.out.println(e.KEY_EVENT_MASK);
}
public void keyReleased(KeyEvent e){
System.out.println(e.KEY_EVENT_MASK);
}
}
class Monitor implements WindowListener{
public void windowActivated(WindowEvent e){
System.out.println("1");
System.out.println(KeyEvent.VK_BACK_SPACE);
}
public void windowClosed(WindowEvent e){
System.out.println("2");
}
public void windowClosing(WindowEvent e){
System.exit(0);
System.out.println("3");
}
public void windowDeactivated(WindowEvent e){
System.out.println("4");
}
public void windowDeiconified(WindowEvent e){
System.out.println("5");
}
public void windowIconified(WindowEvent e){
System.out.println("6");
}
public void windowOpened(WindowEvent e){
System.out.println("7");
}
}