/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package testeventlistners; import java.awt.*; import java.awt.event.*; import javax.swing.*; /** * * @author admin */ public class TestEventListners { /** * @param args the command line arguments */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { MySimpleNotebook frame = new MySimpleNotebook(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } }); } } class MySimpleNotebook extends JFrame{ public MySimpleNotebook(){ setBounds(100, 100, 500, 500); //Container c = getContentPane(); tf = new JTextField ("Сюда Вводить Текст",50); add(tf,BorderLayout.NORTH); //компоновка ta = new JTextArea(); ta.setEditable(false); add(ta); JPanel p = new JPanel(); add(p,BorderLayout.SOUTH); b = new JButton("Перенести"); p.add(b); tm = new TextMove(tf,ta); tf.addActionListener(tm); b.addActionListener(tm); } private JTextField tf; private JTextArea ta; private JButton b; private TextMove tm; } class TextMove implements ActionListener { private JTextField tf; private JTextArea ta; TextMove (JTextField f, JTextArea a) { tf=f; ta=a; } public void actionPerformed(ActionEvent e) { ta.append(tf.getText()+"\n"); }}