北邮《Java技术》期末复习题(含答案)(3)

2018-12-21 12:44

} 6.

// 实现 ActionListener 中的方法

public void actionPerformed(ActionEvent e) { String s; if (e.getActionCommand() == \ System.exit(0); } else if (e.getActionCommand() == \ try { while ((s = in.readLine()) != null) text.append(s + '\\n'); } catch (IOException exp) { } } }

编写一个字符方式的Application程序。在程序中定义一个表示学生的类Student。Student类的属性为学号、姓名和成绩;方法为增加记录setRecord和得到记录getRecord。setRecord给出学号、姓名和成绩的赋值,getRecord通过学号得到学生的成绩。在程序的主类中创建一个Student类的对象objStu,调用setRecord方法为其属性赋值,然后输出该学生的成绩。请写出源程序代码。 class Student { private int ID; private String name; private float score; public void setRecord(int ID,String name,float score){ this.ID = ID; this.name = name; this.score = score; } public float getRecord(int ID){ if(ID == this.ID) return this.score; else return -1; } }

public class StudentApp { public static void main(String[] args) { Student objStu = new Student(); objStu.setRecord(0, \ float Sco = objStu.getRecord(0); System.out.print(Sco);

11

}

}

7. 按照下面要求编写程序:编写一个 JFrame 窗口程

序,要求窗口的内容面板上有一个按钮,点击按钮可以弹出一个对话框。请写出源程序代码。 import javax.swing.*; import java.awt.*;

import java.awt.event.*;

public class FrameApp implements ActionListener { public static void main(String[] args) { JFrame jframe = new JFrame(\ jframe.setSize(400,100); jframe.getContentPane().setLayout(new FlowLayout()); JButton jbtn1 = new JButton(\按钮\ jbtn1.addActionListener(new FrameApp()); jframe.getContentPane().add(jbtn1); jframe.setVisible(true); } public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(null, \ } }

8. 按照下面要求编写程序:编写一个 JFrame 窗口程

序,要求窗口标题栏的文字是“这是一个JFrame窗口程序”。请写出源程序代码。 import javax.swing.*; import java.awt.event.*;

class MyJFrame extends JFrame{ public MyJFrame(String name, int w, int h) { super(); setTitle(name); setSize(w, h); setLocation(100, 100); } }

public class MyJFrameApp { public static void main(String[] args) { String str1 = \ MyJFrame mw = new MyJFrame(str1, 400, 300); mw.setVisible(true); } }


北邮《Java技术》期末复习题(含答案)(3).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:TL-WR700N设置方法

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: