3.创建下面的GUI,颜色列表框为红色、绿色和蓝色(不必为各组件提供功能)。
4 。编程实现程序菜单功能,用户单击Press Me按钮,在小程序的状态栏上显示Button Clicked,假设字号为12,字型为常规。
5. 创建下面的GUI,要求在文本框中输入分数,单击“求和”按钮后在结果文本框中显示总分。
题6图
6.编写一个将华氏温度转换为摄氏温度的程序。应从键盘输入华氏温度,然后通过文本显示转换后的摄氏温度。使用下面的公式进行温度转换:
摄氏温度=5/9Χ(华氏温度-32)
7.编写一个程序,使用户能够使用鼠标在applet中绘制一个矩形。按住鼠标左键,确定矩形的左上角,然后拖动鼠标,在需要的位置(即矩形右下角)释放鼠标。另外,在状态栏中显示矩形面积。
编程第1题
import javax.swing.*; import java.awt.*; import java.awt.event.*; import javax.swing.event.*;
class SwingTest extends JFrame implements ActionListener{ private int count=0;
private JButton b1=new JButton(\英文\ private JButton b2=new JButton(\中文\ private JButton b3=new JButton(\标点\ private JTextArea mytext=new JTextArea(5,20);
public SwingTest() {
setTitle(\ addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0); } });
getContentPane().add(b1, BorderLayout.WEST); b1.addActionListener(this);
getContentPane().add(b2, BorderLayout.NORTH); b2.addActionListener(this);
getContentPane().add(b3, BorderLayout.SOUTH); b3.addActionListener(this);
getContentPane().add(mytext, BorderLayout.CENTER); }
public void actionPerformed(ActionEvent e){ Object ob=e.getSource(); if (ob==b1)
mytext.append(\
else if (ob==b2)
mytext.append(\你按了中文按钮\ else if (ob==b3) mytext.append(\ }
public static void main(String args[]) {
JFrame f=new SwingTest(); f.setSize(300,300); f.setVisible(true); } }
编程第2题
import java.awt.*;
public class Chp9_3_A extends Frame{ TextField t=new TextField();
String[] op={\Button[] btn=new Button[16]; Panel p=new Panel(); public Chp9_3_A(){
setLayout(new BorderLayout()); p.setLayout(new GridLayout(4,4)); for(int i=0;i add(t,BorderLayout.NORTH); add(p,BorderLayout.CENTER); setSize(400,300); } public static void main(String[] args){ new Chp9_3_A().setVisible(true); } } 编程第3题 import java.awt.*; public class Chp9_3_B extends Frame{ Choice ch; Checkbox bg,fg; Button btnOK,btnCancel; Panel p,p1,p2; public Chp9_3_B(){ p=new Panel(); p.setLayout(new GridLayout(2,1)); p1=new Panel(); p2=new Panel(); p1.setLayout(new FlowLayout()); p2.setLayout(new FlowLayout()); ch=new Choice(); ch.add(\红色\ch.add(\绿色\ ch.add(\蓝色\ bg=new Checkbox(\背景\fg=new Checkbox(\前景\p1.add(bg); p1.add(fg); btnOK=new Button(\确定\btnCancel=new Button(\取消\p2.add(btnOK); p2.add(btnCancel); p.add(p1); p.add(p2); add(ch,BorderLayout.NORTH); add(p,BorderLayout.CENTER); setSize(400,300); } public static void main(String[] args){ new Chp9_3_B().setVisible(true); } } 编程第四题: 参考程序如下: import java.awt.*; import java.awt.event.*; public class Chp9_3_F extends Frame{