tubuhideal.java


TUGAS JAVA :

MAEDI LAZIMAN
KELAS A
SEMESTER II
POLITEKNIK HARAPAN BERSAMA TEGAL
================================================================================

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

class tubuhIdeal extends JFrame {

private JTextField txtTinggiBadan = new JTextField();
private JTextField txtBeratBadan = new JTextField();
private JTextField txtTubuhIdeal = new JTextField();
private JLabel lblket1 = new JLabel(“”);
private JLabel lblket2 = new JLabel(“”);
private JLabel lblket3 = new JLabel(“”);
private JLabel lblket4 = new JLabel(“”);

private JComboBox cboTubuhIdeal = new JComboBox();

private JTextArea txtKeterangan = new JTextArea();

public tubuhIdeal () {

Box box = new Box(BoxLayout.Y_AXIS);

JPanel pnl = new JPanel();
pnl.setLayout(new GridLayout(1,1));
pnl.setBackground(new Color(4,99,36));

JLabel lblInfo = new JLabel(” Berdasarkan pada program kesehatan di HP KTouch E60″);
lblInfo.setForeground(Color.CYAN);
pnl.add(lblInfo);

box.add(pnl);
//———————————–

pnl = new JPanel();
pnl.setLayout(new GridLayout(8,4));
pnl.setBackground(new Color(4,99,36));

JLabel lblcbo = new JLabel(” Pria / Wanita”, JLabel.LEADING);
lblcbo.setForeground(Color.ORANGE);
pnl.add(lblcbo);
pnl.add(cboTubuhIdeal);
pnl.add(new JLabel(“”));
pnl.add(new JLabel(“”));

pnl.add(new JLabel(“”));
pnl.add(new JLabel(“”));
pnl.add(new JLabel(“”));
pnl.add(new JLabel(“”));

JLabel lbltb =new JLabel(” Masukkan Tinggi Badan”, JLabel.LEADING);
lbltb.setForeground(Color.ORANGE);
pnl.add(lbltb);
pnl.add(txtTinggiBadan);
pnl.add(new JLabel(“”));
pnl.add(new JLabel(“”));

pnl.add(new JLabel(“”));
pnl.add(new JLabel(“”));
pnl.add(new JLabel(“”));
pnl.add(new JLabel(“”));

JLabel lblbb = new JLabel(” Masukkan Berat Badan”, JLabel.LEADING);
lblbb.setForeground(Color.ORANGE);
pnl.add(lblbb);
pnl.add(txtBeratBadan);
pnl.add(new JLabel(“”));
pnl.add(new JLabel(“”));

pnl.add(new JLabel(“”));
pnl.add(new JLabel(“”));
pnl.add(new JLabel(“”));
pnl.add(new JLabel(“”));

JLabel lblti = new JLabel(” Angka Pembanding”,JLabel.LEADING);
lblti.setForeground(Color.ORANGE);
pnl.add(lblti);
pnl.add(txtTubuhIdeal);
pnl.add(new JLabel(“”));
pnl.add(new JLabel(“”));

pnl.add(new JLabel(“”));
pnl.add(new JLabel(“”));
pnl.add(new JLabel(“”));
pnl.add(new JLabel(“”));

box.add(pnl);
//———————————–

pnl = new JPanel();
pnl.setLayout(new GridLayout(5,1));
pnl.setBackground(new Color(4,99,36));

lblket1.setForeground(Color.CYAN);
lblket1.setFont(new Font(“Verdana”, 2, 11));
pnl.add(lblket1);

lblket2.setForeground(Color.CYAN);
lblket2.setFont(new Font(“Verdana”, 2, 11));
pnl.add(lblket2);

lblket3.setForeground(Color.CYAN);
lblket3.setFont(new Font(“Verdana”, 2, 11));
pnl.add(lblket3);

lblket4.setForeground(Color.CYAN);
lblket4.setFont(new Font(“Verdana”, 2, 11));
pnl.add(lblket4);

pnl.add(new JLabel(“”));

box.add(pnl);
//———————————–

pnl = new JPanel();
pnl.setLayout(new GridLayout(1,2));
pnl.setBackground(new Color(4,99,36));
pnl.setPreferredSize(new Dimension(60,120));

txtKeterangan.setForeground(Color.BLUE);
txtKeterangan.setEditable(false);
pnl.add(txtKeterangan);
pnl.add(new JLabel(“”));

box.add(pnl);
//———————————–

pnl = new JPanel();
pnl.setBackground(new Color(4,99,36));
pnl.setLayout(new GridLayout(1,1));

pnl.add(new JLabel(“”));

box.add(pnl);
//———————————–

cboTubuhIdeal.addItem(“Pria”);
cboTubuhIdeal.addItem(“Wanita”);

cboTubuhIdeal.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {

if(e.getKeyCode() == e.VK_ENTER) {

txtTinggiBadan.requestFocus();
}
}
});

txtTinggiBadan.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {

if(e.getKeyCode() == e.VK_ENTER) {

txtBeratBadan.requestFocus();
}
}
});

txtBeratBadan.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {

if(e.getKeyCode() == e.VK_ENTER) {

double txttb,txtbb;
double txtti;

txttb = Double.parseDouble(txtTinggiBadan.getText());
txtbb = Double.parseDouble(txtBeratBadan.getText());

txtti = txtbb / txttb;

txtTubuhIdeal.setText(String.valueOf(txtti));
txtTinggiBadan.requestFocus();

/*pria
*t 50/158.1 = 0.3162555344718533
*b 50/141.4 = 0.3536067892503536
*/
if(cboTubuhIdeal.getSelectedItem() == “Pria”);

if(txtti < 0.3162555344718533) {

txtKeterangan.setText(” Anda adalah seorang : “+cboTubuhIdeal.getSelectedItem()+”\n”+
” Dengan tinggi badan : “+txtTinggiBadan.getText()+”\n”+
” Dan berat badan : “+txtBeratBadan.getText()+”\n”+
” Anda termasuk mempunyai tubuh yang kurus”);

lblket1.setText(” * PRIA * “);
lblket2.setText(” < 0.3162555344718533 = kurus”);
lblket3.setText(” 0.3162555344718533 s/d 0.3536067892503536 = ideal”);
lblket4.setText(” >= 0.3536067892503536 = gemuk”);

}else if(txtti >= 0.3536067892503536) {

txtKeterangan.setText(” Anda adalah seorang : “+cboTubuhIdeal.getSelectedItem()+”\n”+
” Dengan tinggi badan : “+txtTinggiBadan.getText()+”\n”+
” Dan berat badan : “+txtBeratBadan.getText()+”\n”+
” Anda termasuk mempunyai tubuh yang gemuk”);

lblket1.setText(” * PRIA * “);
lblket2.setText(” < 0.3162555344718533 = kurus”);
lblket3.setText(” 0.3162555344718533 s/d 0.3536067892503536 = ideal”);
lblket4.setText(” >= 0.3536067892503536 = gemuk”);

}else if(txtti >= 0.3162555344718533 && txtti < 0.3536067892503536) {

txtKeterangan.setText(” Anda adalah seorang : “+cboTubuhIdeal.getSelectedItem()+”\n”+
” Dengan tinggi badan : “+txtTinggiBadan.getText()+”\n”+
” Dan berat badan : “+txtBeratBadan.getText()+”\n”+
” Anda termasuk mempunyai tubuh yang ideal”);

lblket1.setText(” * PRIA * “);
lblket2.setText(” < 0.3162555344718533 = kurus”);
lblket3.setText(” 0.3162555344718533 s/d 0.3536067892503536 = ideal”);
lblket4.setText(” >= 0.3536067892503536 = gemuk”);
}

if(cboTubuhIdeal.getSelectedItem() == “Wanita”)

/*wanita
*t 50/166.65 = 0.3000300030003
*b 50/147.45 = 0.33916700583367254
*/

if(txtti < 0.3000300030003) {

txtKeterangan.setText(” Anda adalah seorang : “+cboTubuhIdeal.getSelectedItem()+”\n”+
” Dengan tinggi badan : “+txtTinggiBadan.getText()+”\n”+
” Dan berat badan : “+txtBeratBadan.getText()+”\n”+
” Anda termasuk mempunyai tubuh yang kurus”);

lblket1.setText(” * WANITA * “);
lblket2.setText(” < 0.3000300030003 = kurus”);
lblket3.setText(” 0.3000300030003 s/d 0.33916700583367254 = ideal”);
lblket4.setText(” > 0.33916700583367254 = gemuk”);

}else if(txtti > 0.33916700583367254) {

txtKeterangan.setText(” Anda adalah seorang : “+cboTubuhIdeal.getSelectedItem()+”\n”+
” Dengan tinggi badan : “+txtTinggiBadan.getText()+”\n”+
” Dan berat badan : “+txtBeratBadan.getText()+”\n”+
” Anda termasuk mempunyai tubuh yang gemuk”);

lblket1.setText(” * WANITA * “);
lblket2.setText(” < 0.3000300030003 = kurus”);
lblket3.setText(” 0.3000300030003 s/d 0.33916700583367254 = ideal”);
lblket4.setText(” > 0.33916700583367254 = gemuk”);

}else if(txtti >= 0.3000300030003 && txtti <= 0.33916700583367254) {

txtKeterangan.setText(” Anda adalah seorang : “+cboTubuhIdeal.getSelectedItem()+”\n”+
” Dengan tinggi badan : “+txtTinggiBadan.getText()+”\n”+
” Dan berat badan : “+txtBeratBadan.getText()+”\n”+
” Anda termasuk mempunyai tubuh yang ideal”);

lblket1.setText(” * WANITA * “);
lblket2.setText(” < 0.3000300030003 = kurus”);
lblket3.setText(” 0.3000300030003 s/d 0.33916700583367254 = ideal”);
lblket4.setText(” > 0.33916700583367254 = gemuk”);
}

//cboTubuhIdeal.setSelectedIndex(0);
txtTinggiBadan.setText(“”);
txtBeratBadan.setText(“”);
//txtTubuhIdeal.setText(“”);
cboTubuhIdeal.requestFocus();
}
}
});

addWindowListener(new WindowAdapter() {
public void windowOpened(WindowEvent e) {

txtTubuhIdeal.setEditable(false);
}
});

add(box);
setTitle(“Aplikasi Sederhana Tubuh Ideal”);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(600,500);
//pack();
show();
}

public static void main(String[] args) {

new tubuhIdeal();
}
}

2 thoughts on “tubuhideal.java

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s