refreshing 2D Graphics screen problem
From: edward hage (edha_at_xs4all.nl)
Date: 01/13/04
- Previous message: Silvio Bierman: "Re: Java Question - Calling JavaScript"
- Next in thread: Silvio Bierman: "Re: refreshing 2D Graphics screen problem"
- Reply: Silvio Bierman: "Re: refreshing 2D Graphics screen problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 13 Jan 2004 23:38:26 +0100
The following program is an applet that reads a number from a file 10
times per second. It needs to be shown graphically.
The file monitors a procesvariable and changes continuously. It is read
okay, and also displays correct on screen (this in the form of a box
that is filled with a certain % corresponding to the value in the file.)
However, the screen only gets the initial value right. The problem I
encounter is that the display is not updated. This is because the method
paint is only performed at init, and for example when I drag the
window (appletviewer) of the screen. That part of the screen is updated.
My question: How can I make sure that every time a value is written,
that the method paint is performed. Can I make a link in class
RemindTask to paint. I tried some things but this did not work. I am a
newbie at Java. Can somebody help me out?
Thanks in advance, Edward Hage
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import javax.swing.*;
import java.io.*;
import java.util.Timer;
import java.util.TimerTask;
public class Shapes extends JApplet {
Timer timer;
Double showvalue;
// some more things //
public void init() {
timer = new Timer();
timer.schedule(new RemindTask(), 0, 100);
}
class RemindTask extends TimerTask {
public void run() {
String d;
d = ReadTopLine();
showvalue = Double.valueOf(d);
}
private String ReadTopLine() {
File inputFile = new File("showfile.txt");
// etc.
return string read from file
//
}
public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D)g;
// etc. draw a box filled with
value showvalue //
}
public static void main(String s[]) {
JFrame f = new JFrame("Shapes");
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);}
});
JApplet applet = new Shapes();
f.getContentPane().add("Center", applet);
applet.init();
f.pack();
f.setSize(new Dimension(550,100));
f.show();
}
}
- Previous message: Silvio Bierman: "Re: Java Question - Calling JavaScript"
- Next in thread: Silvio Bierman: "Re: refreshing 2D Graphics screen problem"
- Reply: Silvio Bierman: "Re: refreshing 2D Graphics screen problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|