I have a counter that counts ne the amount of time
I noticed when I opened the task manager that with every second the memory used by the application increases, which is not good
How to use variables so that the memory is recklessly not wasted
When I read the FAQ I found out that you can't just use string variables. You need to use a StringBuffer or StringBuilder to change it frequently.
Since I have such information displayed in the application, I will give a small sample of code without libraries and the rest of the unnecessary code.
public static StringBuffer time_buffer = new StringBuffer(); public void timerStart() { timer = new Timer(1000, new ActionListener() { public void actionPerformed(ActionEvent e) { time_buffer.setLength(0); time_buffer.append(Long.toString(System.currentTimeMillis()/1000)); jLabel.setText(time_buffer); ///Здесь условие выхода и остановка таймера timer.stop(); } } } public static void main() { Frame window = new Frame(); window.setVisible(true); timer.start(); window.timerStart(); }
jLabel.setText(Long.toString(System.currentTimeMillis()/1000));? - Nofate ♦