Advertisement
Guest User

Untitled

a guest
Apr 20th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.30 KB | None | 0 0
  1. package ergasia2;
  2.  
  3. import java.applet.Applet;
  4. import java.awt.Button;
  5. import java.awt.Color;
  6. import java.awt.Label;
  7. import java.awt.TextField;
  8. import java.awt.event.ActionEvent;
  9. import java.awt.event.ActionListener;
  10.  
  11. public class trialala extends Applet implements ActionListener {
  12.     TextField t1, t2, t3;
  13.     Label L1, L2, L3;
  14.     Button b1;
  15.     double w,h,dms;
  16.     public void init() {
  17.        
  18.         L1 = new Label ("Weight:");
  19.         L2 = new Label ("Height:");
  20.         L3 = new Label ("DMS:");
  21.         t1 = new TextField (30);
  22.         t2 = new TextField (30);
  23.         t3 = new TextField (30);
  24.         b1 = new Button ("Ypologise ");
  25.        
  26.         b1.addActionListener(this);
  27.        
  28.         add (L1);
  29.         add (t1);
  30.         add (L2);
  31.         add (t2);
  32.         add (L3);
  33.         add (t3);
  34.         add (b1);
  35.     }
  36.     public void actionPerformed (ActionEvent a) {
  37.         try {
  38.             w = Double.parseDouble(t1.getText());
  39.             h = Double.parseDouble(t2.getText());
  40.             dms = w/(h*h);
  41.             if (dms <=18) {
  42.                 t3.setText("ΕΛΛΙΠΟΒΑΡΗΣ");
  43.                 t3.setBackground(Color.red);
  44.             }
  45.             else if ((dms>18) && (dms<=30)) {
  46.                 t3.setBackground(Color.green);
  47.                 t3.setText("KANONIKOS");
  48.             }
  49.             else {
  50.                 t3.setBackground(Color.orange);
  51.                 t3.setText("ΥΠΕΡΒΑΡΟΣ");
  52.             }
  53.            
  54.            
  55.         } catch (NumberFormatException e) {
  56.             t2.setText("Wrong data");
  57.             t2.setBackground(Color.pink);
  58.         }
  59.        
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement