Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Perform the following steps. 1. Start TextPad and open the file named MessageBox

ID: 3774879 • Letter: P

Question

Perform the following steps.

1. Start TextPad and open the file named MessageBox. Print a copy for your reference.

2. Compile the MessageBox file.

3. Open the file named Flora. Print a copy for your reference.

4. Compile and run the Flora program.

5. Try entering data appropriately, then try omitting data fields. Notice when the message boxes are displayed. Close the program.

6. Look through the source code for the Flora.java file. Insert comment marks (//) at the beginning of all lines involving any of the message boxes, except for the MessageBox declaration statements. Directly underneath the lines that are commented out, insert new code to generate JOptionPane dialog boxes that replace the message boxes. Use the same titles, prompts, and buttons. Do not forget to import the necessary Swing packages.

7. Compile the Flora programs again and fix errors if necessary.

8. Run the program and enter both appropriate and incorrect data. Try leaving some fields blank.

9. If necessary, fix any logic errors and then repeat steps 7 and 8 until the program runs correctly.

10. Print a copy of the updated Flora.java file for your instructor.

//messagebox.java:

import java.awt.*;

import java.awt.event.*;

public class MessageBox extends Dialog implements ActionListener

{

private String result;

private Button OKButton;

public MessageBox(Frame frame, String title, String messageString)

{

// call dialog's constructor

super(frame, title, true);

// determine the size of the message box

Rectangle bounds = frame.getBounds();

setBackground(Color.white);

setLocation(bounds.x+bounds.width/3, bounds.y+bounds.height/3);

// create a panel to hold the message

Panel messagePane = new Panel();

Label message = new Label(messageString);

messagePane.add(message);

add(messagePane, BorderLayout.CENTER);

// create a panel to hold the button

Panel buttonPane = new Panel();

OKButton = new Button(" OK ");

buttonPane.add(OKButton);

add(buttonPane, BorderLayout.SOUTH);

// add the Action Listener to the button

OKButton.addActionListener(this);

// reorganize internal components to fit window

pack();

}

public void actionPerformed(ActionEvent e)

{

setVisible(false); } }

// end class MessageBox

/* Chapter 8 Programming Assignment 2

Programmer:

Date:

Program Name: Flora

*/

import java.io.*;

import java.awt.*;

import java.awt.event.*;

public class Flora extends Frame implements ActionListener

{

MessageBox savedBox;

MessageBox errorBox;

DataOutputStream output;

//Construct components

Panel dataFields = new Panel();

Panel firstRow = new Panel();

Panel secondRow = new Panel();

Panel thirdRow = new Panel();

Panel fourthRow = new Panel();

Panel fifthRow = new Panel();

Panel sixthRow = new Panel();

Panel buttonArea= new Panel();

Button newSticker = new Button("New Sticker");

Button renewal = new Button("Renewal");

Label vinLabel = new Label("Enter Vehicle VIN number: ");

TextField vin = new TextField(20);

Label yearLabel = new Label("Year: ");

TextField year = new TextField(4);

Label makeLabel = new Label("Make: ");

TextField make = new TextField(10);

Label modelLabel = new Label("Model:");

TextField model = new TextField(10);

Label firstNameLabel = new Label("Enter First Name: ");

TextField firstName = new TextField(15);

Label lastNameLabel = new Label("Enter Last Name:");

TextField lastName = new TextField(20);

Label addressLabel = new Label("Enter Flora Address:");

TextField address = new TextField (35);

public static void main(String[] args)

{

Flora window = new Flora();

window.setTitle("Flora City Stickers");

window.setSize(450, 250);

window.setVisible(true);

}

public Flora()

{

//Set background and layout managers

setBackground(Color.magenta);

setLayout(new BorderLayout());

dataFields.setLayout(new GridLayout(6,1));

FlowLayout rowSetup = new FlowLayout(FlowLayout.LEFT,5,2);

firstRow.setLayout(rowSetup);

secondRow.setLayout(rowSetup);

thirdRow.setLayout(rowSetup);

fourthRow.setLayout(rowSetup);

fifthRow.setLayout(rowSetup);

sixthRow.setLayout(rowSetup);

buttonArea.setLayout(new FlowLayout());

//Add fields to rows

firstRow.add(vinLabel);

firstRow.add(yearLabel);

firstRow.add(makeLabel);

firstRow.add(modelLabel);

secondRow.add(vin);

secondRow.add(year);

secondRow.add(make);

secondRow.add(model);

thirdRow.add(firstNameLabel);

thirdRow.add(lastNameLabel);

fourthRow.add(firstName);

fourthRow.add(lastName);

fifthRow.add(addressLabel);

sixthRow.add(address);

//Add rows to panel

dataFields.add(firstRow);

dataFields.add(secondRow);

dataFields.add(thirdRow);

dataFields.add(fourthRow);

dataFields.add(fifthRow);

dataFields.add(sixthRow);

//Add buttons to panel

buttonArea.add(newSticker);

buttonArea.add(renewal);

//Add panels to frame

add(dataFields, BorderLayout.NORTH);

add(buttonArea, BorderLayout.SOUTH);

//Add functionality to buttons

newSticker.addActionListener(this);

renewal.addActionListener(this);

//Open the file

try

{

output = new DataOutputStream(new FileOutputStream("Sticker.dat"));

}

catch(IOException c)

{

System.exit(1);

}

//Construct window listener

addWindowListener(

new WindowAdapter()

{

public void windowClosing(WindowEvent e) { System.exit(0); } } ); } public void actionPerformed(ActionEvent e) { String arg = e.getActionCommand(); String code; if (arg == "New Sticker") code = "N"; else code = "R"; if ( (vin.getText().compareTo("")<1) || (year.getText().compareTo("")<1) || (make.getText().compareTo("")<1) || (model.getText().compareTo("")<1) || (firstName.getText().compareTo("")<1) || (lastName.getText().compareTo("")<1) || (address.getText().compareTo("")<1) ) { errorBox = new MessageBox(this, "Data Entry Error", "You must complete all fields."); errorBox.setVisible(true); } else { try { output.writeUTF(code); output.writeUTF(vin.getText()); output.writeUTF(year.getText()); output.writeUTF(make.getText()); output.writeUTF(model.getText()); output.writeUTF(firstName.getText()); output.writeUTF(lastName.getText()); output.writeUTF(address.getText()); savedBox = new MessageBox(this, "Data Submitted", "The vehicle information has been saved."); savedBox.setVisible(true); } catch(IOException c) { System.exit(1); } clearFields(); } } public void clearFields() { //Clear fields and reset the focus vin.setText(""); year.setText(""); make.setText(""); model.setText(""); firstName.setText(""); lastName.setText(""); address.setText(""); vin.requestFocus(); } }

Explanation / Answer

Your subsequent step is to compile the program. To compile the instance, from the directory above the HelloWorldSwing.java record:

javac start/HelloWorldSwing.java
in case you choose, you may collect the instance from inside the start directory:

javac HelloWorldSwing.java
however you ought to consider to depart the begin listing to execute this system.

if you are unable to assemble, make certain you're the use of the compiler in a recent launch of the Java platform. you can verify the model of your compiler or Java Runtime surroundings (JRE) the use of those commands

javac -version
java -model
as soon as you have up to date your JDK, you need to be able to use the applications on this trail without changes. any other common mistake is installing the JRE and no longer the entire Java improvement package (JDK) had to bring together these packages. talk to the Getting commenced path that will help you solve any compiling issues you come upon. some other aid is the Troubleshooting manual for Java™ SE 6 computer technologies.