第一范文网 - 专业文章范例文档资料分享平台

Java习题集3 - 图文

来源:用户分享 时间:2025/10/2 15:50:10 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

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 -

搜索更多关于: Java习题集3 - 图文 的文档
Java习题集3 - 图文.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c3pao431apw7916195czl_13.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top