首页 > 题库 > 学历提升 > 自学考试 > 自考本科 > 设计题

类Test33显示一个窗口,其中含有两个标签、两个文本框及三个按钮。如题33图所示。单击Clear按钮时清空两个文本框的内容;单击Copy按钮时将上面文本框的内容复制到下面的文本框中;单击Close按钮则结束程序的运行。
要求:编写代码,实现单击三个按钮所完成的事件处理程序。

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Test33 extends WindowAdapter implements ActionListener{
JFrame f;
JButton bClear, bCopy,bClose;
JLabel ISource, ITarget, ISpacel, ISpace2;
JTextField tfs,tft;String ad="How are you!";
public static void main(String args []{
Test33 be= new Test33(); be.go();
}
public void go(){
f=newJFrame("3CJFrame");
f.setLayout(new GridLayout(6,1,10,10));
f.setSize(350,250);
ISource=new JLabel("Source");ITarget=newJLabel("Target");
ISpacel= new JLabel(); ISpace2= new JLabel();
tfs= new JTextField(ad,15); tft=new JTextField(15);
JPanel panl=new JPanel(); JPanel pan3=new JPanel();
JPanel pan2= new JPanel();
pan3.setLayout(new FlowLayout(FlowLayout.CENTER,40,0));
pan1.add(lSource);
pan1.add(tfs);
pan2.add(ITarget);
pan2.add(tft);
bClear = new JButtn("Cler"); bCopy = new JButton("Copy");
bClose = new JButton("Close");
bClear.addActionListener(his); bCopy.addActionListener(his);
bClose.addActionListener(this);
pan3 .add(bClear); pan3 .add(bCopy); pan3.add(bClose);
f.add(ISpacel);
f.add(pan1);
f.add(pan2);
f.add(lSpace2);
f.add(pan3);
f.addWindowListener(this);
f.setVisible(true);
}

public void actionPerformed(ActionEvent e){
//请在答题卡(纸)上填写此处应编写的代码
}
public void windowClosing(WindowEvente){
System.exit(0);
}
}


参考答案: 查看答案 查看解析 下载APP畅快刷题

相关知识点试题

相关试卷