NOTE: My English isn't the best so please don't mind too much Grammar mistakes.
Hey there, Java Starter here, anyways i was writing my CPS Test program, and i found a bug i can't figure out. this question may got asked before but i couldn't use the .equals function.
Code:
boolean wait = false;
times2 times2 = new times2(0, false);
times2.setTimes(0);
final AtomicInteger times = new AtomicInteger(0);
b1.addActionListener(new ActionListener() {
final AtomicInteger clicks = new AtomicInteger(0);
@SuppressWarnings("unlikely-arg-type")
public void actionPerformed(ActionEvent e) {
System.out.println("Console> startTest;");
// This if condition won't work.
if(times.equals(times2.getTimes())) {
b1.setText("3");
try {
TimeUnit.SECONDS.sleep((long)1.0);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
b1.setText("2");
try {
TimeUnit.SECONDS.sleep((long)1.0);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
b1.setText("1");
try {
TimeUnit.SECONDS.sleep((long)1.0);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
b1.setText("CLICK!");
times.incrementAndGet();
times2.setWait(true);
}else if(!times.equals(times2.getTimes())){
clicks.incrementAndGet();
}
if(times2.getWait() == true) {
try {
TimeUnit.SECONDS.sleep((long)10.0);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
JLabel text2 = new JLabel("");
Font f = new Font(null, Font.BOLD , 0);
Font size = f.deriveFont(45f);
double clicks2 = clicks.get();
double results = clicks2/10;
text2.setText("<html> Your final Results: <html> " + "<html> <br> <html>" + results);
text2.setFont(size);
text2.setPreferredSize(new Dimension(100,100));
JFrame end = new JFrame();
end.setPreferredSize(new Dimension(350,350));
end.setMaximumSize(new Dimension(450,450));
end.setLocationRelativeTo(null);
end.setTitle("RESULTS");
end.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
end.pack();
end.setVisible(true);
end.getContentPane().add(text2, BorderLayout.CENTER);
}
}
});
times2.java:
public class times2 {
private int times;
private boolean wait;
public times2(int times2, boolean wait2) {
this.times = times2;
this.wait = wait2;
}
public int getTimes() {
return times;
}
public void setTimes(int times) {
this.times = times;
}
public boolean isWait() {
return wait;
}
public void setWait(boolean wait) {
this.wait = wait;
}
public boolean getWait() {
// TODO Auto-generated method stub
return false;
}
}
If you know whats wrong Please respond to this post.