比如想实现Ctrl+Enter发送文本框中的内容,如何实现?

解决方案 »

  1.   

    http://hi.baidu.com/beanchx/blog/item/230e31fa0321031fa8d31183.html
      

  2.   

    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();
    }
    }