Hi all,

I'm about to start on my Java course next semester. Since I've only coded in C/C++ til now, I'm a bit stumped. I'll give you an assignment from last year, maybe some of you guys can show me how this program would look like in Java.

Here goes:

Create a JFrame window (with BorderLayout).
There are two ComboBoxes in the bottom.
In the first ComboBox, the user can select the amount of figures
In the second ComboBox, the user can select the figure desired (triangle, square, circle)
After selecting the desired values from the combobox and clicking anywhere,
the selected amount of the desired figures appear on random coordinates in the

By pressing the "Enter" key, you can erase the drawn figures (the amount turns to 0)

By pressing the up-arrow and down-arrow keys, you can make the figures bigger or smaller.

I really hope some of you guys can help me out on this one. Cheers.

5 Years
Discussion Span
Last Post by muff1n

you want to use graphics. You also want to implement MouseMotionListener, and KeyListener, which are both located in java.awt.event. I suggest you look through the API docs to find out how to make a JFrame, and how to set the layout. But the combo box and JFrame are located in javax.swing.

I cannot help you more, unless you have a specific issue. We do not do your homework/assignments here. We just help.


Didn't mean for you to complete the task, any help is appreciated.
Alright, so I've created the JFrame and successfully created the two ComboBoxes. How can I make the code work so that when certain values from the Boxes are selected, it actually uses them when painting the required figures? How can I tie the ComboBox values to the rest of the program?


you can either get the choice selected from the combo box, or you can add a change listener to the combo box and set the value in the change listener. Look through the combo box API doc, and see if you can find anything that can help you fix your problem.


Okay, I've got most of the code done. At first I created a button. By clicking on it (via actionListener), the figures would be drawn to certain coordinates. Now I'm trying to implement mouseListener so that the figures would appear to wherever the user clicks.
Since the whole code is in 3 different files, I've packed them into a single .rar. You can find it @ http://www.upload.ee/files/1592409/KOOD.rar.html .

What's wrong with the code?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.