5
Explanation:
I have a component JTextField
that would be a regressive counter, but when I use the ActionListener
in this way:
public static ActionListener alredBGolem = new ActionListener() {
public void actionPerformed(ActionEvent evt) {
redBGolem.setText(String.valueOf(tempoRedBGolem));
tempoRedBGolem--;
}
};
It works correctly, but when it calls a function:
public static JTextField redBGolem = new JTextField();
private static int tempoRedBGolem = 300;
private static Timer timerRedBGolem = new Timer(1000, alredBGolem);
public static ActionListener alredBGolem = new ActionListener() {
public void actionPerformed(ActionEvent evt) {
count(redBGolem,timerRedBGolem,tempoRedBGolem,1);
}
};
public static void count(JTextField Field, Timer cTimer, int Tempo, int Type){
Field.setText(String.valueOf(Tempo));
Tempo--;
System.out.println(Tempo);
}
He just prints it 299
repeatedly and the JTextField
does not leave the 300
.
How to solve this problem?
Thank you @utluiz worked with the counter class, I’m using the transparent background on
JtextFiel
only when it changes the content it gets all scrambled as if it prints one number on top of the other, you know what ? I’m using thebackground
thus:redBGolem.setBackground(new Color(1.0f,1.0f,1.0f,0f));
– tissei
@alleen94 I’m not much of that part of GUI, but try calling the method
repaint()
component element or methodrevalidate()
of the panel containing it.– utluiz