展开全部
package com.aia.posa.horse.view;
import java.awt.EventQueue;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.border.EmptyBorder;
public class CheckboxGroupExample extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel contentPane;
private TextField display ;
private List list=new ArrayList();
private JRadioButton M240HTN01_20P;
private JRadioButton M238HVN01_00D;
private JRadioButton T215HVN01_10F;
private JRadioButton M238HVN01_00C;
private JRadioButton M238HVN01_00E;
private static String PRE_DISPLAY="程式:";
private static String SUF_DISPLAY=" 恒源灯:2颗";
/**
* Launch the application.
*/
public static void main(String[] args) {
62616964757a686964616fe58685e5aeb931333365653862EventQueue.invokeLater(new Runnable() {
public void run() {
try {
CheckboxGroupExample frame = new CheckboxGroupExample();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public CheckboxGroupExample() {
this.initMainPanel()
.initDisplayTextField()
.initM240HTN01_20P()
.initM238HVN01_00D()
.initT215HVN01_10F()
.initM238HVN01_00C()
.initM238HVN01_00E()
.registClickEvent();
}
private void registClickEvent() {
for(JRadioButton source:list){
source.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
display.setText(PRE_DISPLAY+((JRadioButton) e.getSource()).getText()+SUF_DISPLAY);
}
});
}
}
private CheckboxGroupExample initM238HVN01_00E() {
M238HVN01_00E = new JRadioButton("M238HVN01.00E");
M238HVN01_00E.setBounds(32, 95, 146, 23);
contentPane.add(M238HVN01_00E);
list.add(M238HVN01_00E);
return this;
}
private CheckboxGroupExample initM238HVN01_00C() {
M238HVN01_00C = new JRadioButton("M238HVN01.00C");
M238HVN01_00C.setBounds(251, 58, 146, 23);
contentPane.add(M238HVN01_00C);
list.add(M238HVN01_00C);
return this;
}
private CheckboxGroupExample initT215HVN01_10F() {
T215HVN01_10F = new JRadioButton("T215HVN01.10F");
T215HVN01_10F.setBounds(251, 25, 146, 23);
contentPane.add(T215HVN01_10F);
list.add(T215HVN01_10F);
return this;
}
private CheckboxGroupExample initM238HVN01_00D() {
M238HVN01_00D = new JRadioButton("M238HVN01.00D");
M238HVN01_00D.setBounds(32, 58, 146, 23);
contentPane.add(M238HVN01_00D);
list.add(M238HVN01_00D);
return this;
}
private CheckboxGroupExample initM240HTN01_20P() {
M240HTN01_20P = new JRadioButton("M240HTN01.20P");
M240HTN01_20P.setBounds(32, 25, 146, 23);
contentPane.add(M240HTN01_20P);
list.add(M240HTN01_20P);
return this;
}
private CheckboxGroupExample initDisplayTextField() {
display = new TextField();
display.setBounds(0, 162, 434, 22);
contentPane.add(display);
return this;
}
private CheckboxGroupExample initMainPanel() {
setTitle("Checkboxgroup Example");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 222);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
return this;
}
}