import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JTextField; import static javax.swing.SwingUtilities.invokeLater; import static javax.swing.WindowConstants.DISPOSE_ON_CLOSE; public class Test8011005 implements ActionListener, Runnable { public static void main(String[] args) { invokeLater(new Test8011005()); } public JTextField text; @Override public void actionPerformed(ActionEvent event) { this.text.setEditable(!this.text.isEditable()); } @Override public void run() { this.text = new JTextField("abcdefghijklmnopqrstuvwxyz"); JButton button = new JButton("press"); button.addActionListener(this); JFrame frame = new JFrame(getClass().getSimpleName()); frame.add(BorderLayout.CENTER, this.text); frame.add(BorderLayout.EAST, button); frame.pack(); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE); frame.setVisible(true); } }