Posted on 2008-12-12 11:41
ZhouFeng 阅读(397)
评论(0) 编辑 收藏 所属分类:
转载 、
JAVA
这段代码可以实现
public class Test {
private boolean isPressed = false;
public void show(){
JFrame frame = new JFrame();
MyTableModel tableModel=new MyTableModel();
JTable table=new JTable(tableModel);
JTextArea text = new JTextArea(3,20);
text.addKeyListener(new KeyAdapter(){
public void keyPressed(KeyEvent e) {
if(KeyEvent.VK_CONTROL == e.getKeyCode()){
isPressed = true;
}
if(e.getKeyCode() == KeyEvent.VK_ENTER && isPressed){
JOptionPane.showMessageDialog(null,"Ctrl+Enter was pressed.");
}
}
public void keyReleased(KeyEvent e){
System.out.println(e.getKeyCode());
if(KeyEvent.VK_CONTROL == e.getKeyCode() || KeyEvent.VK_ENTER == e.getKeyCode()){
isPressed = false;
}
}
});
frame.getContentPane().add(new JScrollPane(text));
frame.setSize(300,400);
frame.show();
}
public static void main(String[] args){
Test test = new Test();
test.show();
}
}