Print Window Close Window
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class GUICountdown implements ActionListener { private JFrame frame; private JButton button; private Container contentPane; private JLabel label; public static void main (String[] args) { GUICountdown guiCount = new GUICountdown(); guiCount.start(); } public void start() { frame = new JFrame("GUI Countdown"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); contentPane = frame.getContentPane(); button = new JButton("Countdown Button"); button.addActionListener(this); contentPane.add(button); frame.setSize(300,300); frame.setVisible(true); } public void actionPerformed(ActionEvent e) { button.setForeground(Color.red); switch (button.getText()) { case "Countdown Button": button.setText("Five"); break; case "Five": button.setText("Four"); break; case "Four": button.setText("Three"); break; case "Three": button.setText("Two"); break; case "Two": button.setText("One"); break; case "One": button.setVisible(false); label = new JLabel("Congratulations!!! You've reached ZERO!"); contentPane.add(label); break; } } } Print Window Close Window
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class GUICountdown implements ActionListener { private JFrame frame; private JButton button; private Container contentPane; private JLabel label; public static void main (String[] args) { GUICountdown guiCount = new GUICountdown(); guiCount.start(); } public void start() { frame = new JFrame("GUI Countdown"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); contentPane = frame.getContentPane(); button = new JButton("Countdown Button"); button.addActionListener(this); contentPane.add(button); frame.setSize(300,300); frame.setVisible(true); } public void actionPerformed(ActionEvent e) { button.setForeground(Color.red); switch (button.getText()) { case "Countdown Button": button.setText("Five"); break; case "Five": button.setText("Four"); break; case "Four": button.setText("Three"); break; case "Three": button.setText("Two"); break; case "Two": button.setText("One"); break; case "One": button.setVisible(false); label = new JLabel("Congratulations!!! You've reached ZERO!"); contentPane.add(label); break; } } }