I have a small query please let me explain the scenario. I have a swing jframe in which i have a button named "start" which starts the timer in seconds so whenever i click on start it converts the the button itself to "reset" which should make the seconds to zero and should again convert itself to "start". My concern is for these both scenarios i have to run two set of codes for which i used two classes which implements ActionListener interface is there any way to include these two set of codes in the same class which implements ActionListener, and switch the block of code depending on a boolean variable which changes its value as the button changes.
I tried it but i am facing performance issues like freezing the application and not even working exactly as expected.
please review my code below.
public class SuperTimer extends JFrame
{
JButton start;
private final StartCountDown countdown;
public SuperTimer()
{
countdown= new StartCountDown();
start.addActionListener(countdown);
}
public class StartCountDown implements ActionListener
{
public void actionPerformed(ActionEvent l)
{
if(l.getSource()==start)
{
count = Long.parseLong(input.getText());
start.setText("Reset");
reset = new Reset();
start.removeActionListener(countdown);
start.addActionListener(reset);
invalid.setVisible(false);
}
TimeClass tc = new TimeClass(count);
timer = new Timer(1000,tc);
timer.start();
}
}
public class Reset implements ActionListener
{
public void actionPerformed(ActionEvent j)
{
start.setText("Start");
time.setText("00:00:00");
input.setText("");
timer.stop();
timeup.setVisible(false);
start.removeActionListener(reset);
start.addActionListener(countdown);
}
}
}**