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

Java习题集3 - 图文

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

{

n=n1*n2;

text3.setText(String.valueOf(n)); } else {

n=n1/n2;

text3.setText(String.valueOf(n)); } } }

public class Class1 {

public static void main (String[] args) {

new F3(); } }

8、设计两个文本区和一个?确定?按钮,当在第一个文本区输入文本时,第二个文本区也会显示相同的文本;当点击按钮时,在第二个文本区内会显示?我按了确定按钮?

import java.awt.*;

import java.awt.event.*;

class F4 extends Frame implements TextListener,ActionListener { TextArea text1,text2;Button button; F4()

{ text1=new TextArea(\ text2=new TextArea(\ button=new Button(\确定\

add(text1);add(text2);add(button); text1.addTextListener(this); button.addActionListener(this); setBounds(100,100,400,200); setVisible(true); }

public void textValueChanged(TextEvent e) { if(e.getSource()==text1)

{ text2.setText(text1.getText()); }

- 45 -

}

public void actionPerformed(ActionEvent e) { if (e.getSource()==button)

text2.setText(\我按了确定按钮\ } }

public class Class1 {

public static void main (String[] args) {

new F4(); } }

9、下图是一程序的运行结果,请编程序完成。

import java.awt.*;

class Mypanel1 extends Panel {

Checkbox box1,box2,box3; Mypanel1() {

box1=new Checkbox(\音乐\ box2=new Checkbox(\体育\ box3=new Checkbox(\吹牛\

add(box1);add(box2);add(box3); } }

class Mypanel2 extends Panel {

Checkbox box1,box2,box3;

- 46 -

Mypanel2() {

box1=new Checkbox(\读书\ box2=new Checkbox(\电脑\ box3=new Checkbox(\电影\

add(box1);add(box2);add(box3); } }

class F5 extends Frame {

Mypanel1 panel1; Mypanel2 panel2; F5() {

setLayout(new GridLayout(2,2)); panel1=new Mypanel1(); panel2=new Mypanel2();

add(panel1);add(new Label());add(new Label());add(panel2); setBounds(100,100,400,200); setVisible(true); } }

public class Class1 {

public static void main (String[] args) {

new F5(); } }

10、如下图所示,当单击?开南窗?按钮时,出现名字为?阳光窗口?;当单击?开北窗?按钮时,出现名字为?冰雪之窗?的窗口;当单击?关南窗?或?关北窗?按钮时,相应窗口就关闭。

- 47 -

答:程序如下 import java.awt.*;

import java.awt.event.*;

class Yourwindow extends Frame {

Yourwindow(String s,int a,int b) {

super(s);

setLayout(new GridLayout(1,1)); setSize(a,b);

setBackground(Color.white); setVisible(false); validate(); } }

class F6 extends Frame implements ActionListener {

Yourwindow window1,window2;

Button button1,button2,button3,button4; F6() {

button1=new Button(\开南窗\ button2=new Button(\开北窗\ button3=new Button(\关南窗\ button4=new Button(\关北窗\

window1=new Yourwindow(\阳光之窗\ window2=new Yourwindow(\冰雪之窗\ button1.addActionListener(this); button2.addActionListener(this); button3.addActionListener(this);

- 48 -

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