当前位置:首页 > Java习题集3 - 图文
button4.addActionListener(this);
add(button1);add(button2);add(button3);add(button4); setBounds(100,100,400,200); setVisible(true); }
public void actionPerformed(ActionEvent e) {
if(e.getSource()==button1) {
window1.setVisible(true); }
else if(e.getSource()==button3) {
window1.setVisible(false); }
else if(e.getSource()==button2) {
window2.setVisible(true); }
else if(e.getSource()==button4) {
window2.setVisible(false); } } }
public class Class1 {
public static void main (String[] args) {
new F6(); } }
11、在显示区域上有一个文本域、一个面板和由三个单选按钮组成的按钮组,每个单选按钮对应的标识为?中国队?,?韩国队?,?日本队?并放入面板中。当选择相应的单选按钮时。在文本域中会显示出相应的?选中了XX队?。编写程序代码完成上述要求,布局由自己定。 答:程序如下 import java.awt.*;
import java.awt.event.*;
- 49 -
class F7 extends Frame implements ItemListener {
Label label1;
TextField text1; Panel p;
CheckboxGroup checkboxgroup1; Checkbox radio1; Checkbox radio2; Checkbox radio3; F7() {
Label label1= new Label(\请选择参赛队:\ text1=new TextField(40); p=new Panel();
checkboxgroup1=new CheckboxGroup();
radio1=new Checkbox(\中国队\ radio2=new Checkbox(\韩国队\ radio3=new Checkbox(\日本队\ radio1.addItemListener(this);
radio2.addItemListener(this); radio3.addItemListener(this); p.add(radio1); p.add(radio2); p.add(radio3); add(label1); add(p);
add(text1);
setBounds(100,100,400,200); setVisible(true); }
public void itemStateChanged(ItemEvent e) {
if (e.getItemSelectable()==radio1) {
text1.setText(\选中了中国队\ }
else if (e.getItemSelectable()==radio2) {
text1.setText(\选中了韩国队\
- 50 -
共分享92篇相关文档