home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Programming Languages Suite
/
ProgLangD.iso
/
VCAFE.3.0A
/
Sample.bin
/
CalculateFrame.java
< prev
next >
Wrap
Text File
|
1998-11-02
|
8KB
|
250 lines
/*
A basic extension of the java.awt.Frame class
*/
import java.awt.*;
import symantec.itools.awt.KeyPressManagerPanel;
public class CalculateFrame extends Frame {
void Frame1_WindowClosing(java.awt.event.WindowEvent event)
{
dispose(); // hide the Frame
}
public CalculateFrame()
{
// This code is automatically generated by Visual Cafe when you add
// components to the visual environment. It instantiates and initializes
// the components. To modify the code, only use code syntax that matches
// what Visual Cafe can generate, or Visual Cafe may be unable to back
// parse your Java file into its visual environment.
//{{INIT_CONTROLS
setLayout(new GridBagLayout());
setSize(461,241);
setVisible(false);
Number1Label.setText("Number 1 =");
add(Number1Label,new com.symantec.itools.awt.GridBagConstraintsD(0,0,2,2,0.0,0.0,java.awt.GridBagConstraints.CENTER,java.awt.GridBagConstraints.NONE,new Insets(5,27,0,0),0,0));
Number1Label.setBounds(91,62,79,23);
add(Number1TextField,new com.symantec.itools.awt.GridBagConstraintsD(2,0,1,1,0.0,0.0,java.awt.GridBagConstraints.CENTER,java.awt.GridBagConstraints.NONE,new Insets(5,52,0,0),89,-2));
Number1TextField.setBounds(222,62,113,21);
Number2Label.setText("Number 2 =");
add(Number2Label,new com.symantec.itools.awt.GridBagConstraintsD(0,2,2,1,0.0,0.0,java.awt.GridBagConstraints.CENTER,java.awt.GridBagConstraints.NONE,new Insets(10,27,0,0),0,0));
Number2Label.setBounds(91,95,79,23);
add(Number2TextField,new com.symantec.itools.awt.GridBagConstraintsD(2,2,1,2,0.0,0.0,java.awt.GridBagConstraints.CENTER,java.awt.GridBagConstraints.NONE,new Insets(12,52,0,0),89,0));
Number2TextField.setBounds(222,97,113,23);
AnswerLabel.setText("Answer =");
add(AnswerLabel,new com.symantec.itools.awt.GridBagConstraintsD(0,4,1,1,0.0,0.0,java.awt.GridBagConstraints.CENTER,java.awt.GridBagConstraints.NONE,new Insets(14,34,0,0),0,0));
AnswerLabel.setBounds(98,134,65,23);
AnswerTextField.setEditable(false);
add(AnswerTextField,new com.symantec.itools.awt.GridBagConstraintsD(2,4,1,1,0.0,0.0,java.awt.GridBagConstraints.CENTER,java.awt.GridBagConstraints.NONE,new Insets(14,52,0,0),89,0));
AnswerTextField.setBackground(java.awt.Color.lightGray);
AnswerTextField.setBounds(222,134,113,23);
panel1.setLayout(new GridLayout(4,1,0,2));
add(panel1,new com.symantec.itools.awt.GridBagConstraintsD(3,0,1,6,0.0,0.0,java.awt.GridBagConstraints.CENTER,java.awt.GridBagConstraints.NONE,new Insets(6,13,23,28),0,0));
panel1.setBounds(348,63,21,98);
PlusButton.setActionCommand("button");
PlusButton.setLabel("+");
panel1.add(PlusButton);
PlusButton.setBounds(0,0,21,23);
SubtractButton.setActionCommand("button");
SubtractButton.setLabel("-");
panel1.add(SubtractButton);
SubtractButton.setBounds(0,25,21,23);
MultiplyButton.setActionCommand("button");
MultiplyButton.setLabel("X");
panel1.add(MultiplyButton);
MultiplyButton.setBounds(0,50,21,23);
DivideButton.setActionCommand("button");
DivideButton.setLabel("/");
panel1.add(DivideButton);
DivideButton.setBounds(0,75,21,23);
setTitle("Simple Calculation");
//}}
//{{INIT_MENUS
//}}
//{{REGISTER_LISTENERS
Window lWindow = new Window();
addWindowListener(lWindow);
SymAction lSymAction = new SymAction();
PlusButton.addActionListener(lSymAction);
SubtractButton.addActionListener(lSymAction);
MultiplyButton.addActionListener(lSymAction);
DivideButton.addActionListener(lSymAction);
//}}
}
public CalculateFrame(String title)
{
this();
setTitle(title);
}
// public void show()
//{
// move(50, 50);
// super.show();
// }
boolean fComponentsAdjusted = false;
//{{DECLARE_CONTROLS
java.awt.Label Number1Label = new java.awt.Label();
java.awt.TextField Number1TextField = new java.awt.TextField(15);
java.awt.Label Number2Label = new java.awt.Label();
java.awt.TextField Number2TextField = new java.awt.TextField(15);
java.awt.Label AnswerLabel = new java.awt.Label();
java.awt.TextField AnswerTextField = new java.awt.TextField(15);
java.awt.Panel panel1 = new java.awt.Panel();
java.awt.Button PlusButton = new java.awt.Button();
java.awt.Button SubtractButton = new java.awt.Button();
java.awt.Button MultiplyButton = new java.awt.Button();
java.awt.Button DivideButton = new java.awt.Button();
//}}
//{{DECLARE_MENUS
//}}
class Window extends java.awt.event.WindowAdapter
{
public void windowClosing(java.awt.event.WindowEvent event)
{
Object object = event.getSource();
if (object == CalculateFrame.this)
Frame1_WindowClosing(event);
}
}
class SymAction implements java.awt.event.ActionListener
{
public void actionPerformed(java.awt.event.ActionEvent event)
{
Object object = event.getSource();
if (object == PlusButton)
plusButton_ActionPerformed(event);
else if (object == SubtractButton)
subtractButton_ActionPerformed(event);
else if (object == MultiplyButton)
multiplyButton_ActionPerformed(event);
else if (object == DivideButton)
divideButton_ActionPerformed(event);
}
}
void plusButton_ActionPerformed(java.awt.event.ActionEvent event)
{
// to do: code goes here.
plusButton_ActionPerformed_Interaction1(event);
}
void plusButton_ActionPerformed_Interaction1(java.awt.event.ActionEvent event)
{
double sum, num1, num2;
try {
num1 = (Double.valueOf(Number1TextField.getText())).doubleValue();
num2 = (Double.valueOf(Number2TextField.getText())).doubleValue();
} catch (NumberFormatException e) { return; }
sum = num1 + num2;
if (sum < 0) { AnswerTextField.setBackground(Color.red); }
else { AnswerTextField.setBackground(Color.lightGray); }
AnswerTextField.setText(String.valueOf(sum)); }
void subtractButton_ActionPerformed(java.awt.event.ActionEvent event)
{
// to do: code goes here.
subtractButton_ActionPerformed_Interaction1(event);
}
void subtractButton_ActionPerformed_Interaction1(java.awt.event.ActionEvent event)
{
double diff, num1, num2;
try {
num1 = (Double.valueOf(Number1TextField.getText())).doubleValue();
num2 = (Double.valueOf(Number2TextField.getText())).doubleValue();
} catch (NumberFormatException e) { return; }
diff = num1 - num2;
if (diff < 0) { AnswerTextField.setBackground(Color.red); }
else { AnswerTextField.setBackground(Color.gray); }
AnswerTextField.setText(String.valueOf(diff));
}
void multiplyButton_ActionPerformed(java.awt.event.ActionEvent event)
{
// to do: code goes here.
multiplyButton_ActionPerformed_Interaction1(event);
}
void multiplyButton_ActionPerformed_Interaction1(java.awt.event.ActionEvent event)
{
double product, num1, num2;
try {
num1 = (Double.valueOf(Number1TextField.getText())).doubleValue();
num2 = (Double.valueOf(Number2TextField.getText())).doubleValue();
} catch (NumberFormatException e) { return; }
product = num1 * num2;
if (product < 0) { AnswerTextField.setBackground(Color.red); }
else { AnswerTextField.setBackground(Color.gray); }
AnswerTextField.setText(String.valueOf(product));
}
void divideButton_ActionPerformed(java.awt.event.ActionEvent event)
{
// to do: code goes here.
divideButton_ActionPerformed_Interaction1(event);
}
void divideButton_ActionPerformed_Interaction1(java.awt.event.ActionEvent event)
{
double quotient, num1, num2;
try {
num1 = (Double.valueOf(Number1TextField.getText())).doubleValue();
num2 = (Double.valueOf(Number2TextField.getText())).doubleValue();
} catch (NumberFormatException e) { return; }
if (num2 == 0) return;
quotient = num1 / num2;
if (quotient < 0) { AnswerTextField.setBackground(Color.red); }
else { AnswerTextField.setBackground(Color.gray); }
AnswerTextField.setText(String.valueOf(quotient));
}
}