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

[429 byte] By [usc_trojana] at [2007-11-27 7:37:05]
# 1
Sure. Write a component that draws itself by first drawing the background image, and then draws the needle based on whatever state the component represents.
paulcwa at 2007-7-12 19:17:36 > top of Java-index,Java Essentials,Java Programming...
# 2
Do you have any examples online? I am new to Java programming..I read Java Swing and almost completed half of the tutorials..I would appreciate if you can help me in a lil bit more detail
usc_trojana at 2007-7-12 19:17:36 > top of Java-index,Java Essentials,Java Programming...
# 3
Do you have any examples online? I am new to Java programming..I read Java Swing and almost completed half of the tutorials..I would appreciate if you can help me in a lil bit more detail
usc_trojana at 2007-7-12 19:17:36 > top of Java-index,Java Essentials,Java Programming...
# 4
Do you have any examples online? I am new to Java programming..I read Java Swing and almost completed half of the tutorials..I would appreciate if you can help me in a lil bit more detail
usc_trojana at 2007-7-12 19:17:36 > top of Java-index,Java Essentials,Java Programming...
# 5
Do you have any examples online? I am new to Java programming..I read Java Swing and almost completed half of the tutorials..I would appreciate if you can help me in a lil bit more detail
usc_trojana at 2007-7-12 19:17:36 > top of Java-index,Java Essentials,Java Programming...
# 6

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.

paulcwa at 2007-7-12 19:17:36 > top of Java-index,Java Essentials,Java Programming...