Program
This program is intended to give you experience building a basic GUI application with Java Swing. You will utilize a few different JComponents and pop up a modal dialog upon a button press. More specifically, your program is meant to simulate a “Magic 8-Ball” program, where the user of your program has the ability to ask a yes/no question, and a random yes/no response is provided. Your program must meet the following requirements:
• the GUI look and feel is up to you
• utilize at least 1 JLabel, 1 JTextField, and 1 JButton
• set the window title, icon, and default close behavior to exit
• pop up a modal dialog with the randomly selected response
• at least 7 different responses (3 affirmative, 3 negative, 1 noncommittal)
• no pop up message if no question is asked
See the Example Output for our implementation of this assignment. Your implementation does not have to look like this; it only needs to support the requested functionality.
(a) Components
Use the Swing examples in this course, or tutorials online, to help you create a GUI that you are happy with and that supports the requested functionality. Start simple and build up. Your main class should extend JFrame so that your program is inherently a Java Swing window. Setup your window by changing the window title, specifying a new window icon, setting the desired size, and specifying the default close behavior to exit the program when closed. Once your window is to your liking, concentrate on the window’s layout manager and adding the required components to it. You can use any layout manager you want (see a Visual Guide to Layout Managers). You can also add any components you want beyond what is required.
Here is an example with the minimum requirements:
Events
Your program must contain at least 1 JButton for the user to press to submit their question to be answered. When the button is pressed, it will trigger an ActionEvent. You can handle this event inline, but it is cleaner and recommended to make your class listen for this event and handle it in a separate method. One easy way to do this, is to have your class implement the ActionListener interface and override the actionPerformed() method.
Responses
Your program must at least support the following response types:
• strongly affirmative
• affirmative
•slightly affirmative
• strongly negative
• negative
•slightly negative
• noncommittal
Your program may support more responses if desired.
This assignment has been answered 5 times in private sessions.
Or buy a ready solution below.
© 2024 Codify Tutor. All rights reserved