Tuesday, 18 December 2012

Contoh atau Cara ComboBox Di Java



package Java_gui;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class cth_combobox {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
     JFrame frm_combo = new JFrame("Pemakaian ComboBox");
     JLabel lbl_gol = new JLabel("Golongan");
     String item[] = {"","IA","IIA"};
     JComboBox cbo_gol = new JComboBox(item);
     JLabel lbl_gaji = new JLabel("Gaji Pokok");
     final JTextField txt_gaji = new JTextField();
     ActionListener klik = new ActionListener()
     {
            public void actionPerformed(ActionEvent e) {
JComboBox data = (JComboBox) e.getSource();
String teks = (String)data.getSelectedItem();

    if(teks.equals(""))
    txt_gaji.setText("");
    else if (teks.equals("IA"))
    txt_gaji.setText("2000000");
    else
       txt_gaji.setText("100000");
           }
        };
     cbo_gol.addActionListener(klik);
Container konten= frm_combo.getContentPane();
konten.setLayout(null);
konten.add(lbl_gol);
lbl_gol.setBounds(20, 10, 100, 20 );
konten.add(cbo_gol);
cbo_gol.setBounds(120, 10, 75, 20 );

konten.add(lbl_gaji);
lbl_gaji.setBounds(20, 40, 100, 20 );

konten.add(txt_gaji);
txt_gaji.setBounds(120, 40, 110, 20);
txt_gaji.setEnabled(false);


     frm_combo.setLocation(30, 50);
        frm_combo.setSize(300, 150);
        frm_combo.setResizable(false);
        frm_combo.setVisible(true);
        frm_combo.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);




    }

}


Perhatian: Yuk Baca Artikel bagus di Nurul Musthofa

Artikel Terkait

No comments:

Post a Comment

 

Network

Pesan

Semoga situs ini bermanfaat