JRadioButton dan ButtonGroup Sebuah pilihan tombol radio - item yang dapat dipilih atau tidak terpilih, dan yang menampilkan para negara pengguna. Digunakan dengan objek ButtonGroup untuk menciptakan sekelompok tombol di mana hanya satu tombol pada suatu waktu dapat dipilih. (untuk membuat objek dan ButtonGroup menggunakan metode menambahkan untuk menyertakan object JRadioButton dalam kelompok.)
Konstructor
JRadioButton () Menciptakan awalnya dipilih tombol radio tanpa teks ditetapkan. JRadioButton (Action a) Menciptakan properti radiobutton mana diambil dari aksi disediakan. JRadioButton (Icon icon) Menciptakan awalnya dipilih tombol radio dengan gambar tertentu, tetapi tidak ada teks. JRadioButton (Icon icon, boolean dipilih) Menciptakan tombol radio dengan gambar dan seleksi yang ditentukan tanda, tetapi tidak ada teks. JRadioButton (String teks) Menciptakan tombol radio dipilih dengan teks tertentu. JRadioButton (String teks, boolean selected) Menciptakan tombol radio dengan teks dan seleksi state. JRadioButton (String teks, Icon icon) Menciptakan tombol radio yang memiliki teks dan gambar tertentu, dan itu adalah awalnya dipilih. JRadioButton (String teks, Icon icon, boolean selected) Menciptakan tombol radio tertentu yang memiliki teks, gambar, dan seleksi state.
Method
public void configurePropertiesFromAction (Action a) Metode pabrik yang menetapkan sumber ActionEvent's properti sesuai dengan nilai-nilai dari Aksi contoh.
PropertyChangeListener protected createActionPropertyChangeListener (Action a) Metode pabrik yang menciptakan PropertyChangeListener digunakan untuk memperbarui sumber ActionEvent sebagai perubahan properti pada Aksi misalnya.
AccessibleContext getAccessibleContext () Mendapatkan AccessibleContext terkait dengan JRadioButton ini.
String getUIClassID () Mengembalikan nama L & F kelas yang membuat komponen ini.
String protected paramString () Mengembalikan sebuah string representasi JRadioButton ini.
void updateUI () Reset UI properti ke nilai saat ini dari tampilan dan nuansa
ButtonGroup Kelas ini digunakan untuk membuat multi-lingkup pengecualian untuk satu set tombol. Menciptakan satu set tombol ButtonGroup dengan objek yang sama berarti salah satu yang dipilh, dari tombol-tombol tersebut akan menonaktifkan semua tombol lain dalam grup. Sebuah ButtonGroup dapat digunakan dengan setiap himpunan objek yang mewarisi dari AbstractButton. Biasanya kelompok tombol berisi contoh JRadioButton, JRadioButtonMenuItem, atau JToggleButton. Itu tidak masuk akal untuk menempatkan sebuah instance dari JLabel atau tombol JMenuItem dalam grup ini karena JMenuItem JLabel dan tidak menjalankan negara yang dipilih. Pada awalnya, semua tombol dalam grup tersebut dipilih. Setelah dipilih tombol apapun, satu tombol selalu dipilih dalam grup. Tidak ada cara untuk mengubah tombol pemrograman untuk "off", dalam rangka untuk menghapus grup tombol. Untuk memberi kesan "tidak ada yang dipilih", tambahkan tombol radio yang tak terlihat untuk kelompok dan kemudian pemrograman pilih yang tombol untuk menonaktifkan semua tombol radio yang ditampilkan. Sebagai contoh, tombol normal dengan label "none" dapat ditransfer untuk memilih tombol radio tak terlihat.
Konstructor
public ButtonGroup()
Mambuat ButtonGroup baru.
Method
public void add (AbstractButton b) Menambahkan tombol, atau kelompok pilaiah ke grup. public void remove (AbstractButton b)
Menghapus tombol dari grup. Enumeration publik getElements () Kembali semua tombol yang berpartisipasi dalam grup ini. ButtonModel publik getSelection ()
Mengembalikan model tombol yang dipilih. public void setSelected (ButtonModel m, oolean b) Menetapkan nilai yang dipilih untuk ButtonModel. Hanya satu tombol dalam kelompok dapat dipilih pada satu waktu. public boolean isSelected (ButtonModel m) Kembali apakah ButtonModel dipilih. public int getButtonCount ()
Kuliah Pemrograman Desktop Java [Badiyanto, S..Kom. M.Kom] …………………
Mengembalikan jumlah tombol dalam kelompok.
Latihan
Form dibawah ini akan memasukan nama dan pilihan jenis kelamin dan Status.
Jika Jenis kelamin Laki-laki, dan setatus menikah dipanggil bapak dan kalau belum menikahdipanggil Mas. Jika Jenis kelamin Perempuan, dan status menikah dipanggil ibu, jika belum menikah dipanggil Mbak. Rancanglah form berikut :
Kode Program
/*
* NewJFrameRadio.java
*
* Created on 27 Feb 10, 0:18:53
*/
/**
*
* @author Badiyanto
*/
public class NewJFrameRadio extends javax.swing.JFrame {
String sk,st;
/** Creates new form NewJFrameRadio */
Kuliah Pemrograman Desktop Java [Badiyanto, S..Kom. M.Kom] …………………
Kuliah Pemrograman Desktop Java [Badiyanto, S..Kom. M.Kom] …………………
public NewJFrameRadio() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jRadioButton1 = new javax.swing.JRadioButton();
jRadioButton2 = new javax.swing.JRadioButton();
jLabel1 = new javax.swing.JLabel();
jTextFieldNama = new javax.swing.JTextField();
jPanel2 = new javax.swing.JPanel();
jRadioButtonTidakNikah = new javax.swing.JRadioButton();
jRadioButtonNikah = new javax.swing.JRadioButton();
jTextFieldPanggil = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Program Pilihan Radio Button");
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createTitledBorder("Jenis Kelamin")));
jPanel1.setName("jPanel1");
jRadioButton1.setText("Laki-laki");
jRadioButton1.setName("jRadioButton1"); // NOI18N
jRadioButton1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jRadioButton1MouseClicked(evt);
}
});
jRadioButton2.setText("Perempuan");
jRadioButton2.setName("jRadioButton2"); // NOI18N
jRadioButton2.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jRadioButton2MouseClicked(evt);
}
});
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(35, 35, 35)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jRadioButton2)
Kuliah Pemrograman Desktop Java [Badiyanto, S..Kom. M.Kom] …………………
.addComponent(jRadioButton1))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jRadioButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jRadioButton2))
);
jLabel1.setText("Nama");
jLabel1.setName("jLabel1"); // NOI18N
jTextFieldNama.setName("jTextFieldNama"); // NOI18N
jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Status"));
jPanel2.setName("jPanel2"); // NOI18N
jRadioButtonTidakNikah.setText("Tidak Nikah");
jRadioButtonTidakNikah.setName("jRadioButtonTidakNikah"); // NOI18N
jRadioButtonTidakNikah.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jRadioButtonTidakNikahMouseClicked(evt);
}
});
jRadioButtonNikah.setText("Nikah");
jRadioButtonNikah.setName("jRadioButtonNikah"); // NOI18N
jRadioButtonNikah.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jRadioButtonNikahMouseClicked(evt);
}
});
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(23, 23, 23)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jRadioButtonNikah)
.addComponent(jRadioButtonTidakNikah))
.addContainerGap(30, Short.MAX_VALUE))
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(jRadioButtonTidakNikah)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jRadioButtonNikah)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE,
Kuliah Pemrograman Desktop Java [Badiyanto, S..Kom. M.Kom] …………………
Short.MAX_VALUE))
);
jTextFieldPanggil.setName("jTextFieldPanggil"); // NOI18N
jLabel2.setText("Dipanggil");
jLabel2.setName("jLabel2"); // NOI18N
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(40, 40, 40)
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jTextFieldNama, javax.swing.GroupLayout.PREFERRED_SIZE, 216, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGap(28, 28, 28)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(36, 36, 36)
.addComponent(jLabel2)
.addGap(18, 18, 18)
.addComponent(jTextFieldPanggil, javax.swing.GroupLayout.PREFERRED_SIZE, 252, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
.addContainerGap(51, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(jTextFieldNama, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(29, 29, 29)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(jPanel2, 0, 84, Short.MAX_VALUE)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,
Kuliah Pemrograman Desktop Java [Badiyanto, S..Kom. M.Kom] …………………
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(12, 12, 12)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(jTextFieldPanggil, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(124, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void jRadioButton1MouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
if (jRadioButton1.isSelected()) {
jRadioButton2.setSelected(false);
sk="L";
}
}
private void jRadioButton2MouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
if (jRadioButton2.isSelected())
{
jRadioButton1.setSelected(false);
sk="P";
}
}
private void jRadioButtonTidakNikahMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
if (jRadioButtonTidakNikah.isSelected()) {
jRadioButtonNikah.setSelected(false);
st="B";
}
jTextFieldPanggil.setText(Panggil(sk,st)+" "+jTextFieldNama.getText());
}
private void jRadioButtonNikahMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
if (jRadioButtonNikah.isSelected()) {
jRadioButtonTidakNikah.setSelected(false);
st="K";
}
jTextFieldPanggil.setText(Panggil(sk,st)+" "+jTextFieldNama.getText());
}
private String Panggil(String Seks, String status)
{
if (Seks.equals("L")) {
if (status.equals("B")){
return("Mas");
}
else {
return("Pak");
}
}
else {
if (status.equals("B")){
return("Mbak");
Kuliah Pemrograman Desktop Java [Badiyanto, S..Kom. M.Kom] …………………
}
else {
return("Ibu");
}
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrameRadio().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JRadioButton jRadioButton1;
private javax.swing.JRadioButton jRadioButton2;
private javax.swing.JRadioButton jRadioButtonNikah;
private javax.swing.JRadioButton jRadioButtonTidakNikah;
private javax.swing.JTextField jTextFieldNama;
private javax.swing.JTextField jTextFieldPanggil;
// End of variables declaration
}
/*
* NewJFrameRadio.java
*
* Created on 27 Feb 10, 0:18:53
*/
/**
*
* @author Badiyanto
*/
public class NewJFrameRadio extends javax.swing.JFrame {
String sk,st;
/** Creates new form NewJFrameRadio */
Kuliah Pemrograman Desktop Java [Badiyanto, S..Kom. M.Kom] …………………
Kuliah Pemrograman Desktop Java [Badiyanto, S..Kom. M.Kom] …………………
public NewJFrameRadio() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jRadioButton1 = new javax.swing.JRadioButton();
jRadioButton2 = new javax.swing.JRadioButton();
jLabel1 = new javax.swing.JLabel();
jTextFieldNama = new javax.swing.JTextField();
jPanel2 = new javax.swing.JPanel();
jRadioButtonTidakNikah = new javax.swing.JRadioButton();
jRadioButtonNikah = new javax.swing.JRadioButton();
jTextFieldPanggil = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Program Pilihan Radio Button");
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createTitledBorder("Jenis Kelamin")));
jPanel1.setName("jPanel1");
jRadioButton1.setText("Laki-laki");
jRadioButton1.setName("jRadioButton1"); // NOI18N
jRadioButton1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jRadioButton1MouseClicked(evt);
}
});
jRadioButton2.setText("Perempuan");
jRadioButton2.setName("jRadioButton2"); // NOI18N
jRadioButton2.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jRadioButton2MouseClicked(evt);
}
});
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(35, 35, 35)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jRadioButton2)
Kuliah Pemrograman Desktop Java [Badiyanto, S..Kom. M.Kom] …………………
.addComponent(jRadioButton1))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jRadioButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jRadioButton2))
);
jLabel1.setText("Nama");
jLabel1.setName("jLabel1"); // NOI18N
jTextFieldNama.setName("jTextFieldNama"); // NOI18N
jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Status"));
jPanel2.setName("jPanel2"); // NOI18N
jRadioButtonTidakNikah.setText("Tidak Nikah");
jRadioButtonTidakNikah.setName("jRadioButtonTidakNikah"); // NOI18N
jRadioButtonTidakNikah.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jRadioButtonTidakNikahMouseClicked(evt);
}
});
jRadioButtonNikah.setText("Nikah");
jRadioButtonNikah.setName("jRadioButtonNikah"); // NOI18N
jRadioButtonNikah.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jRadioButtonNikahMouseClicked(evt);
}
});
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(23, 23, 23)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jRadioButtonNikah)
.addComponent(jRadioButtonTidakNikah))
.addContainerGap(30, Short.MAX_VALUE))
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(jRadioButtonTidakNikah)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jRadioButtonNikah)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE,
Kuliah Pemrograman Desktop Java [Badiyanto, S..Kom. M.Kom] …………………
Short.MAX_VALUE))
);
jTextFieldPanggil.setName("jTextFieldPanggil"); // NOI18N
jLabel2.setText("Dipanggil");
jLabel2.setName("jLabel2"); // NOI18N
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(40, 40, 40)
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jTextFieldNama, javax.swing.GroupLayout.PREFERRED_SIZE, 216, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGap(28, 28, 28)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(36, 36, 36)
.addComponent(jLabel2)
.addGap(18, 18, 18)
.addComponent(jTextFieldPanggil, javax.swing.GroupLayout.PREFERRED_SIZE, 252, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
.addContainerGap(51, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(jTextFieldNama, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(29, 29, 29)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(jPanel2, 0, 84, Short.MAX_VALUE)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,
Kuliah Pemrograman Desktop Java [Badiyanto, S..Kom. M.Kom] …………………
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(12, 12, 12)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(jTextFieldPanggil, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(124, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void jRadioButton1MouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
if (jRadioButton1.isSelected()) {
jRadioButton2.setSelected(false);
sk="L";
}
}
private void jRadioButton2MouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
if (jRadioButton2.isSelected())
{
jRadioButton1.setSelected(false);
sk="P";
}
}
private void jRadioButtonTidakNikahMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
if (jRadioButtonTidakNikah.isSelected()) {
jRadioButtonNikah.setSelected(false);
st="B";
}
jTextFieldPanggil.setText(Panggil(sk,st)+" "+jTextFieldNama.getText());
}
private void jRadioButtonNikahMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
if (jRadioButtonNikah.isSelected()) {
jRadioButtonTidakNikah.setSelected(false);
st="K";
}
jTextFieldPanggil.setText(Panggil(sk,st)+" "+jTextFieldNama.getText());
}
private String Panggil(String Seks, String status)
{
if (Seks.equals("L")) {
if (status.equals("B")){
return("Mas");
}
else {
return("Pak");
}
}
else {
if (status.equals("B")){
return("Mbak");
Kuliah Pemrograman Desktop Java [Badiyanto, S..Kom. M.Kom] …………………
}
else {
return("Ibu");
}
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrameRadio().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JRadioButton jRadioButton1;
private javax.swing.JRadioButton jRadioButton2;
private javax.swing.JRadioButton jRadioButtonNikah;
private javax.swing.JRadioButton jRadioButtonTidakNikah;
private javax.swing.JTextField jTextFieldNama;
private javax.swing.JTextField jTextFieldPanggil;
// End of variables declaration
}
No comments:
Post a Comment