Question

JAVA CODING

Must be compilable, thanks

The purpose is to provide an exercise in event-driven programming and image handling using JavaFX. Create an application that responds to the user clicking command buttons. Initially, it will display one of two graphic images and, based upon the button clicked by the user, will switch the image displayed. If the user clicks the mouse button to display the same image as is currently displayed, the image is not changed, but a message at the bottom of the screen informs them of the result.

Use appropriate Layout managers to allow the user to resize without changing the relative location of the components. Run my downloadable class to see behavior. Review the use of Layout managers, panes, labels, and methods to get/set text and to set images for display as well as event handlers.???

use the well-known Lucy cartoon character from the Peanuts® comic strip.

When "the doctor is in", we see Lucy at her booth and the sign on the booth says, "The doctor is in."

When the "doctor is out", Lucy is gone and the sign says, "The doctor is out."

Two buttons will display below the graphic, so the user can click one or the other to change the status. A status message will appear below the buttons to indicate the result of the user clicking a button.

Use the two images shown below for the program

PSYCHIATRIC HELP 54 THE DOCTOR IS IN

(right-click, Save as Picture.) Sample output is shown next.

As the application begins, Lucy is displayed as “in” with message text of "The doctor is in" displayed. The font for the message is Arial Bold.

If the user clicks the "in" button again (while the doctor is "in"), the image does not change, but the message at the bottom is updated to "The doctor IS IN, already!".

If the doctor was "out", then clicking the "in" button causes Lucy to be displayed with the "in sign", and the message is updated to indicate that the doctor is in, as in the first example.


When the user clicks the "out" button, the "doctor is out" image is displayed, along with the status message updated to reflect the doctor being out.

As above, if the user clicks the "out" button again (while the doctor is out), the message at the bottom is updated to "The doctor IS OUT, already!"

If the doctor was "in", then clicking the "out" button causes the "out" image and message to be displayed.

change the message color to red when the user clicks the same button twice in a row (the “already” messages) and reset to black when they click the other button.

Make sure that the title bar displays CIS 263 and your name where this example shows “Event-Driven”.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.awt.*;
import java.awt.EventQueue;
import java.awt.event.*;
import javax.swing.*;
//Class Doctor Availability
public class DoctorAvailability extends JFrame implements ActionListener
{
   //Doctor in out status for button message
   private static String DOCTOR_IN = "in";
   private static String DOCTOR_OUT = "out";
   //Font object created
   Font fA;
   //Image object created
   private Image image = null;
   //For image status
   private String imgStatus = " ";
   //Lable to display message
   JLabel status;

   //Parameterized constructor
   public DoctorAvailability(String titleMessage)
   {
       //Set the title of frame
   setTitle(titleMessage);

       //Closes the frame by clicking close icon on window
   setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

       //Size of frame
       setSize(300, 400);

       //Image initialization
       image = new ImageIcon().getImage();

       //Container Layout
       Container container = getContentPane();
       container.setLayout(new BorderLayout());
       container.add(createControls(), BorderLayout.SOUTH);
   }

   //Panel creation
   private JPanel createControls()
   {
       //Creates a button for Doctor IN
   JButton doctorIn = new JButton("Click for in");

       //Adds action listiner
   doctorIn.addActionListener(this);
       doctorIn.setActionCommand(DOCTOR_IN);

       //Creates a button for Doctor OUT
       JButton doctorOut = new JButton("Click for out");

       //Adds action listiner
   doctorOut.addActionListener(this);
   doctorOut.setActionCommand(DOCTOR_OUT);

       //Creates Panel and sets layout
   JPanel panel = new JPanel();
   panel.setLayout(new GridLayout(3,1));

       //Font created with arial bold size is 14
       fA = new Font("Arial", Font.BOLD, 14);
       //Sets the label data to null
       status = new JLabel("");
       //Sets the font for the label
       status.setFont(fA);

       //Adds buttons and label to the panel
   panel.add(doctorIn);
   panel.add(doctorOut);
       panel.add(status);

   return panel;
   }

   //Overides paint method
   public void paint(Graphics g)
   {
   super.paint(g);
       //Displays the image
       g.drawImage(image, 50, 50, image.getWidth(null), image.getHeight(null), null);
   }

   //Overides action performed for button
   public void actionPerformed(ActionEvent event)
   {
       //Retrives the action command and stores it
   String actionCommand = event.getActionCommand();
       //Compares the action command with string DOCTOR_IN
       if (DOCTOR_IN.equals(actionCommand))
       {
           //If the message for image is IN
           if(imgStatus.equals("IN"))
           {
               //Sets the Doctor in image
               image = new ImageIcon("DoctorIn.png").getImage();
               //Sets the font color to red
               status.setForeground(Color.RED);
               //Displays the message
               status.setText("The Doctor IS IN, already!");
               imgStatus = "IN";
           }
           else
           {
               //Sets the Doctor in image
           image = new ImageIcon("DoctorIn.png").getImage();
               //Sets the font color to black
               status.setForeground(Color.BLACK);
               //Displays the message
               status.setText("The Doctor IS IN");
               imgStatus = "IN";
           }
   }
       //Compares the action command with string DOCTOR_OUT
       else if (DOCTOR_OUT.equals(actionCommand))
       {
           //If the message for image is OUT
           if(imgStatus.equals("OUT"))
           {
               //Sets the Doctor out image
       image = new ImageIcon("DoctorOut.png").getImage();
               //Sets the font color to red
               status.setForeground(Color.RED);
               //Displays the message
               status.setText("The Doctor IS OUT, already!");
               imgStatus = "OUT";
           }
           else
           {
               //Sets the Doctor out image
       image = new ImageIcon("DoctorOut.png").getImage();
               //Sets the font color to black
               status.setForeground(Color.BLACK);
               //Displays the message
               status.setText("The Doctor IS OUT");
               imgStatus = "OUT";
           }
   }
   repaint();
   }

   public static void main(String[] args)
   {
   EventQueue.invokeLater(new Runnable()
       {
       public void run()
           {
       DoctorAvailability frame = new DoctorAvailability("Dr. Availability");
       frame.setVisible(true);
       }
   });
   }
}

Output:

Dr. Availability Dr. Availability HELP 5ヰ aun a THE DOCTOR Click for in Click for in Click for out Click for out The Doctor iDr. Availability Dr. Availability HELP 5 HELP 5ヰ THE DOCTOR S OUT THE DOCTOR isloUT OuT Click for in Click for in Click for o

Add a comment
Know the answer?
Add Answer to:
JAVA CODING Must be compilable, thanks The purpose is to provide an exercise in event-driven programming...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using Java, please create the program for the following prompt. MUST CREATE BUTTONS IN A JFRAME,...

    Using Java, please create the program for the following prompt. MUST CREATE BUTTONS IN A JFRAME, as specified by the prompt! DO NOT use user input of 1, 2, 3 etc. User input must come from clicking the buttons. Please be sure to test your program. Thank you! Write a program that displays three buttons with the names or images of three candidates for public of office. Imagine that a person votes by clicking the button that shows the candidate...

  • QUESTION 3 [49 MARKS 3.1) Write the Java statements for a class called Calculator to produce...

    QUESTION 3 [49 MARKS 3.1) Write the Java statements for a class called Calculator to produce the GUI below. Use 3 panels to arrange the components. You must use an array when defining the numbered buttons (o-9. Do not declare 10 buttons individually. The textfield must be initialized with the text as shown below, and be able to accommodate up to 25 characters. The spacing between the numbered buttons is 10. (28) for caloula Add Equals 3.2 Rewrite any existing...

  • This is python3. Please help me out. Develop the following GUI interface to allow the user...

    This is python3. Please help me out. Develop the following GUI interface to allow the user to specify the number of rows and number of columns of cards to be shown to the user. Show default values 2 and 2 for number of rows and number of columns. The buttons "New Game" and "Turn Over" span two column-cells each. Fig 1. The GUI when the program first starts. When the user clicks the "New Game" button, the program will read...

  • Basic button tracking Deliverables Updated files for app6.java myJFrame6.java myJPanel6.java student.java Contents You can start with...

    Basic button tracking Deliverables Updated files for app6.java myJFrame6.java myJPanel6.java student.java Contents You can start with the files available here. public class app6 { public static void main(String args[]) {     myJFrame6 mjf = new myJFrame6(); } } import java.awt.*; import javax.swing.*; import java.awt.event.*; public class myJFrame6 extends JFrame {    myJPanel6 p6;    public myJFrame6 ()    {        super ("My First Frame"); //------------------------------------------------------ // Create components: Jpanel, JLabel and JTextField        p6 = new myJPanel6(); //------------------------------------------------------...

  • Exercise 11-4 Create a Reminder app In this exercise, you’ll add a service to a Reminder...

    Exercise 11-4 Create a Reminder app In this exercise, you’ll add a service to a Reminder app that displays a notification every hour that says, “Look into the distance. It’s good for your eyes.” Test the app 1. Start Android Studio and open the project named ch11_ex4_Reminder. 2. Review the code. Note that it contains a layout and a class for an activity, but no class for a service. 1. Run the app. Note that it displays a message that...

  • for Javascript, JQuery When the page is first opened a user will see the name field...

    for Javascript, JQuery When the page is first opened a user will see the name field and the three vacation images to the left of the page. The page should behave according to the following rules. 1. When a user's mouse pointer goes over any image, that image's border will change to be "outset 10px" and when the mouse pointer leaves that image it's border will change to "none". 2. When the user clicks a "Vacation" image on the left,...

  • PYTHON PROGRAMMING LANGUAGE (NEEDED ASAP) Using a structured approach to writing the program: This section will...

    PYTHON PROGRAMMING LANGUAGE (NEEDED ASAP) Using a structured approach to writing the program: This section will guide you in starting the program in a methodical way. The program will display a window with GUI widgets that are associated with particular functions: Employee Payroll O X -- - - - - - - - - - - Show Payroll Find Employee by Name Highest Lowest Find Employee by Amount Write Output to Fie Cancel - -------- ------------- Notice that some of...

  • C+ HelloVisualWorld, pages 121-125 (in the 3-6 Deciding Which Interface to Use Section) We were unable...

    C+ HelloVisualWorld, pages 121-125 (in the 3-6 Deciding Which Interface to Use Section) We were unable to transcribe this imageCHAPTER 3 Using Guy Objects and the Visual Studio IDE Using Gul Objects (continued) Forn click the Form, its Properties window appears in the lower right portion of the screen, and you can see that the Text property for the Form IS set to Forml. Take a moment to scroll through the list in the Properties Window, examining the values of...

  • Java Thank you!! In this assignment you will be developing an image manipulation program. The remaining...

    Java Thank you!! In this assignment you will be developing an image manipulation program. The remaining laboratory assignments will build on this one, allowing you to improve your initial submission based on feedback from your instructor. The program itself will be capable of reading and writing multiple image formats including jpg, png, tiff, and a custom format: msoe files. The program will also be able to apply simple transformations to the image like: Converting the image to grayscale . Producing...

  • Java program that creates a photo album application.    Which will load a collection of images...

    Java program that creates a photo album application.    Which will load a collection of images and displays them in a album layout. The program will allow the user to tag images with metadata: •Title for the photo .      Limited to 100 characters. •Description for the photo . Limited to 300 characters. •Date taken •Place taken Functional Specs 1.Your album should be able to display the pictures sorted by Title, Date, and Place. 2.When the user clicks on a photo,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT