...
Code Block |
---|
JLabel infoLbl = new JLabel(); infoLbl.setText("Enter text here:"); controlPnl.add(infoLbl); JTextField infoTF = new TextFieldJTextField("default text"); infoTF.setPreferredSize(new java.awt.Dimension(75, 23)); // set default text field size to 75x23 pixels. infoTF.addActionListener(new ActionListener() { /** * This method runs when "Enter" is pressed after entering text into the text field. */ public void actionPerformed(ActionEvent evt) { String text = infoTF.getText(); // the text of the text field. // Do stuff here. Generally, delegate to a non-GUI object (the "model"). } }); controlPnl.add(infoTF); |
...