Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to draw in JPanel

Status
Not open for further replies.

tikual

Technical User
Jun 10, 2003
237
0
0
HK
Hi all,

I create a JFrame and add a JPanel at the center. Then how to draw something to this panel? Do I need to create a circle class or rectangle class and then add by JPanel? If yes, can anyone give me example?

Thanks a lot!

tikual
 
Hi,

Thanks for timw answer, one more question. How can I click on a same panel and it draws circle/rectangle or something according to my choice in comboBox?

Thanks

tikual
 
You would need to use a MouseListener to dectect the click.

see: java.awt.event.MouseListener

-Greg :-Q

flaga.gif
 
Hi Greg,

I have implemented MouseListener and it could draw. But I would like it draws according to my comboBox choice. How to do that?

Thanks

tikual
 
Hey there, glad you got it working so far. See
JComboBox.getSelectedItem() to get the currently selected item in the combo box. Also, you can use java.awt.Event.ItemListener and the ItemStateChanged() method to dectect the change in selection if you want to make it change dynamically.

-Greg :-Q

flaga.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top