本帖最后由 陆旭东 于 2013-3-30 16:30 编辑
- import javax.swing.*;
- //import javax.swing.JButton;
- import javax.swing.JLabel;
- //import java.awt.AWTEvent.ComponentEvent.InputEvent.KeyEvent;
- //import java.awt.Component.*;
- //import java.util.EventListener.*;
- import java.awt.event.*;
- public class EventDemo extends JFrame{
- /**
- * @param args
- */
- private JTextField textField1;
- private JTextField textField2;
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- EventDemo frame=new EventDemo();
- frame.setVisible(true);
- }
- public EventDemo(){
- super();
- getContentPane().setLayout(null);
- setBounds(100,100,305,113);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- textField1=new JTextField();
- textField1.addKeyListener(new TextKeyListerner());
- textField1.setBounds(115,12,172,22);
- getContentPane().add(textField1);
- textField2=new JTextField();
- textField2.setBounds(115,40,172,22);
- getContentPane().add(textField2);
- final JLabel label=new JLabel();
- label.setText("第一个文本框:");
- label.setBounds(10,12,99,18);
- getContentPane().add(label);
- final JLabel label_1 =new JLabel();
- label.setText("第二个文本框:");
- label.setBounds(10,40,99,18);
- getContentPane().add(label_1);
- }
- private final class TextKeyListerner implements KeyListener{
- public void keyPressed(KeyEvent e){
-
- }
- public void keyReleased(KeyEvent e){
- String text = textField1.getText();//获取第一个文本框的字符串
- textField2.setText(text);//赋值给第二个文本框
- }
- public void keyTyped(KeyEvent e){
-
- }
- }
- }
复制代码 请问这段代码的运行后为什么第一个文本框之前的标签”第一个文本框“怎么不会显示。看不出什么问题…… |