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 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?
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.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.