home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / VCafe / VCSAMPL.BIN / degrees.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-09-08  |  4.0 KB  |  137 lines

  1. import java.applet.Applet;
  2. import java.awt.Button;
  3. import java.awt.Checkbox;
  4. import java.awt.CheckboxGroup;
  5. import java.awt.Color;
  6. import java.awt.Component;
  7. import java.awt.Container;
  8. import java.awt.GridBagConstraints;
  9. import java.awt.GridBagLayout;
  10. import java.awt.Insets;
  11. import java.awt.TextField;
  12. import java.awt.event.ItemEvent;
  13. import java.awt.event.MouseEvent;
  14.  
  15. public class degrees extends Applet {
  16.    boolean FSelected;
  17.    TextField edit1;
  18.    Checkbox Fahrenheit;
  19.    CheckboxGroup group1;
  20.    Button clearbutton;
  21.    Checkbox Celcius;
  22.  
  23.    public void init() {
  24.       GridBagLayout gridBagLayout = new GridBagLayout();
  25.       ((Container)this).setLayout(gridBagLayout);
  26.       ((Component)this).setSize(226, 95);
  27.       this.edit1 = new TextField(15);
  28.       this.edit1.setBounds(33, 24, 24, 23);
  29.       GridBagConstraints gbc = new GridBagConstraints();
  30.       gbc.gridx = 0;
  31.       gbc.gridy = 0;
  32.       gbc.weightx = (double)1.0F;
  33.       gbc.weighty = (double)1.0F;
  34.       gbc.anchor = 15;
  35.       gbc.fill = 0;
  36.       gbc.insets = new Insets(0, 0, 0, 0);
  37.       ((GridBagLayout)((Container)this).getLayout()).setConstraints(this.edit1, gbc);
  38.       ((Container)this).add(this.edit1);
  39.       this.group1 = new CheckboxGroup();
  40.       this.Fahrenheit = new Checkbox("Fahrenheit", this.group1, true);
  41.       this.Fahrenheit.setBounds(90, 24, 89, 23);
  42.       gbc = new GridBagConstraints();
  43.       gbc.gridx = 1;
  44.       gbc.gridy = 0;
  45.       gbc.weightx = (double)1.0F;
  46.       gbc.weighty = (double)1.0F;
  47.       gbc.anchor = 16;
  48.       gbc.fill = 0;
  49.       gbc.insets = new Insets(0, 0, 0, 0);
  50.       ((GridBagLayout)((Container)this).getLayout()).setConstraints(this.Fahrenheit, gbc);
  51.       ((Container)this).add(this.Fahrenheit);
  52.       this.clearbutton = new Button();
  53.       this.clearbutton.setActionCommand("button");
  54.       this.clearbutton.setLabel("Clear");
  55.       this.clearbutton.setBounds(23, 59, 44, 23);
  56.       this.clearbutton.setBackground(new Color(8421504));
  57.       gbc = new GridBagConstraints();
  58.       gbc.gridx = 0;
  59.       gbc.gridy = 1;
  60.       gbc.weightx = (double)1.0F;
  61.       gbc.weighty = (double)1.0F;
  62.       gbc.fill = 0;
  63.       gbc.insets = new Insets(0, 0, 0, 0);
  64.       ((GridBagLayout)((Container)this).getLayout()).setConstraints(this.clearbutton, gbc);
  65.       ((Container)this).add(this.clearbutton);
  66.       this.Celcius = new Checkbox("Celcius", this.group1, false);
  67.       this.Celcius.setBounds(90, 47, 72, 23);
  68.       gbc = new GridBagConstraints();
  69.       gbc.gridx = 1;
  70.       gbc.gridy = 1;
  71.       gbc.weightx = (double)1.0F;
  72.       gbc.weighty = (double)1.0F;
  73.       gbc.anchor = 18;
  74.       gbc.fill = 0;
  75.       gbc.insets = new Insets(0, 0, 0, 0);
  76.       ((GridBagLayout)((Container)this).getLayout()).setConstraints(this.Celcius, gbc);
  77.       ((Container)this).add(this.Celcius);
  78.       this.FSelected = true;
  79.       this.edit1.requestFocus();
  80.       degrees$SymItem lSymItem = new degrees$SymItem(this);
  81.       this.Celcius.addItemListener(lSymItem);
  82.       this.Fahrenheit.addItemListener(lSymItem);
  83.       degrees$SymMouse lSymMouse = new degrees$SymMouse(this);
  84.       this.clearbutton.addMouseListener(lSymMouse);
  85.       ((Container)this).validate();
  86.    }
  87.  
  88.    void clickedFahrenheit(ItemEvent event) {
  89.       if (!this.FSelected) {
  90.          float degree;
  91.          try {
  92.             degree = Float.valueOf(this.edit1.getText());
  93.          } catch (NumberFormatException var3) {
  94.             return;
  95.          }
  96.  
  97.          if (degree <= 0.0F) {
  98.             this.edit1.setBackground(Color.blue);
  99.          } else if (degree >= 100.0F) {
  100.             this.edit1.setBackground(Color.red);
  101.          } else {
  102.             this.edit1.setBackground(Color.white);
  103.          }
  104.  
  105.          this.edit1.setText(String.valueOf(1.8 * (double)degree + (double)32.0F));
  106.          this.FSelected = true;
  107.       }
  108.    }
  109.  
  110.    void clickedCelcius(ItemEvent event) {
  111.       if (this.FSelected) {
  112.          float degree;
  113.          try {
  114.             degree = Float.valueOf(this.edit1.getText());
  115.          } catch (NumberFormatException var3) {
  116.             return;
  117.          }
  118.  
  119.          if (degree <= 32.0F) {
  120.             this.edit1.setBackground(Color.blue);
  121.          } else if (degree >= 212.0F) {
  122.             this.edit1.setBackground(Color.red);
  123.          } else {
  124.             this.edit1.setBackground(Color.white);
  125.          }
  126.  
  127.          this.edit1.setText(String.valueOf(((double)degree - (double)32.0F) / 1.8));
  128.          this.FSelected = false;
  129.       }
  130.    }
  131.  
  132.    void clearbutton_MouseClick(MouseEvent event) {
  133.       this.edit1.setText("");
  134.       this.edit1.setBackground(Color.white);
  135.    }
  136. }
  137.