Java方法调用事件_在Java GUI中,怎么实现一个事件处理调用另一个事件处理

给你写个简单的例子:

public class TestJFrame extends JFrame implements ActionListener{

ButtonGroup group;

JRadioButton smallButton;

JRadioButton largeButton;

JButton jbtopic; // 建议你的“题目”用Button控件

public TestJFrame (){

this.setVisible(true);

jbtopic = new JButton("题目");

jbtopic.addActionListener(this); //给jbtopic 按钮注册监听

group = new ButtonGroup();

smallButton = new JRadioButton("Small",true);

largeButton = new JRadioButton("Large",false);

group.add(smallButton );

group.add(largeButton );

this.setLayout(new GridLayout(2,1)); //设置布局方式为网格布局,行列数自己改一下

this.add(smallButton);

this.add(largeButton);

this.add(jbtopic);

}

public static void main(String[] args) {

TestJFrame tjf = new TestJFrame();

}

public void actionPerformed(ActionEvent e) {

if( e.getActionCommand().equals("题目") ){

if(smallButton.isSelected()) {

System.out.println("small");

}

if(largeButton.isSelected()) { //用isSelected返回true,或者false

System.out.println("large");

}

}

}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值