Question
I need help with this FortuneTeller.java. GUI Here is the provided file *********************************************************************************************************************** import java.awt.*; // the basic awt functionality import javax.swing.*; // java's awesome
I need help with this FortuneTeller.java. GUI
Here is the provided file
***********************************************************************************************************************
import java.awt.*; // the "basic" awt functionality import javax.swing.*; // java's awesome swing functionality import java.awt.event.*; // necessary for event listeners
// A FortuneTeller class that extends the JFrame class public class FortuneTeller extends JFrame {
// This class's default, no-argument constructor public FortuneTeller() { }
// Create the panel, with the necessary components private void buildPanel() { }
// A private INNER class that implements an event listener. // Recall that the actionPerformed method below // is invoked when the calcButton in the GUI is clicked. private class CalcButtonListener implements ActionListener {
// The required method, which ActionListner requires public void actionPerformed(ActionEvent e) { }
}
// The "main" routine, where it all begins public static void main(String[] args) { } }
*********************************************************************************************************
END
This lab is meant to acquaint you with GUIs, which we've started discussing in lecture. You'l1 modify, expand, and improve the ABetterWindow.java GUI application that was shown in lecture, and also add an event listener, which will enable you to respond to a person's mouse clicks Introduction The goal of this lab is for you to make a Fortune Teller GUI. A user asks a question, and the application responds accordingly, based on whether the question is a "why," "where," "who," etc. questions. Two sample invocations of the Fortune Teller GUI are shown in Figure 1 The crystal ball says... Message Ask me a question!: When is Monday iProbably not before tomorrow! Tell me now OK The crystal ball says... Message Ask me a question!! Why is 1+1-2? l) Because that's how it is! Tell me now OK Figure 1: Two sample invocations of the?omus.Lellet GUI: the GUI's response is shown on the right I. Structuring a class file for a GUI application The sample code, ABetterWindow.java, that was shown in lecture, was a very simplified, non modular version of a GUI application. In that code, the entirety of java's swing commands were placed into the main method. That example was a good, bare-bones version of a GUI, that was meant to get the main idea across. However, the better, more accepted approach, to writing a GUI application, is to modularize the different parts of a graphical program into the following: 1) a constructor, 2) a method that builds the main panel, 3) a private, inner class that implements an ActionListener, and 4) a main method The code in Figure 2 is the skeleton of a properly modularized class file, for writing a simple GUI application. ActionListeners have not yet been fully discussed in lecture. However, it has been mentioned that an ActionListener "listens" for an event (a button is clicked, a slider is moved, etc.), and that specific code is executed whenever an event occurs. For the sake of thisStep 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