没有合适的资源?快使用搜索试试~ 我知道了~
JAVA第三次计分作业.pdf
需积分: 0 0 下载量 172 浏览量
2024-04-09
09:07:13
上传
评论
收藏 287KB PDF 举报
温馨提示
试读
14页
JAVA第三次计分作业.pdf
资源推荐
资源详情
资源评论
2024/4/2 03:00
CourseGrading
https://cg.sau.edu.cn/assignment/index.jsp?assignID=8682#An_ProgramFP
2/16
1. 【请复制本程序,作为java程序代码,进行编译,补充填写缺失代码部分,并实现题目要求功能,
从而获得空白填写所需的内容。】
【注意】填写语句时,请使用注释里指定的变量名,CG自动评判,未按要求编写,无成绩。
编写图形界面程序,在窗体中设置菜单栏,在菜单栏上添加“file”菜单,在文件菜单中添加"ne
w"和"quit"两个菜单项,其中"quit"菜单项单击后可以退出程序。
import java.awt.*;
import java.awt.event.ActionEvent;import java.aw
;//事件处理需要的包
import javax.swing.*;
public class EditorJFra extends
JFrame
implements
ActionListener
{
public EditorJFra (){
super
("图形界面");//设置标题栏
this.setLocation(300,240);
this.setSize(300,150);
this.
setLayout(new GridLayout(3, 1))
;//设置网格布局管理器
this.add(new Label("标签"));
this.add(new TextField("abc",20));
this.add(new Button("ok"));
JMenuBar menubar = new JMenuBar();
this.
setJMenuBar(menubar)
;//设置菜单栏
JMenu menu_file = new JMenu("file");
menubar.add(menu_file)
; //向菜单栏添加menu_file菜单
JMenuItem menuitem_new = new JMenuItem("
; //向菜menu_file菜单添加"new"菜单项
JMenuItem menuitem_exit = new JMenuItem("quit");
menu_file.add(menuitem_exit)
; //向菜menu_file菜单添加menuitem_exit菜单
项
menuitem_exit.
addActionListener(this)
; //给menuitem_exit菜单项添
加单击事件
this.
setVisible(true)
;//显示窗体
}
public void
actionPerformed(ActionEvent e)
{//单击事件处理方法,参数变量名e
System.exit(0);
}
public static void main(String arg[])
{
new EditorJFra();
}
}
已提交
2024/4/2 03:00
CourseGrading
https://cg.sau.edu.cn/assignment/index.jsp?assignID=8682#An_ProgramFP
3/16
2024/4/2 03:00
CourseGrading
https://cg.sau.edu.cn/assignment/index.jsp?assignID=8682#An_ProgramFP
4/16
2. 【请复制本程序,作为java程序代码,进行编译,补充填写缺失代码部分,并实现题目要求功能,
从而获得空白填写所需的内容。】
【注意】填写语句时,请使用注释里指定的变量名,CG自动评判,未按要求编写,无成绩。
自定义异常类,非法年龄类,并在person3类中使用此类,根据情况抛出异常,并进行处理。
class IllegalAgeException extends
Exception
//无效年龄异常
类
{
public IllegalAgeException(String s)
{
super(s);
}
public IllegalAgeException()
{
this("");
}
}
public class Person3
{
protected String name; //姓名
protected int age; //年龄
public Person3(String name,int age)
throws IllegalAgeException
//抛出异常
的方法,请准确写出抛出的异常类
{
this.set(name);
this.set(age);
}
public void set(String name)
{
if (name==null || name=="")
this.name = "姓名未知";
else
this.name = name;
}
public void set(int age)
throws IllegalAgeException
//抛出异常的方法,请准
确写出抛出的异常类
{
if (age>=0 && age<100)
已提交
剩余13页未读,继续阅读
资源评论
2301_78828247
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功