A:\chapt5\FredsApplet.java:113: cannot resolve symbol
symbol : constructor MessageBox
(FredsApplet,java.lang.String,java.lang.String)
location: class MessageBox
errorBox = new MessageBox(this, "Data Entry","Nothing Entered");
^
1 error
---------------------------------------------------------------------
FredsApplet.java
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class FredsApplet extends Applet implements ActionListener
{
MessageBox errorBox;
private Button keysArray[];
private Panel keyPad;
private Panel lcdPad;
private Panel buttonPad;
private TextField lcdField;
Panel firstRow = new Panel();
Panel secondRow = new Panel();
Panel thirdRow = new Panel();
Panel fourthRow = new Panel();
Panel fifthRow = new Panel();
Label companyName = new Label("Fred's Foods",Label.CENTER);
Label produceCode = new Label("Enter The Produce Code: ");
TextField produceField = new TextField(10);
Label lblWeight = new Label("Enter the weight: ");
TextField weightField = new TextField(10);
Button CalculateButton = new Button("Calculate");
Button ProduceButton = new Button("Produce Code");
Button WeightButton = new Button("Weight");
Button ClearButton = new Button("Clear");
private int result;
private boolean first;
private boolean foundKey;
static boolean clearText;
Label foodLabel = new Label("");
Choice foodChoice = new Choice();
public void init()
{
lcdField = new TextField(20);
lcdPad = new Panel();
keyPad = new Panel();
buttonPad = new Panel();
keysArray = new Button[10];
setLayout(new BorderLayout());
setBackground(Color.gray);
lcdField.setEditable(false);
lcdPad.add(lcdField);
lcdPad.add(companyName);
lcdPad.add(produceCode);
lcdPad.add(produceField);
for(int i = 0; i<=9; i++)
keysArray[i] = new Button(String.valueOf(i));
keyPad.setLayout(new GridLayout(6,2));
for(int i =0; i<=9; i++)
keyPad.add(keysArray[i]);
buttonPad.add(CalculateButton);
buttonPad.add(ProduceButton);
buttonPad.add(WeightButton);
buttonPad.add(ClearButton);
buttonPad.add(foodChoice);
foodChoice.addItem("Grape(s)");
foodChoice.addItem("Orange(s)");
foodChoice.addItem("Apple(s)");
foodChoice.addItem("Bannana(s)");
foodChoice.addItem("Mango(s)");
foodChoice.addItem("Lemon(s)");
foodChoice.addItem("Brocoli");
foodChoice.addItem("Salad");
foodChoice.addItem("Avocato");
foodChoice.addItem("Tomatoe(s)");
add(lcdPad, BorderLayout.NORTH);
add(keyPad, BorderLayout.CENTER);
add(buttonPad, BorderLayout.SOUTH);
for(int i = 0; i < keysArray.length; i++)
keysArray[i].addActionListener(this);
CalculateButton.addActionListener(this);
ClearButton.addActionListener(this);
ProduceButton.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
foundKey = false;
for(int i = 0; i < keysArray.length && !foundKey;
i++)
if(e.getSource() == keysArray[i])
{
foundKey = true;
switch(i)
{
case 0: case 1: case 2: case 3: case 4:
case 5: case 6: case 7: case 8: case 9:
lcdField.setText(lcdField.getText()+keysArray
[i].getLabel());
break;
}
}
if(e.getSource() == ClearButton)
{
lcdField.setText("");
clearText=false;
}
if(e.getSource() == ProduceButton)
{
if(lcdField.getText().length()==0)
{
errorBox = new MessageBox(this, "Data
Entry","Nothing Entered");
errorBox.setVisible(true);
}
else
result = Integer.parseInt(lcdField.getText
());
if(result == 1111)
{
lcdField.setText("");
lcdField.setText("Code accepted for Grape
(s)");
}
if(result == 1112)
{
lcdField.setText("");
lcdField.setText("Code accepted for Orange
(s)");
}
if(result == 1113)
{
lcdField.setText("");
lcdField.setText("Code accepted for Apple
(s)");
}
if(result == 1114)
{
lcdField.setText("");
lcdField.setText("Code accepted for Mango
(s)");
}
if(result == 1115)
{
lcdField.setText("");
lcdField.setText("Code accepted for Lemon
(s)");
}
}
}
}
----------------------------------------------------------------------
MessageBox.java
import java.awt.*;
import java.awt.event.*;
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);
}
}