Bram Keren
Bram Keren
Bram Keren
*;
import java.awt.*;
import java.awt.event.*;
frm1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// class sedan
// anonymous class 1
{ hitung1++;
label1.setText(String.valueOf(hitung1));
}; // akhir a.c.1
b1.addActionListener(act1);
JButton b2 = new JButton("”Koreksi”");
// a.c.2
{ if (hitung1 == 0) hitung1 = 0;
else hitung1-=1;
label1.setText(String.valueOf(hitung1));
}; // akhir a.c.2
b2.addActionListener(act2);
// class mpv
// anonymous class 1
{ hitung2++;
label2.setText(String.valueOf(hitung2));
}; // akhir a.c.1
b3.addActionListener(act3);
// a.c.2
else hitung2-=1;
label2.setText(String.valueOf(hitung2));
}; // akhir a.c.2
b4.addActionListener(act4);
// class motor
// anonymous class 1
{ hitung3++;
label3.setText(String.valueOf(hitung3));
}; // akhir a.c.1
b5.addActionListener(act5);
// a.c.2
{ if (hitung3 == 0) hitung3 = 0;
else hitung3-=1;
label3.setText(String.valueOf(hitung3));
}
}; // akhir a.c.2
b6.addActionListener(act6);
kon1.setLayout(lay1);
kon1.add(b1);
kon1.add(b3);
kon1.add(b5);
kon1.add(label1);
kon1.add(label2);
kon1.add(label3);
kon1.add(b2);
kon1.add(b4);
kon1.add(b6);
frm1.setPreferredSize(sz);
// displaying
frm1.pack();
frm1.setVisible(true);
}
public static void main(String a[])
// run in EDT
SwingUtilities.invokeLater(sw);
}
import javax.swing.*;
import java.awt.event.*;
import java.util.Random;
x.setVisible(true);
setSize (500,500);
bram.setLayout(null);
lbllebar.setBounds(30,80,100,25);
lblluas.setBounds(30,175,100,25);
bram.add(lblpanjang);
bram.add(lbllebar);
bram.add(lblluas);
txtpanjang.setBounds(150,30,50,25);
txtlebar.setBounds(150,80,50,25);
tfluas.setBounds(150,175,50,25);
bram.add(txtpanjang);
bram.add(txtlebar);
bram.add(tfluas);
getContentPane().add(bram);
txtpanjang.addKeyListener(new KeyAdapter()
String d= txtpanjang.getText();
if(evt.getSource()== txtpanjang)
if(c==KeyEvent.VK_ENTER)
if(d.length()==2)
{ if(!Character.isDigit(d.charAt(1)) || !Character.isDigit(d.charAt(0)))
"ERROR",JOptionPane.ERROR_MESSAGE);
txtpanjang.setText("");
txtpanjang.requestFocus();
else
{ txtlebar.requestFocus();
else if(Character.isDigit(d.charAt(0)))
{ txtlebar.requestFocus();
else
"ERROR",JOptionPane.ERROR_MESSAGE);
txtpanjang.setText("");
txtpanjang.requestFocus();
{ char c= ke.getKeyChar();
if(txtpanjang.getText().length()>3)
ke.consume();
});
txtlebar.addKeyListener(new KeyAdapter(){
String d=txtlebar.getText();
if(evt.getSource()==txtlebar)
if(c==KeyEvent.VK_ENTER)
if(d.length()==2){
if(!Character.isDigit(d.charAt(1)) || !Character.isDigit(d.charAt(0))){
"ERROR",JOptionPane.ERROR_MESSAGE);
txtlebar.setText("");
txtlebar.requestFocus();
}else {
tfluas.requestFocus();
hitungluas();
posisiAcak();
} else if(Character.isDigit(d.charAt(0))) {
tfluas.requestFocus();
hitungluas();
posisiAcak();
} else {
"ERROR",JOptionPane.ERROR_MESSAGE);
txtlebar.requestFocus();
char c= ke.getKeyChar();
if(txtlebar.getText().length()>1)
ke.consume();
});
String sPanjang=txtpanjang.getText();
String sLebar=txtlebar.getText();
tfluas.setText(sLuas);
}
int corX,corY;
corX =r1.nextInt(400);
tfluas.setBounds(corX,corY,50,25);
}
Jcombobox
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public TestJComboBox() {
getContentPane().setBackground(Color.red);
setLayout(new FlowLayout());
add(cbo);
cbo.addItemListener(this);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setTitle("Test ComboBox");
setBounds(300,300,250,250);//( X, Y, panjang X, panjang Y)
theApp.setVisible(true);
if(e.getStateChange()==ItemEvent.SELECTED){
if(item.equals("merah")){
getContentPane().setBackground(Color.green);
} else if (item.equals("hijau")){
//getContentPane().setBackground(Color.black);
new test1().setVisible(true);
} else if (item.equals("biru")){
getContentPane().setBackground(Color.blue);
} else if (item.equals("hitam")){
getContentPane().setBackground(Color.yellow);
} else if (item.equals("kuning")){
getContentPane().setBackground(Color.yellow);
}
TestRadioCheck
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
pnlRadio.setLayout(new GridLayout(2,3));
pnlRadio.add(new JLabel("Gender"));
pnlRadio.add(radMale);
pnlRadio.add(radFemale);
pnlRadio.add(new JLabel("Membership"));
pnlRadio.add(radMember);
pnlRadio.add(radNonMember);
grpGender.add(radMale);
grpGender.add(radFemale);
grpMembership.add(radMember);
grpMembership.add(radNonMember);
radMale.setSelected(true);
radMember.setSelected(true);
//SET CHECK
pnlCheck.setLayout(new FlowLayout());
pnlCheck.add(haveCC);
pnlCheck.add(btnShow);
btnShow.addActionListener(this);
setLayout(new FlowLayout());
add(pnlRadio);
add(pnlCheck);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setTitle("Test Combobox2");
setBounds(0,0,350,150);
theApp.setVisible(true);
JOptionPane.showMessageDialog(this,str);