Sie sind auf Seite 1von 5

/*

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/

package tespilihan;

import com.sun.org.apache.bcel.internal.generic.RETURN;

import java.awt.*;

import java.awt.event.*;

/**

* @author Lab. Statis

*/

public class tespilihan extends Frame

Checkbox cb1,cb2,cb3,cb4,cb5,cb6;

CheckboxGroup cbg;

TextArea ta1,ta2;

Label l1,l2;

public static void main (String[]args){

tespilihan tsp = new tespilihan();

}
public tespilihan(){

setSize(500,300);

Panel p1 = new Panel();

p1.setBackground(Color.GRAY);

p1.setSize(300,500);

p1.setLayout(new GridLayout (8,1));

p1.add(l1 = new Label("Checkbox"));

l1.setForeground(Color.YELLOW);

p1.add(cb1=new Checkbox("Java"));

p1.add(cb2=new Checkbox("C++"));

p1.add(cb3=new Checkbox("PHP"));

cbg=new CheckboxGroup();

p1.add(l2 = new Label("CheckBoxGroup"));

l2.setForeground(Color.BLUE);

p1.add(cb4=new Checkbox("satu",cbg,true));

p1.add(cb5=new Checkbox("dua",cbg,false));

p1.add(cb6=new Checkbox("tiga",cbg,false));

add("West",p1);

show();

Panel p2 = new Panel();

p2.setBackground(Color.BLUE);

p2.setLayout(new GridLayout (2,1));

p2.add(ta1 = new TextArea ("",3,35, TextArea.SCROLLBARS_NONE));

ta1.setEditable(false);

p2.add(ta2 = new TextArea ("",3,35, TextArea.SCROLLBARS_NONE));

ta2.setEditable(false);

add("East",p2);
cb1.addItemListener(new tespilihan.a());

cb2.addItemListener(new tespilihan.a());

cb3.addItemListener(new tespilihan.a());

cb4.addItemListener(new tespilihan.a());

cb5.addItemListener(new tespilihan.a());

cb6.addItemListener(new tespilihan.a());

show();

public boolean handleEvent (Event check)

switch (check.id)

case Event.WINDOW_DESTROY: //perintah untuk menutup program saat diklik close (Simbol
ujung kanan atas)

System.exit(0); //menutup program

} return false;

public void tampilkan(){

ta1.setText("Status java : "+ cb1.getState()+"\n status c++"+ cb2.getState()+"\n status php : "+
cb3.getState()+"");

public void tampilkan1(){

ta2.setText("Yang Terpilih : \n tombol radio \n satu");

public void tampilkan2(){


ta2.setText("Yang Terpilih : \n tombol radio \n dua");

public void tampilkan3(){

ta2.setText("Yang Terpilih : \n tombol radio \n tiga");

class a implements ItemListener{

public void itemStateChanged (ItemEvent e){

Object o = e.getItem();

if (o.equals("Java")){

tampilkan();

else if (o.equals("C++")){

tampilkan();

else if (o.equals("PHP")){

tampilkan();

else if (o.equals("satu")){

tampilkan1();

else if (o.equals("dua")){

tampilkan2();

else if (o.equals("tiga")){

tampilkan3();
}