Re: How to Refresh the System Resources Data like amount of Free
Memory.
vijju wrote:
Hi,
I am Pretty New to java swing.
I am displaying the Runtime.getSystemResource().FreeMemory Information
in the textField.
I want this information To Refresh every 10 seconds.
I don't know ,how to use Javax.swing.Timer class .
Please Help me out with this Problem.
Thanking You,
Vijay
Here is a simple example of using javax.swing.Timer to update a JLabel.
package com.knutejohnson.components;
import java.awt.*;
import java.awt.event.*;
import java.text.*;
import java.util.*;
import javax.swing.*;
public class JTimeLabel extends JLabel implements ActionListener {
private SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
private javax.swing.Timer timer = new javax.swing.Timer(250,this);
public JTimeLabel() {
super();
timer.start();
}
public JTimeLabel(String text) {
super(text);
timer.start();
}
public JTimeLabel(String text, int horizontalAlignment) {
super(text,horizontalAlignment);
timer.start();
}
public JTimeLabel(String text, int horizontalAlignment, String
pattern) {
super(text, horizontalAlignment);
this.sdf = new SimpleDateFormat(pattern);
timer.start();
}
public void actionPerformed(ActionEvent ae) {
setText(sdf.format(new Date()));
}
public static void main(String[] args) {
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(new JTimeLabel("24:00:00",JLabel.CENTER));
f.pack();
f.setVisible(true);
}
}
--
Knute Johnson
email s/nospam/knute/