java swing 多个按钮_Java awt里多个按钮如何实现多个功能 ??大神来!!!

展开全部

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;

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值