首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

请问java程序中组合键的使用

2012-01-01 
请教java程序中组合键的使用比如想实现Ctrl+Enter发送文本框中的内容,如何实现?[解决办法]http://hi.baidu

请教java程序中组合键的使用
比如想实现Ctrl+Enter发送文本框中的内容,如何实现?

[解决办法]
http://hi.baidu.com/beanchx/blog/item/230e31fa0321031fa8d31183.html
[解决办法]
public class Test extends JFrame implements KeyListener{
JTextArea jt1,jt2;
public Test(){
this.setSize(250,200);
Container con = this.getContentPane();
JPanel jp = new JPanel();
jp.setLayout(new BorderLayout());
jt1 = new JTextArea();
jt1.setEnabled(false);
jt1.setBackground(Color.lightGray);
jt2 = new JTextArea();
jt2.addKeyListener(this);
jp.add(jt1,BorderLayout.CENTER);
jp.add(jt2,BorderLayout.SOUTH);
con.add(jp);
this.setLocation(100,100);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
//this.pack();
}
public void keyTyped(KeyEvent e){
if(e.getKeyChar()== e.VK_ENTER){
jt1.setText(jt2.getText());
jt2.setText( " ");
}
}
public void keyReleased(KeyEvent e){}
public void keyPressed(KeyEvent e){}
public static void main(String[] args){
new Test();
}
}

热点排行
Bad Request.