35.阅读下列程序,请写出该程序的功能。
import java.applet.*:import java.awt.event.*;import javax.swing.*
public class Class 1 extends Applet implements KeyListener{
JButton button=new JButton(″开始″);
JTextArea text=new JTextArea(5,20);
public void init() {
button.addKeyListener(this); add(button);add(text);
}
public void keyPressed(KeyEvent e){
int t=e.getKeyCode();
if(t>=KeyEvent.VK_A&& t<=KeyEvent.VK_Z) {
text.append(″ ″+(char)t);
}
}
public void keyTyped(KeyEvent e){}
public void keyReleased(KeyEvent e){}
}
36.阅读下列程序,请写出该程序的功能。
import java.applet.*; import java.awt.*;
public class Test36 extends java.applet.Applet implements Runnable{
Thread myThread = null;
double seta=0.0;
public void start() {
setSize(500,400);
if(myThread=null){ myThread=new Thread(this); myThread.start();}
}
public void run() {
while(myThread!=null) {
try {myThread.sleep(40);
} catch(InterruptedException e){}
seta+=3.0; if(seta>=360)seta=0; repaint();
}
}
public void paint(Graphics g) {
final double pi=3.14159; final double r = 100.0;
int x0=250+(int)(r*Math.cos(3.1415926/180.0*seta));
int y0=200+(int)(r*Math.sin(3.1415926/180.0*seta));
g.setColor(Color.red); g.drawOval(x0,y0,10,10);
}
}
六、程序设计题(本大题共2小题,每小题6分,共1 2分)
37.请编写方法void strReverse(String str),该方法的功能是输出一个新字符串,新字符串字符排列顺序与原字符串str的字符排列顺序相反。例如,strReverse(″ABCD″) 所输出的结果是″DCBA″。请使用字符串与字节数组的相互转换方法进行设计。
38.请设计实现如下用于输入学号和姓名的对话框界面,其中空白格是文本框,用于输入相应的内容。
这里给出的是程序的一部分,你要编写的是类InputNoNameDialog的构造方法InputNoNameDialog(JFrame f,String s,JTextField t)。其中参数f是对话框的依赖窗口,s是对话框标题,t是依赖窗口中显示对话框输入内容的文本框。
以下是类InputNoNameDialog的程序框架。
class InputNoNameDialog extends JDialog implements ActionListener{
JLabel title;JTextField textl,text2,mainText;JButton done;
InputNoNameDialog(JFrame f String s,JTextField t) {
super(f,s,true); mainText = t;Container con = getContentPane();
title=new JLabel(s); textl=new JTextField(10);
text2=new JTextField(10); con.setLayout(new GridLayout(3,2));
con.setSize(200,100); setModal(false);
//请在以下位置续写其余代码
}
public void actionPerformed(ActionEvent e) {
//输入结束按确定按钮后,将对话框中输入的学号和姓名在它依赖窗口的文本框中显示。
mainText.setText(″学号:″+textl.getText()+″ 姓名:″+text2.getText());
setVisible(false);dispose();
}
}
联系客服