Hello! My name is Joel and is kinda new to java programming. I got a problem. I want to make 4 buttons on a Panel that has 4 different timers. When i press the first one i want it to take 5 minutes and then pop up a screen with a text like this "Your eggs are ready". And i want different timers on all of the buttons. I did succed with one button but cant figure out how i can add listeners to any more buttons. And how do i add delay in a while loop?
Thanks for the replies! Have a nice day!package bluered.timer; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Scanner; import javax.swing.JButton; import javax.swing.JFrame; import java.io.*; import javax.swing.JLabel; import javax.swing.JOptionPane; import sun.audio.*; import static javax.swing.JOptionPane.*; import javax.swing.JPanel; public class BlueRedTimer { public static void main(String args[]) { JFrame frame=new JFrame("Test"); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(300,80); JPanel panel=new JPanel(); frame.add(panel); JButton button=new JButton("Timer1"); JButton button2=new JButton("Timer2"); JButton button3=new JButton("Timer3"); JButton button4=new JButton("Timer4"); panel.add(button); panel.add(button2); panel.add(button3); panel.add(button4); button.addActionListener(new Action()); button2.addActionListener(new Action()); } static class Action implements ActionListener { public void actionPerformed(ActionEvent e){ int Blue=300; //I want the "blue" timer to be set at 5 minutes. So when i press button timer1 it will start a countdown of 5 minutes and then a screen pops up. while (Blue>0){ Blue--; System.out.println(Blue); } if (Blue==0){ JOptionPane.showMessageDialog(null, "Timer one is ready!");} } }}