更多优质自考资料尽在百度贴吧自考乐园俱乐部
(http://tieba.http://www.wodefanwen.com//club/5346389)欢迎?加入...欢迎?交流...止不住的惊喜等着你.........
过文本显示转换后的摄氏温度。使用下面的公式进行温度转换:
摄氏温度=5/9Χ(华氏温度-32)
8.编写一个程序,使用户能够使用鼠标在applet中绘制一个矩形。按住鼠标左键,确定矩形的左上角,然后拖动鼠标,在需要的位置(即矩形右下角)释放鼠标。另外,在状态栏中显示矩形面积。
参考答案 1.false 2.true
3. CheckboxGroup 4.D 5. C
6. 参考程序如下:
import javawt.*;来源:考试大 import javawt.event.*;
public class Chp9_3_C extends Frame implements ActionListener{ TextField textField1,textField2,textField3; Button button1=new Button(\求和\ Panel panel1,panel2; public Chp9_3_C(){
textField1=new TextField(); textField2=new TextField(); textField3=new TextField(); panel1=new Panel(); panel2=new Panel();
panel1.setLayout(new GridLayout(3,2)); panel2.setLayout(new FlowLayout()); panel1.add(new Label(\数学: \ panel1.add(textField1);
panel1.add(new Label(\英语: \ panel1.add(textField2);
panel1.add(new Label(\总分: \ panel1.add(textField3); panel2.add(button1);
add(panel1,BorderLayout.CENTER); add(panel2,BorderLayout.SOUTH); button1.addActionListener(this); setSize(300,200); setVisible(true); }
public static void main(String[] args){ new Chp9_3_C(); }
public void actionPerformed(ActionEvent e){ int n1,n2,sum;
更多优质自考资料尽在百度贴吧自考乐园俱乐部
(http://tieba.http://www.wodefanwen.com//club/5346389)欢迎?加入...欢迎?交流...止不住的惊喜等着你.........
n1=Integer.parseInt(textField1.getText()); n2=Integer.parseInt(textField2.getText()); sum=n1+n2;
textField3.setText(\} }
6.参考程序如下: import javawt.*;
import javawt.event.*;
public class Chp9_3_D extends Frame{ TextField textField1,textField2; Button button1; public Chp9_3_D(){
textField1=new TextField(30); textField2=new TextField(30); button1=new Button(\转换\setLayout(new FlowLayout()); add(new Label(\华氏温度:\add(textField1);
add(new Label(\摄氏温度:\add(textField2);
textField2.setEditable(false); add(button1); setSize(400,300); pack();
button1.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ button1_actionPerformed(e); } });
addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ System.exit(0); } }); }
public static void main(String[] args){ new Chp9_3_D().setVisible(true); }
private void button1_actionPerformed(ActionEvent e){ double d=Double.parseDouble(textField1.getText()); double h=5.0/9.0*(d-32); textField2.setText(\}
更多优质自考资料尽在百度贴吧自考乐园俱乐部
(http://tieba.http://www.wodefanwen.com//club/5346389)欢迎?加入...欢迎?交流...止不住的惊喜等着你.........
}
7.参考程序如下: import javapplet.Applet; import javawt.*;
import javawt.event.*; public class Chp9_3_E MouseListener,MouseMotionListener{
int x1,y1,x2,y2; public void init(){
addMouseListener(this);
addMouseMotionListener(this); }
public void paint(Graphics g){ g.drawRect(x1,y1,x2,y2);
int area=Math.abs(x2-x1)*Math.abs(y2-y1); showStatus(\矩形面积: \ }
//implementation of MouseListener
public void mousePressed(MouseEvent e){ x1=e.getX(); y1=e.getY(); }
public void mouseClicked(MouseEvent e){} public void mouseEntered(MouseEvent e){} public void mouseExited(MouseEvent e){} public void mouseReleased(MouseEvent e){} //implementation of MouseMotionEvent public void mouseDragged(MouseEvent e){ x2=e.getX(); y2=e.getY(); repaint(); }
public void mouseMoved(MouseEvent e){} }
extends Applet implements