package pages; import javax.swing.*;import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener; public class page411 extends JFrame { private JTextField tf = new JTextField(20); private JTextArea ta = new JTextArea(7,20); public page411(){ setTitle("TextArea Example"); setDefaultCloseOperation(EXIT_ON_CLOSE); Container c = getContentPane(); c.setLayout(new FlowLayout()); c.add(new JLabel("Press Enter after input entry")); c.add(tf); c.add(new JScrollPane(ta)); tf.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JTextField t = (JTextField)e.getSource(); //getting a source to mention the object it is listening to ta.append(t.getText() + "\n"); //t.getText gets user text input //attaching TextField to textArea
//textField is to get an user input t.setText(""); //removing content in TextField } }); setSize(300,300); setVisible(true); } public static void main(String [] args){ new page411(); } }
댓글
댓글 쓰기