/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author M@siti
// */
//import java.awt.FlowLayout;
import java.awt.Font;
import javax.swing.*;
import java.awt.font.*;
//import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class hitung_gizi2 extends JFrame {
String mak_pokok[] = {"Nasi Putih", "Nasi Kuning", "Nasi Jagung"};
JComboBox cb_pokok = new JComboBox(mak_pokok);
String nabati[] = {"bayam", "Kelor", "sawi"};
JComboBox cb_nabati = new JComboBox(nabati);
String hewani[] = {"Nasi Putih", "Nasi Kuning", "Nasi Jagung"};
JComboBox cb_hewani = new JComboBox(hewani);
String sayur[] = {"Nasi Putih", "Nasi Kuning", "Nasi Jagung"};
JComboBox cb_sayur = new JComboBox(sayur);
String buah[] = {"Nasi Putih", "Nasi Kuning", "Nasi Jagung"};
JComboBox cb_buah = new JComboBox(buah);
JLabel lbl_judul = new JLabel("HITUNG GIZI");
JLabel lbl_pokok = new JLabel("Makanan Pokok");
JLabel lbl_nabati = new JLabel("Lauk Nabati");
JLabel lbl_hewani = new JLabel("Lauk Hewani");
JLabel lbl_sayur = new JLabel("Sayur");
JLabel lbl_Buah = new JLabel("Buah");
JLabel lbl_gr = new JLabel("gr");
JLabel lbl_ket = new JLabel("Daftar Makanan Yang Anda Masukkan");
JTextField txt_grpokok = new JTextField();
JTextField txt_grnabati = new JTextField();
JTextField txt_grhewani = new JTextField();
JTextField txt_grsayur = new JTextField();
JTextField txt_grbuah = new JTextField();
JButton btn_pokok = new JButton("+");
JButton btn_nabati = new JButton("+");
JButton btn_hewani = new JButton("+");
JButton btn_sayur = new JButton("m+");
JButton btn_buah = new JButton("m+m");
JButton btn_submit = new JButton("Submit");
Font x = new Font("Times New Roman", Font.BOLD, 15);
Font y = new Font("Times New Romn", Font.BOLD, 30);
JTextArea tx = new JTextArea();
void tampil() {
for (int i = 0; i <= mak_pokok.length; i++) {
cb_pokok.addItem(new String().valueOf(i ));
}
for (int i = 0; i < nabati.length; i++) {
cb_nabati.addItem(new String().valueOf(i + 1));
}
for (int i = 0; i < hewani.length; i++) {
cb_hewani.addItem(new String().valueOf(i + 1));
}
for (int i = 0; i < sayur.length; i++) {
cb_sayur.addItem(new String().valueOf(i + 1));
}
for (int i = 0; i < buah.length; i++) {
cb_buah.addItem(new String().valueOf(i + 1));
}
getContentPane().add(lbl_judul);
getContentPane().add(lbl_pokok);
getContentPane().add(lbl_nabati);
getContentPane().add(lbl_hewani);
getContentPane().add(lbl_sayur);
getContentPane().add(lbl_Buah);
lbl_judul.setFont(y);
lbl_pokok.setFont(x);
lbl_nabati.setFont(x);
lbl_hewani.setFont(x);
lbl_sayur.setFont(x);
lbl_Buah.setFont(x);
btn_pokok.setFont(x);
btn_nabati.setFont(x);
btn_hewani.setFont(x);
btn_sayur.setFont(x);
btn_buah.setFont(x);
getContentPane().add(cb_pokok);
getContentPane().add(cb_nabati);
getContentPane().add(cb_hewani);
getContentPane().add(cb_sayur);
getContentPane().add(cb_buah);
getContentPane().add(lbl_gr);
lbl_gr.setFont(x);
getContentPane().add(txt_grpokok);
getContentPane().add(txt_grnabati);
getContentPane().add(txt_grhewani);
getContentPane().add(txt_grsayur);
getContentPane().add(txt_grbuah);
getContentPane().add(btn_pokok);
getContentPane().add(btn_nabati);
getContentPane().add(btn_hewani);
getContentPane().add(btn_sayur);
getContentPane().add(btn_buah);
getContentPane().add(lbl_ket);
getContentPane().add(tx);
getContentPane().add(lbl_ket);
getContentPane().add(btn_submit);
lbl_judul.setBounds(200, 20, 400, 25);
lbl_pokok.setBounds(30, 80, 400, 25);
lbl_nabati.setBounds(30, 160, 400, 25);
lbl_hewani.setBounds(30, 240, 400, 25);
lbl_sayur.setBounds(30, 320, 400, 25);
lbl_Buah.setBounds(30, 400, 400, 25);
cb_pokok.setBounds(30, 120, 150, 25);
cb_nabati.setBounds(30, 200, 150, 25);
cb_hewani.setBounds(30, 280, 150, 25);
cb_sayur.setBounds(30, 360, 150, 25);
cb_buah.setBounds(30, 440, 150, 25);
lbl_ket.setBounds(430, 80, 400, 25);
lbl_gr.setBounds(250, 80, 400, 25);
txt_grpokok.setBounds(250, 120, 80, 25);
txt_grnabati.setBounds(250, 200, 80, 25);
txt_grhewani.setBounds(250, 280, 80, 25);
txt_grsayur.setBounds(250, 360, 80, 25);
txt_grbuah.setBounds(250, 440, 80, 25);
btn_pokok.setBounds(350, 120, 35, 25);
btn_nabati.setBounds(350, 200, 35, 25);
btn_hewani.setBounds(350, 280, 35, 25);
btn_sayur.setBounds(350, 360, 35, 25);
btn_buah.setBounds(350, 440, 35, 25);
tx.setBounds(430, 120, 330, 350);
btn_submit.setBounds(570, 480, 100, 25);
}
void aksi() {
btn_submit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
throw new UnsupportedOperationException("Not supported yet.");
}
});
btn_pokok.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
if (event.getSource() == btn_pokok) {
String s = cb_pokok.getSelectedItem() + " ";
tx.setText(s);
}
}
});
btn_nabati.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
if (event.getSource() == btn_nabati) {
String s = cb_nabati.getSelectedItem() + " ";
tx.setText(s);
}
}
});
btn_hewani.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
if (event.getSource() == btn_hewani) {
String s = cb_hewani.getSelectedItem() + " ";
tx.setText(s);
}
}
});
btn_sayur.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
if (event.getSource() == btn_sayur) {
String s = cb_sayur.getSelectedItem() + " ";
tx.setText(s);
}
}
});
btn_buah.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
if (event.getSource() == btn_buah) {
String s = cb_buah.getSelectedItem() + " ";
tx.setText(s);
}
}
});
}
void resetpokok() {
txt_grpokok.setText("");
}
void resetnabati() {
txt_grnabati.setText("");
}
void resethewani() {
txt_grhewani.setText("");
}
void resetsayur() {
txt_grsayur.setText("");
}
void resetbuah() {
txt_grbuah.setText("");
}
public hitung_gizi2() {
setLayout(null);
setLocation(300, 100);
aksi();
tampil();
setResizable(false);
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
setSize(800, 600);
setVisible(true);
}
void submit() {
}
public static void main(String[] args) {
hitung_gizi2 a = new hitung_gizi2();
a.tampil();
a.aksi();
}
}
Tidak ada komentar:
Posting Komentar