java实验报告实验六Java图形用户界面

上传人:壹****1 文档编号:495292931 上传时间:2023-02-08 格式:DOC 页数:27 大小:537.02KB
返回 下载 相关 举报
java实验报告实验六Java图形用户界面_第1页
第1页 / 共27页
java实验报告实验六Java图形用户界面_第2页
第2页 / 共27页
java实验报告实验六Java图形用户界面_第3页
第3页 / 共27页
java实验报告实验六Java图形用户界面_第4页
第4页 / 共27页
java实验报告实验六Java图形用户界面_第5页
第5页 / 共27页
点击查看更多>>
资源描述

《java实验报告实验六Java图形用户界面》由会员分享,可在线阅读,更多相关《java实验报告实验六Java图形用户界面(27页珍藏版)》请在金锄头文库上搜索。

1、信 息 工 程 学 院实验报告的内容与格式按任课教师的要求书写。 Java程序设计 实习报告JAVA图形用户界面实验六Java图形用户界面1实验目的(1)掌握图形用户界面基本组件。(2)了解如何使用布局管理器对组件进行管理。(3)掌握Java事件处理机制。2实验内容实验题1 编写一个模拟计算器的程序,使用面板和网格布局,添加一个文本框,10个数字按钮(0-9),4个加减乘除按钮,一个等号按钮,一个清除按钮,要求将计算公式和结果显示在文本框中。运行结果:加法:主要代码:private void initComponents() jButton1 = new javax.swing.JButton

2、();jButton2 = new javax.swing.JButton();jButton3 = new javax.swing.JButton();jButton4 = new javax.swing.JButton();jButton5 = new javax.swing.JButton();jButton6 = new javax.swing.JButton();jButton7 = new javax.swing.JButton();jButton8 = new javax.swing.JButton();jButton9 = new javax.swing.JButton();j

3、Button10 = new javax.swing.JButton();jButton11 = new javax.swing.JButton();jButton12 = new javax.swing.JButton();jButton13 = new javax.swing.JButton();jButton14 = new javax.swing.JButton();jButton15 = new javax.swing.JButton();jTextField1 = new javax.swing.JTextField();setStub(null);jButton1.setText

4、(3);jButton1.addActionListener(new java.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent evt) jButton1ActionPerformed(evt););jButton2.setText(1);jButton2.addActionListener(new java.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent evt)

5、 jButton2ActionPerformed(evt););jButton3.setText(5);jButton3.addActionListener(new java.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent evt) jButton3ActionPerformed(evt););jButton4.setText(2);jButton4.addActionListener(new java.awt.event.ActionListener() public void

6、 actionPerformed(java.awt.event.ActionEvent evt) jButton4ActionPerformed(evt););jButton5.setText(6);jButton5.addActionListener(new java.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent evt) jButton5ActionPerformed(evt););jButton6.setText(8);jButton6.addActionListener

7、(new java.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent evt) jButton6ActionPerformed(evt););jButton7.setText(4);jButton7.addActionListener(new java.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent evt) jButton7ActionPerformed(evt);

8、);jButton8.setText(7);jButton8.addActionListener(new java.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent evt) jButton8ActionPerformed(evt););jButton9.setText(0);jButton9.addActionListener(new java.awt.event.ActionListener() public void actionPerformed(java.awt.even

9、t.ActionEvent evt) jButton9ActionPerformed(evt););jButton10.setText(9);jButton10.addActionListener(new java.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent evt) jButton10ActionPerformed(evt););jButton11.setText(u00f7);jButton11.addActionListener(new java.awt.event.A

10、ctionListener() public void actionPerformed(java.awt.event.ActionEvent evt) jButton11ActionPerformed(evt););jButton12.setText(u00d7);jButton12.addActionListener(new java.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent evt) jButton12ActionPerformed(evt););jButton13.s

11、etText(-);jButton13.addActionListener(new java.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent evt) jButton13ActionPerformed(evt););jButton14.setText(+);jButton14.addActionListener(new java.awt.event.ActionListener() public void actionPerformed(java.awt.event.Action

12、Event evt) jButton14ActionPerformed(evt););jButton15.setText(=);jButton15.addActionListener(new java.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent evt) jButton15ActionPerformed(evt););实验题2 编写一个程序,有一个窗口,该窗口为BorderLayout布局。窗口的中心添加一个Panel容器:pCenter,pCenter的布局是7行7列的Gr

13、idLayout布局,pCenter的中放置49个标签,用来显示日历。窗口北面添加一个Panel容器pNorth,其布局是FlowLayout布局,pNorth放置两个按钮:nextMonth和previousMonth按钮,单击nextMonth,可以显示当前月的下一个月的日历;单击previousMonth按钮,可以显示当前月的上一个月的日历。窗口的南面添加一个Panel容器pSouth,其布局是FlowLayout布局,pSouth中放置一个标签用来显示一些信息。运行结果如图所示。图3.8 运行结果图基本要求 编写完整程序。运行结果:主要代码:private JLabel buttonD

14、ay = new JLabel42;private JButton buttonWeek = new JButton7;private JLabel labelMonth = new JLabel();private JButton buttonLastMonth = new JButton();private JButton buttonNextMonth = new JButton();private JPanel pCenter=new JPanel();private JPanel pNorth=new JPanel();private JPanel pSouth=new JPanel();private JLabel time=new JLabel();public Calender() super(Calender); setBounds(250, 200, 600

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > PPT模板库 > 总结/计划/报告

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号