change picture in Canvas

D

Dimitris \(GIS\)

I have a frame with
a awt.List and a awt.Canvas
I want by selecting diferent elements from the list to change my canvas
picture.
How can I do it?

I try this but it gives me NullPointerException:
if(simList.getSelectedIndex()==0){
ImageCanvas ic=new ImageCanvas("image.jpg");
simPicture.update(ic);
}
 
A

Andrew Thompson

I have a frame with a awt.List and a awt.Canvas

I have rarely found uses for the Canvas class.
Even image rendering is generally simpler to do on a Component.
I want by selecting diferent elements from the list to change my canvas
picture.
How can I do it?

- Use a number of Canvas's in a CardLayout, and flip
between them.

- Alternately, you might try refreshing the current Canvas
by either it's own methods (I am not that familiar with
them - check the API docs) or by instantiating a fresh
Canvas and refreshing the GUI.
I try this but it gives me NullPointerException:
if(simList.getSelectedIndex()==0){
ImageCanvas ic=new ImageCanvas("image.jpg");
simPicture.update(ic);
}

It sounds as though you are trying the second method
mentioned above, but (shrug) I cannot do much with
code snippets[1] and vague descriptions of errors[2].

[1] <http://www.physci.org/codes/sscce.jsp>
[2] <http://www.physci.org/codes/javafaq.jsp#exact>
 
D

Dimitris \(GIS\)

Thank you Andrew


? "Andrew Thompson said:
I have a frame with a awt.List and a awt.Canvas

I have rarely found uses for the Canvas class.
Even image rendering is generally simpler to do on a Component.
I want by selecting diferent elements from the list to change my canvas
picture.
How can I do it?

- Use a number of Canvas's in a CardLayout, and flip
between them.

- Alternately, you might try refreshing the current Canvas
by either it's own methods (I am not that familiar with
them - check the API docs) or by instantiating a fresh
Canvas and refreshing the GUI.
I try this but it gives me NullPointerException:
if(simList.getSelectedIndex()==0){
ImageCanvas ic=new ImageCanvas("image.jpg");
simPicture.update(ic);
}

It sounds as though you are trying the second method
mentioned above, but (shrug) I cannot do much with
code snippets[1] and vague descriptions of errors[2].

[1] <http://www.physci.org/codes/sscce.jsp>
[2] <http://www.physci.org/codes/javafaq.jsp#exact>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top