Answered step by step
Verified Expert Solution
Question
1 Approved Answer
How to set up a simple GUI based on JFrame Setting up listeners and responding to events Drawing simple shapes Dealing with mouse and mouse
How to set up a simple GUI based on JFrame Setting up listeners and responding to events Drawing simple shapes Dealing with mouse and mouse motion events 1. Write a GUI application in Java using Swing that has three buttons and a drawing area. 2. Give the window an initial size of 800 times 800 pixels, and put your name in the menu bar. 3. The buttons should be at the top of the window and be labeled "Ova Rectangle", and "Special". 4. The drawing area should cover the remainder of the window. 5. When it starts, the program should show nothing in the drawing area, but the background of the drawing area should be a non-white color. 6. Pressing the Oval or Rectangle buttons should toggle (turn on or off the display of an oval or rectangle, either or both of which must be visible at the same time. When drawn, the oval and rectangle should be different colors of your choice. 7. You must also be able to click and drag the rectangle or oval around the screen with the mouse. 8. When the user presses the "special" button, the program should do something else not described in the assignment that is unique to your program, such as change the color of all the things you draw, switch the oval to be outlines instead of filled, or draw your name in the middle of the window. 9. As always, make sure the proper block comment is at the top of your main file with your name. 10. Once your program is working, pass it off directly to the instructor or TA. Also, turn in your code to D2L. Get the skeleton of your GUI working first. First get the buttons drawing properly, then go on to listen to and respond to events. Initially, hook up the event listeners so that they print something to the console when a button is pressed. That way you can know that your code is getting events. Make a subclass of JPanel called "DrawPanel" or something like that to draw the objects. Override the "paintComponent" method of this class. This class needs boolean variables to decide whether to draw the rectangle, oval, your name, and the special. It may also need other variables to indicate colors, positions of things, etc. You can measure a string using the FontMetrics class. This measures how much space (in pixels) the string will take when drawn. You would use this information to determine where to place the text and backing rectangle
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started