EventCheck.java
kode:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class CheckHandling extends JFrame implements ItemListener{
private JTextField teks;
private JPanel panel;
private JCheckBox CBox1, CBox2, CBox3;
public CheckHandling() {
setTitle("Tugas CheckBox Handling");
teks = new JTextField("Jenis Kelamin : Pilihan");
teks.setHorizontalAlignment(SwingConstants.CENTER);
panel = new JPanel(new FlowLayout());
CBox1 = new JCheckBox("Pria");
CBox2 = new JCheckBox("Wanita");
CBox3 = new JCheckBox("Banci");
ButtonGroup group = new ButtonGroup();
group.add(CBox1);
group.add(CBox2);
group.add(CBox3);
CBox1.addItemListener(this);
CBox2.addItemListener(this);
CBox3.addItemListener(this);
setLayout(new BorderLayout());
add(teks,"North");
add(panel,"West");
panel.add(CBox1);
panel.add(CBox2);
panel.add(CBox3);
pack();
setVisible(true);
setLocation(200,200);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public void itemStateChanged(ItemEvent event) {
if(event.getSource()==CBox1) {
if(event.getStateChange()==ItemEvent.SELECTED)
teks.setText("Jenis Kelamin : Pria");
}
if(event.getSource()==CBox2){
if(event.getStateChange()==ItemEvent.SELECTED)
teks.setText("Jenis Kelamin : Wanita");
}
if(event.getSource()==CBox3){
if(event.getStateChange()==ItemEvent.SELECTED)
teks.setText("Jenis Kelamin : Banci");
}
}
}
public class EventCheck{
public static void main (String[] args){
new CheckHandling();
}
}
Output:
Minggu, 15 Desember 2013
Tugas Pertemuan 8: Manajemen LayOut
MultyLayout.java
kode:
import java.awt.*;
import javax.swing.*;
class MLayout extends JFrame {
JButton tombol0,tombol1,tombol2,tombol3,tombol4,tombol5,tombol6,tombol7,tombol8,tombol9,tombol10,tombol11;
JLabel lNama,lNama2,lNama3;
JPanel P1,P2,P3;
public MLayout() {
setTitle("MULTI LAYOUT");
JLabel lNama= new JLabel("Flow Layout" );
JButton tombol0=new JButton ("0");
JButton tombol1=new JButton ("1");
JButton tombol2=new JButton ("2");
JButton tombol3=new JButton ("3");
JLabel lNama2= new JLabel("None Layout" );
JButton tombol4=new JButton ("4");
JButton tombol5=new JButton ("5");
JButton tombol6=new JButton ("6");
JButton tombol7=new JButton ("7");
JLabel lNama3= new JLabel("Grid Layout" );
JButton tombol8=new JButton ("8");
JButton tombol9=new JButton ("9");
JButton tombol10=new JButton ("10");
JButton tombol11=new JButton ("11");
P1 = new JPanel();
P2 = new JPanel();
P3 = new JPanel();
setLayout(null);
add(lNama);
add(lNama2);
add(lNama3);
add(P1);
add(P2);
add(P3);
lNama.setBounds(15,10,100,20);
lNama2.setBounds(220,10,100,20);
lNama3.setBounds(320,10,100,20);
P1.setBounds(5,30,200,40);
P2.setBounds(215,30,200,100);
P3.setBounds(320,30,200,150);
P1.setLayout(new FlowLayout());
P1.add(tombol0);
P1.add(tombol1);
P1.add(tombol2);
P1.add(tombol3);
P2.setLayout(null);
P2.add(tombol4);
P2.add(tombol5);
P2.add(tombol6);
P2.add(tombol7);
tombol4.setBounds(5,10,70,20);
tombol5.setBounds(5,30,70,20);
tombol6.setBounds(5,50,70,20);
tombol7.setBounds(5,70,70,20);
P3.setLayout(new GridLayout(2,2));
P3.add(tombol8);
P3.add(tombol9);
P3.add(tombol10);
P3.add(tombol11);
setSize(550,220);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
}
public class MultyLayout{
public static void main(String [] args){
MLayout m = new MLayout();
}
}
Output:
kode:
import java.awt.*;
import javax.swing.*;
class MLayout extends JFrame {
JButton tombol0,tombol1,tombol2,tombol3,tombol4,tombol5,tombol6,tombol7,tombol8,tombol9,tombol10,tombol11;
JLabel lNama,lNama2,lNama3;
JPanel P1,P2,P3;
public MLayout() {
setTitle("MULTI LAYOUT");
JLabel lNama= new JLabel("Flow Layout" );
JButton tombol0=new JButton ("0");
JButton tombol1=new JButton ("1");
JButton tombol2=new JButton ("2");
JButton tombol3=new JButton ("3");
JLabel lNama2= new JLabel("None Layout" );
JButton tombol4=new JButton ("4");
JButton tombol5=new JButton ("5");
JButton tombol6=new JButton ("6");
JButton tombol7=new JButton ("7");
JLabel lNama3= new JLabel("Grid Layout" );
JButton tombol8=new JButton ("8");
JButton tombol9=new JButton ("9");
JButton tombol10=new JButton ("10");
JButton tombol11=new JButton ("11");
P1 = new JPanel();
P2 = new JPanel();
P3 = new JPanel();
setLayout(null);
add(lNama);
add(lNama2);
add(lNama3);
add(P1);
add(P2);
add(P3);
lNama.setBounds(15,10,100,20);
lNama2.setBounds(220,10,100,20);
lNama3.setBounds(320,10,100,20);
P1.setBounds(5,30,200,40);
P2.setBounds(215,30,200,100);
P3.setBounds(320,30,200,150);
P1.setLayout(new FlowLayout());
P1.add(tombol0);
P1.add(tombol1);
P1.add(tombol2);
P1.add(tombol3);
P2.setLayout(null);
P2.add(tombol4);
P2.add(tombol5);
P2.add(tombol6);
P2.add(tombol7);
tombol4.setBounds(5,10,70,20);
tombol5.setBounds(5,30,70,20);
tombol6.setBounds(5,50,70,20);
tombol7.setBounds(5,70,70,20);
P3.setLayout(new GridLayout(2,2));
P3.add(tombol8);
P3.add(tombol9);
P3.add(tombol10);
P3.add(tombol11);
setSize(550,220);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
}
public class MultyLayout{
public static void main(String [] args){
MLayout m = new MLayout();
}
}
Output:
Langganan:
Postingan (Atom)