Rabu, 08 Mei 2013

0 Program GUI

LISTING PROGRAM



import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class tgs extends JFrame implements ActionListener {
 private JLabel lbl1,lbl2,lbl3, lbl4,lbl5,lbl6,lbl7,lbl8;
 private JTextField nama,tinggi,berat,hasil,ideal,anjuran;
 private JButton btn1,btn2,btn3;

 private String nm = "";
    private Double ti, bt, hl;

 public tgs(){
  super("Cek Berat Badan");
  Container container=getContentPane();
  container.setLayout(null);
  
  lbl1 = new JLabel("Cek Berat Badan");
  lbl2 = new JLabel("Nama");
  lbl3 = new JLabel("Tinggi");
  lbl4 = new JLabel("Berat Badan");
  lbl5 = new JLabel("Cm");
  lbl6 = new JLabel("Kg");
  lbl7 = new JLabel("HASIL");
  lbl8 = new JLabel("pesan");
  
  nama = new JTextField();
  tinggi = new JTextField();
  berat = new JTextField();
  hasil = new JTextField();
  ideal = new JTextField();
  anjuran = new JTextField();
  
  btn1 = new JButton("CEK");
  btn2 = new JButton("Coba Lagi");
  btn3 = new JButton("Keluar");
  
  lbl1.setBounds(175, 25, 150, 25); // menghitung berat badan ideal
  lbl2.setBounds(50, 100, 100, 25); // nama
  lbl3.setBounds(50, 125, 100, 25); // tinggi badan
  lbl4.setBounds(50, 150, 100, 25); // berat badan
  lbl5.setBounds(235, 125, 50, 25); // cm
  lbl6.setBounds(235, 150, 50, 25); // kg
  lbl7.setBounds(175, 200, 150, 25); // idealkah badan anda
  lbl8.setBounds(175, 275, 150, 25); // anjuran dari ahli gizi
  
  nama.setBounds(175, 100, 200, 25);
  tinggi.setBounds(175, 125, 50, 25);
  berat.setBounds(175, 150, 50, 25);
  hasil.setBounds(275, 137, 100, 25);
  hasil.setEnabled(false);
  ideal.setBounds(50, 225, 400, 25);
  anjuran.setBounds(50, 300, 400, 25);
  
  btn1.setBounds(50, 350, 133, 75); // idealkah
  btn2.setBounds(183, 350, 133, 75); // coba lagi
  btn3.setBounds(316, 350, 133, 75); // keluar
  
  btn1.addActionListener(this);
  btn2.addActionListener(this);
  btn3.addActionListener(this);
  
  container.add(lbl1);
  container.add(lbl2);
  container.add(lbl3);
  container.add(lbl4);
  container.add(lbl5);
  container.add(lbl6);
  container.add(lbl7);
  container.add(lbl8);
  
  container.add(nama);
  container.add(tinggi);
  container.add(berat);
  container.add(hasil);
  container.add(ideal);
  container.add(anjuran);
  
  container.add(btn1);
  container.add(btn2);
  container.add(btn3);
  
  setSize (500, 500);
  setLocation(400, 150);
  setVisible(true);
 }

 public void actionPerformed(ActionEvent ae) {
  Object obj = ae.getSource();
  if(obj == btn1) {hitungIdeal();}
  if(obj == btn2) {bersih();}
  if(obj == btn3) {System.exit(0);}
 }

 public void bersih() {
  nama.setText("");
  berat.setText("");
  tinggi.setText("");
  hasil.setText("");
  ideal.setText("");
  anjuran.setText("");
  nama.requestFocus(true);
 }

 public void hitungIdeal() {
  if(berat.getText().equals("") || tinggi.getText().equals("") || nama.getText().equals("")) {
   JOptionPane.showMessageDialog(null, "Kotak Input Belum Terisi");
   nama.setText("");
   tinggi.setText("");
   berat.setText("");
   nama.requestFocus(true);
  } else {
   ti = Double.parseDouble(tinggi.getText());;
   bt = Double.parseDouble(berat.getText());
   hl = (ti-110)*1.1;
   double a=1.1*bt;
   double c=0.9*bt;
   
   if (hl>a) {
    ideal.setText("Tidak IDEAL, Anda KURUS");
    anjuran.setText("Makan yang banyak ya :D");
    hasil.setText(String.valueOf(hl));
   } else if(hl<c) {
    ideal.setText("Tidak IDEAL, Anda GEMUK");
    anjuran.setText("banyakin Olahraga dan kurangi makanan berlemak");
    hasil.setText(String.valueOf(hl));
   }
   else {
    ideal.setText("IDEAL");
    anjuran.setText("LANJUTKAN!!!!");
    hasil.setText(String.valueOf(hl));
   }
  }
 }

 public static void main(String args[]) {
        tgs coba = new tgs();
        coba.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
}

OUTPUT PROGRAM



0 komentar:

Posting Komentar

 

Story Of Deny Copyright © 2011 - |- Template created by O Pregador - |- Powered by Blogger Templates