home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Programming Languages Suite
/
ProgLangD.iso
/
VCAFE.3.0A
/
Sample.bin
/
degrees.java
< prev
next >
Wrap
Text File
|
1998-10-28
|
4KB
|
152 lines
import java.awt.*;
public class degrees extends java.applet.Applet {
static boolean FSelected;
public void init() {
//{{INIT_CONTROLS
setLayout(new GridLayout(2,2,0,0));
setSize(398,185);
edit1.setBounds(0,0,199,92);
add(edit1);
CheckboxGroup group1 = new CheckboxGroup();
Fahrenheit.setState(true);
Fahrenheit.setLabel("Fahrenheit");
Fahrenheit.setBounds(199,0,199,92);
add(Fahrenheit);
clearbutton.setActionCommand("button");
clearbutton.setLabel("Clear");
clearbutton.setBounds(0,92,199,92);
clearbutton.setBackground(java.awt.Color.gray);
add(clearbutton);
Celcius.setLabel("Celcius");
Celcius.setBounds(199,92,199,92);
add(Celcius);
//}}
FSelected = true;
edit1.requestFocus();
//{{REGISTER_LISTENERS
SymAction lSymAction = new SymAction();
clearbutton.addActionListener(lSymAction);
SymItem lSymItem = new SymItem();
Fahrenheit.addItemListener(lSymItem);
Celcius.addItemListener(lSymItem);
//}}
validate();
}
//{{DECLARE_CONTROLS
java.awt.TextField edit1 = new java.awt.TextField(15);
java.awt.Checkbox Fahrenheit = new java.awt.Checkbox();
java.awt.Button clearbutton = new java.awt.Button();
java.awt.Checkbox Celcius = new java.awt.Checkbox();
//}}
class SymAction implements java.awt.event.ActionListener
{
public void actionPerformed(java.awt.event.ActionEvent event)
{
Object object = event.getSource();
if (object == clearbutton)
clearbutton_ActionPerformed(event);
}
}
void clearbutton_ActionPerformed(java.awt.event.ActionEvent event)
{
// to do: code goes here.
clearbutton_ActionPerformed_Interaction1(event);
}
void clearbutton_ActionPerformed_Interaction1(java.awt.event.ActionEvent event)
{
try {
// edit1 Clear the text for TextField
edit1.setText("");
} catch (Exception e) {
}
}
class SymItem implements java.awt.event.ItemListener
{
public void itemStateChanged(java.awt.event.ItemEvent event)
{
Object object = event.getSource();
if (object == Fahrenheit)
Fahrenheit_ItemStateChanged(event);
else if (object == Celcius)
Celcius_ItemStateChanged(event);
}
}
void Fahrenheit_ItemStateChanged(java.awt.event.ItemEvent event)
{
// to do: code goes here.
Fahrenheit_ItemStateChanged_Interaction1(event);
}
void Fahrenheit_ItemStateChanged_Interaction1(java.awt.event.ItemEvent event)
{
float degree;
if(FSelected == true) return;
try {
degree = (Float.valueOf(edit1.getText())).floatValue();
} catch(NumberFormatException e) {FSelected = true; return; }
if( degree <= 0 )
edit1.setBackground(Color.cyan);
else if( degree >= 100 )
edit1.setBackground(Color.red);
else edit1.setBackground(Color.white);
edit1.setText(String.valueOf(1.8*degree+32));
FSelected = true;
}
void Celcius_ItemStateChanged(java.awt.event.ItemEvent event)
{
// to do: code goes here.
Celcius_ItemStateChanged_Interaction1(event);
}
void Celcius_ItemStateChanged_Interaction1(java.awt.event.ItemEvent event)
{
float degree;
if(FSelected == false) return;
try {
degree = (Float.valueOf(edit1.getText())).floatValue();
} catch (NumberFormatException e) {FSelected = false; return; }
if( degree <= 32 )
edit1.setBackground(Color.cyan);
else if( degree >= 212 )
edit1.setBackground(Color.red);
else edit1.setBackground(Color.white);
edit1.setText(String.valueOf((degree-32.0)/1.8));
FSelected = false;
}
}