help req. in designing dynamic images
Hi,
I am designing a GUI, and I want to display some dynamic images ...I am trying to display CPU Temperature, CPU power consumption, etc....One example of the image changing dynamically is shown on this link
http://www.snapstream.com/images/blog/godzilla/overheating_max_cpu_tn.jpg
Can I do it by Java Swing? If not, how can i do that?
Hope to hear from you soon. Thanks in advance..
Ankit
I don't have any examples handy, but there are lots of similar examples online in the tutorials.
But basically....in Swing, apparently the method you override to change a component's painting behavior is paintComponent:
public void paintComponent(Graphics g) {
}
java.awt.Graphics has a drawImage method, so you can do this:
public void paintComponent(Graphics g) {
g.drawImage(0, 0, imageOfAMeter);
}
and then you could draw a line on top of that, which would go vaguely like this:
public void paintComponent(Graphics g) {
g.drawImage(0, 0, imageOfAMeter);
g.drawLine(50, 50, 10, 20);
}
except, you wouldn't hardcode the needle values, you'd probably do something more like this:
public void paintComponent(Graphics g) {
g.drawImage(0, 0, imageOfAMeter);
Point end = figureEndpointOfNeedleBasedOnCurrentState();
g.drawLine(needleBase.x, needleBase.y, end.x, end.y);
}
and furthermore you'd have a method on your new object to set its state, something like this:
public void setTemperature(double t);
Then all this stuff could go in a subclass of, I guess, JComponent.
Anyway, this should all be pretty simple. Read the Swing tutorials and you should see plenty of examples. Ask on the Swing forums for Swing-specific issues.