Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ergasia2;
- import java.applet.Applet;
- import java.awt.Button;
- import java.awt.Color;
- import java.awt.Label;
- import java.awt.TextField;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- public class trialala extends Applet implements ActionListener {
- TextField t1, t2, t3;
- Label L1, L2, L3;
- Button b1;
- double w,h,dms;
- public void init() {
- L1 = new Label ("Weight:");
- L2 = new Label ("Height:");
- L3 = new Label ("DMS:");
- t1 = new TextField (30);
- t2 = new TextField (30);
- t3 = new TextField (30);
- b1 = new Button ("Ypologise ");
- b1.addActionListener(this);
- add (L1);
- add (t1);
- add (L2);
- add (t2);
- add (L3);
- add (t3);
- add (b1);
- }
- public void actionPerformed (ActionEvent a) {
- try {
- w = Double.parseDouble(t1.getText());
- h = Double.parseDouble(t2.getText());
- dms = w/(h*h);
- if (dms <=18) {
- t3.setText("ΕΛΛΙΠΟΒΑΡΗΣ");
- t3.setBackground(Color.red);
- }
- else if ((dms>18) && (dms<=30)) {
- t3.setBackground(Color.green);
- t3.setText("KANONIKOS");
- }
- else {
- t3.setBackground(Color.orange);
- t3.setText("ΥΠΕΡΒΑΡΟΣ");
- }
- } catch (NumberFormatException e) {
- t2.setText("Wrong data");
- t2.setBackground(Color.pink);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement