Cześć wszystkim, mam mały problem z tym oto kodem, mianowicie problem jest taki, że jak nacisnę sobie guziczek STOP, to liczenie sekund się zatrzymuje i to jest ok. Problem jest w tym, że nie wiem dlaczego, ale jak próbuję wznowić liczenie przez naciśnięcie STOPA (RESUME) to mi się to liczenie nie wznawia. Pomóżcie mi z tym ludzie, bo siedzę trochę nad taką pierdołą i mnie to denerwuje :D
W sumie to chodzi mi tylko o te wznawianie, resztę zrobię samemu :)
Podczas debugowania w Eclipsie o dziwo działa powiedzmy, że dobrze.
public class Glowna extends JFrame implements ActionListener
{
private JButton b1,b2;
private JTextField t1;
private boolean stopFlag;
private Timers t;
public Glowna()
{
setSize(new Dimension(300,200));
setTitle("Okienełooo");
setLayout(null);
b1 = new JButton("Stop");
b1.setBounds(180, 100, 100, 50);
add(b1);
b1.addActionListener(this);
b2= new JButton("Clear");
b2.setBounds(180, 40, 100, 50);
add(b2);
b2.addActionListener(this);
t1 = new JTextField();
t1.setBounds(50, 50, 50, 50);
add(t1);
stopFlag=false;
t = new Timers();
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
running();
}
public void running()
{
for(; ;)
{
if(stopFlag)
break;
try
{
Thread.sleep(1000);
if(stopFlag)
break;
t.Starten();
if(stopFlag)
break;
t1.setText(String.valueOf(t.getSeconds()));
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == b1)
{
if(!stopFlag)
{
b1.setText("Resume");
stopFlag=true;
}
else
{
b1.setText("Stop");
stopFlag=false;
}
}
else if(e.getSource() == b1)
{
}
}
}
public class Timers
{
private int miliseconds,seconds,minutes;
public int getMiliseconds()
{
return miliseconds;
}
public int getSeconds()
{
return seconds;
}
public int getMinutes()
{
return minutes;
}
public void Clear()
{
miliseconds=seconds=minutes=0;
}
public void Starten()
{
seconds++;
/*if(miliseconds == 1000)
{
seconds++;
miliseconds=0;
}*/
if(seconds==60)
{
minutes++;
seconds=0;
}
}
public Timers()
{
miliseconds=0;
seconds=0;
minutes=0;
}
}
public class Program
{
public static void main(String[] args)
{
Glowna g = new Glowna();
}
}