实验 8 JAVA GUI实训
合集下载
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
JButton button=;//实例化按钮,显示"加1"
JLabel label=newJLabel("现在的计数是:");
JLabel showLabel =new;//显示count的值
//在窗体的北部添加,label
//在窗体的中部添加,showLabel
//在窗体的南部添加按钮button
实验8javagui课程名称java程序设计班级座号姓名实验名称实验8javagui实训实验时间实验目的通过讲解和上机练习要求学生掌握图形用户界面的设计理解并掌握事件处理
实验8 JAVA GUI
课程名称
Java程序设计
班级
座号
姓名
实验名称
实验时间
实验目的
通过讲解和上机练习,要求学生掌握图形用户界面的设计,理解并掌握事件处理。
JButtonbutton;
JLabelshowLabel;
publicSY8_2(String title)throwsHeadlessException {
super(title);
button=newJButton("加1");
JLabel label =newJLabel("现在的计数是:");
privateintcount= 0;
JButtonbutton;
JLabelshowLabel;
publicSY8_2(String title)throwsHeadlessException {
super(title);
button=newJButton("加1");
JLabel label =newJLabel("现在的计数是:");
import java.awt.event.*;lass Bubble extends JFrame {
private int x, y;
public static void main(String[] args) {
new Bubble();
}
public Bubble() {
f.setSize(200,100);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}
2.更改以上的程序代码完成上述要求。
publicclassSY8_2extendsJFrame {
privateintcount= 0;
setSize(200, 100);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
publicstaticvoidmain(String[] args) {
SY8_2 f =newSY8_2("GUI实训");
f.setVisible(true);
}
showLabel=newJLabel(" "+count);
add(BorderLayout.NORTH, label);
add(BorderLayout.CENTER,showLabel);
add(BorderLayout.SOUTH,button);
button.addActionListener(this);
x = evt.getX();//记录鼠标的位置
y = evt.getY();
repaint();
}
}
}
实验过程记录
1
2
3
实验结果分析与总结
程序源代码
指导老师评阅意见
填写内容时,可把表格扩大。
super("泡泡");
this.setSize(200, 200);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
//事件委托
}
public void paint(Graphics g) {
super.paint(g);//清除屏幕内容
实验环境
实验内容安排
1.使用Jframe和Jbutton完成以下界面的制作,补充代码。
publicclassSY8_1 {
privatestaticintcount=0;
publicstaticvoidmain(String[] args) {
JFrame f=newJFrame("GUI实训");
showLabel=newJLabel(" "+count);
//在窗体的北部添加,label
//在窗体的中部添加,showLabel
//在窗体的南部添加按钮button
setSize(200, 100);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
publicstaticvoidmain(String[] args) {
SY8_2 f =newSY8_2("GUI实训");
f.setVisible(true);
}
}
1.使用实验SY8_2的代码,给按钮添加事件,完成加1操作。
publicclassSY8_2extendsJFrame{
//实现ActionListener接口
g.setColor(Color.red);//设为红色
if (x > 0 && y > 0){
//在记录下来的鼠标的位置画直径为30的圆
}
}
private class Mouser extends MouseAdapter {
public void mouseClicked(MouseEvent evt) {
@Override
publicvoidactionPerformed(ActionEvent e) {
//count加1
//设置Label显示count的值
}
}
1.相应鼠标事件,使用Graphics类在鼠标点击位置画一个圆
package chapt07.drawing;
import java.awt.*;
JLabel label=newJLabel("现在的计数是:");
JLabel showLabel =new;//显示count的值
//在窗体的北部添加,label
//在窗体的中部添加,showLabel
//在窗体的南部添加按钮button
实验8javagui课程名称java程序设计班级座号姓名实验名称实验8javagui实训实验时间实验目的通过讲解和上机练习要求学生掌握图形用户界面的设计理解并掌握事件处理
实验8 JAVA GUI
课程名称
Java程序设计
班级
座号
姓名
实验名称
实验时间
实验目的
通过讲解和上机练习,要求学生掌握图形用户界面的设计,理解并掌握事件处理。
JButtonbutton;
JLabelshowLabel;
publicSY8_2(String title)throwsHeadlessException {
super(title);
button=newJButton("加1");
JLabel label =newJLabel("现在的计数是:");
privateintcount= 0;
JButtonbutton;
JLabelshowLabel;
publicSY8_2(String title)throwsHeadlessException {
super(title);
button=newJButton("加1");
JLabel label =newJLabel("现在的计数是:");
import java.awt.event.*;lass Bubble extends JFrame {
private int x, y;
public static void main(String[] args) {
new Bubble();
}
public Bubble() {
f.setSize(200,100);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}
2.更改以上的程序代码完成上述要求。
publicclassSY8_2extendsJFrame {
privateintcount= 0;
setSize(200, 100);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
publicstaticvoidmain(String[] args) {
SY8_2 f =newSY8_2("GUI实训");
f.setVisible(true);
}
showLabel=newJLabel(" "+count);
add(BorderLayout.NORTH, label);
add(BorderLayout.CENTER,showLabel);
add(BorderLayout.SOUTH,button);
button.addActionListener(this);
x = evt.getX();//记录鼠标的位置
y = evt.getY();
repaint();
}
}
}
实验过程记录
1
2
3
实验结果分析与总结
程序源代码
指导老师评阅意见
填写内容时,可把表格扩大。
super("泡泡");
this.setSize(200, 200);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
//事件委托
}
public void paint(Graphics g) {
super.paint(g);//清除屏幕内容
实验环境
实验内容安排
1.使用Jframe和Jbutton完成以下界面的制作,补充代码。
publicclassSY8_1 {
privatestaticintcount=0;
publicstaticvoidmain(String[] args) {
JFrame f=newJFrame("GUI实训");
showLabel=newJLabel(" "+count);
//在窗体的北部添加,label
//在窗体的中部添加,showLabel
//在窗体的南部添加按钮button
setSize(200, 100);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
publicstaticvoidmain(String[] args) {
SY8_2 f =newSY8_2("GUI实训");
f.setVisible(true);
}
}
1.使用实验SY8_2的代码,给按钮添加事件,完成加1操作。
publicclassSY8_2extendsJFrame{
//实现ActionListener接口
g.setColor(Color.red);//设为红色
if (x > 0 && y > 0){
//在记录下来的鼠标的位置画直径为30的圆
}
}
private class Mouser extends MouseAdapter {
public void mouseClicked(MouseEvent evt) {
@Override
publicvoidactionPerformed(ActionEvent e) {
//count加1
//设置Label显示count的值
}
}
1.相应鼠标事件,使用Graphics类在鼠标点击位置画一个圆
package chapt07.drawing;
import java.awt.*;