import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; public class SwingTest { private JButton button; public SwingTest() { JFrame frame = new JFrame("SwingTest"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setBounds(100, 100, 200, 100); button = new JButton("処理できます"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { button.setText("処理中"); doHeavyProcess(); button.setText("処理できます"); } }); frame.getContentPane().add(button); frame.setVisible(true); } private void doHeavyProcess() { try { Thread.sleep(10000L); } catch (InterruptedException ex) {} } public static void main(String[] args) { new SwingTest(); } }