练习59

import java.awt.*;

import javax.swing.*;

import java.awt.event.*;

public class JRadioButtonDemo extends JFrame {

protected JPanel topPanel;

private Container container;

public JRadioButtonDemo() {

container = this.getContentPane();//获取内容窗格

topPanel = new JPanel();

topPanel.setLayout(new FlowLayout(FlowLayout.LEFT));

// 设置边框文本提示信息

topPanel.setBorder(BorderFactory.createTitledBorder("借阅查询选项"));

JRadioButton currBorrowButton = new JRadioButton("当前借阅");

JRadioButton oldBorrowButton = new JRadioButton("历史借阅");

topPanel.add(currBorrowButton); //添加组件到面板容器

topPanel.add(oldBorrowButton); //添加组件到面板容器

// 注册事件监听程序,对ActionEvent事件作出处理

currBorrowButton.addActionListener(new CurrentBorrowInfoListener());

oldBorrowButton.addActionListener(new OldBorrowInfoListener());

/** 将2个RadioButton对象放进ButtonGroup中,以实现二选一 */

ButtonGroup buttonGroup1 = new ButtonGroup();

buttonGroup1.add(currBorrowButton);

buttonGroup1.add(oldBorrowButton);

this.add(BorderLayout.NORTH, topPanel); //把面板容器添加到内容窗格上

this.setTitle("图书管理系统我的借阅"); //设置标题

this.setSize(600, 450);//设置大小

this.setVisible(true);//设置可见性

}

class CurrentBorrowInfoListener implements ActionListener {

public void actionPerformed(ActionEvent event) {

// 把当前借阅信息从数据库取出,以表格的形式显示出来,代码实现见13章

}

}

class OldBorrowInfoListener implements ActionListener {

public void actionPerformed(ActionEvent event) {

// 把历史借阅信息从数据库取出,以表格的形式显示出来,代码实现见13章

}

}

public static void main(String[] arg) {

new JRadioButtonDemo();

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值