import javax.swing.*;
import java.awt.event.*;
class Aplikasi_Event_CheckBox extends JFrame
{
JLabel ibnama = new JLabel ("Nama");
JTextField txnama=new JTextField(20);
JLabel ibnim = new JLabel ("NIM");
JTextField txnim=new JTextField(8);
JLabel ibkelamin = new JLabel ("Jenis Kelamin");
JRadioButton pria = new JRadioButton("pria");
JRadioButton wanita = new JRadioButton("wanita");
ButtonGroup kelompok = new ButtonGroup();
JLabel ibkelompok = new JLabel("Kelompok");
String [] jeniskelompok = {"1","2","3","4","5","6","7"} ;
JComboBox cbkelompok = new JComboBox(jeniskelompok);
JLabel ibhobi=new JLabel("Hobi");
JCheckBox baca=new JCheckBox("Membaca");
JCheckBox mancing=new JCheckBox("Memancing");
JCheckBox jalan=new JCheckBox("Jalan-Jalan");
JButton cetak=new JButton("Cetak");
JTextArea hasil=new JTextArea();
Aplikasi_Event_CheckBox()
{
setTitle("Event Sederhana");
setLocation(300,100);
setSize(300,520);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
void KomponenVisual()
{
getContentPane().setLayout(null);
getContentPane().add(ibnama);
ibnama.setBounds(10,10,80,20);
getContentPane().add(txnama);
txnama.setBounds(105,10,175,20);
getContentPane().add(ibnim);
ibnim.setBounds(10,33,80,20);
getContentPane().add(txnim);
txnim.setBounds(105,33,70,20);
getContentPane().add(ibkelamin);
ibkelamin.setBounds(10,56,80,20);
kelompok.add(pria);
kelompok.add(wanita);
getContentPane().add(pria);
pria.setBounds(105,56,50,20);
getContentPane().add(wanita);
wanita.setBounds(160,56,70,20);
getContentPane().add(ibkelompok);
ibkelompok.setBounds(10,80,90,20);
getContentPane().add(cbkelompok);
cbkelompok.setBounds(105,80,100,20);
getContentPane().add(ibhobi);
ibhobi.setBounds(10,110,70,20);
getContentPane().add(baca);
baca.setBounds(105,110,100,20);
getContentPane().add(mancing);
mancing.setBounds(105,130,100,20);
getContentPane().add(jalan);
jalan.setBounds(105,150,100,20);
getContentPane().add(cetak);
cetak.setBounds(10,180,270,20);
getContentPane().add(hasil);
hasil.setBounds(10,210,270,270);
setVisible(true);
}
void AksiReaksi()
{
cetak.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
hasil.append(txnama.getText()+"\n");
hasil.append(txnim.getText()+"\n");
hasil.append(cbkelompok.getSelectedItem()+"\n");
if(pria.isSelected()==true)
{
hasil.append(pria.getText()+"\n");
}
else
{
hasil.append(wanita.getText()+"\n");
}
if(baca.isSelected()==true)
{
hasil.append(baca.getText()+"\n");
}
if(mancing.isSelected()==true)
{
hasil.append(mancing.getText()+"\n");
}
if(jalan.isSelected()==true)
{
hasil.append(jalan.getText()+"\n");
}}});}
public static void main(String args[])
{
Aplikasi_Event_CheckBox AEC=new Aplikasi_Event_CheckBox();
AEC.KomponenVisual();
AEC.AksiReaksi();
}}
**OutPut**
No comments:
Write comments