云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > Java习题集3 - 图文

Java习题集3 - 图文

  • 62 次阅读
  • 3 次下载
  • 2025/5/1 15:44:45

{

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 - 图文 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

{ 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、设计两个文本区和一个?确定?按钮,当在第一个文本区输入文本时,第二个文本区也会显示相同的

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com