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

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

..信息工程学院1Java程序设计实习报告JAVA图形用户界面实验六Java图形用户界面1.实验目的(1)掌握图形用户界面基本组件。(2)了解如何使用布局管理器对组件进行管理。(3)掌握Java事件处理机制。2.实验内容实验题1编写一个模拟计算器的程序,使用面板和网格布局,添加一个文本框,10个数字按钮(0-9),4个加减乘除按钮,一个等号按钮,一个清除按钮,要求将计算公式和结果显示在文本框中。运行结果:实验报告的内容与格式按任课教师的要求书写。..加法:主要代码:privatevoidinitComponents(){jButton1=newjavax.swing.JButton();jButton2=newjavax.swing.JButton();jButton3=newjavax.swing.JButton();jButton4=newjavax.swing.JButton();jButton5=newjavax.swing.JButton();jButton6=newjavax.swing.JButton();jButton7=newjavax.swing.JButton();jButton8=newjavax.swing.JButton();jButton9=newjavax.swing.JButton();jButton10=newjavax.swing.JButton();jButton11=newjavax.swing.JButton();jButton12=newjavax.swing.JButton();jButton13=newjavax.swing.JButton();jButton14=newjavax.swing.JButton();jButton15=newjavax.swing.JButton();jTextField1=newjavax.swing.JTextField();..setStub(null);jButton1.setText(3);jButton1.addActionListener(newjava.awt.event.ActionListener(){publicvoidactionPerformed(java.awt.event.ActionEventevt){jButton1ActionPerformed(evt);}});jButton2.setText(1);jButton2.addActionListener(newjava.awt.event.ActionListener(){publicvoidactionPerformed(java.awt.event.ActionEventevt){jButton2ActionPerformed(evt);}});jButton3.setText(5);jButton3.addActionListener(newjava.awt.event.ActionListener(){publicvoidactionPerformed(java.awt.event.ActionEventevt){jButton3ActionPerformed(evt);}});jButton4.setText(2);jButton4.addActionListener(newjava.awt.event.ActionListener(){publicvoidactionPerformed(java.awt.event.ActionEventevt){jButton4ActionPerformed(evt);}});..jButton5.setText(6);jButton5.addActionListener(newjava.awt.event.ActionListener(){publicvoidactionPerformed(java.awt.event.ActionEventevt){jButton5ActionPerformed(evt);}});jButton6.setText(8);jButton6.addActionListener(newjava.awt.event.ActionListener(){publicvoidactionPerformed(java.awt.event.ActionEventevt){jButton6ActionPerformed(evt);}});jButton7.setText(4);jButton7.addActionListener(newjava.awt.event.ActionListener(){publicvoidactionPerformed(java.awt.event.ActionEventevt){jButton7ActionPerformed(evt);}});jButton8.setText(7);jButton8.addActionListener(newjava.awt.event.ActionListener(){publicvoidactionPerformed(java.awt.event.ActionEventevt){jButton8ActionPerformed(evt);}});..jButton9.setText(0);jButton9.addActionListener(newjava.awt.event.ActionListener(){publicvoidactionPerformed(java.awt.event.ActionEventevt){jButton9ActionPerformed(evt);}});jButton10.setText(9);jButton10.addActionListener(newjava.awt.event.ActionListener(){publicvoidactionPerformed(java.awt.event.ActionEventevt){jButton10ActionPerformed(evt);}});jButton11.setText(\u00f7);jButton11.addActionListener(newjava.awt.event.ActionListener(){publicvoidactionPerformed(java.awt.event.ActionEventevt){jButton11ActionPerformed(evt);}});jButton12.setText(\u00d7);jButton12.addActionListener(newjava.awt.event.ActionListener(){publicvoidactionPerformed(java.awt.event.ActionEventevt){jButton12ActionPerformed(evt);}});jButton13.setText(-);..jButton13.addActionListener(newjava.awt.event.ActionListener(){publicvoidactionPerformed(java.awt.event.ActionEventevt){jButton13ActionPerformed(evt);}});jButton14.setText(+);jButton14.addActionListener(newjava.awt.event.ActionListener(){publicvoidactionPerformed(java.awt.event.ActionEventevt){jButton14ActionPerformed(evt);}});jButton15.setText(=);jButton15.addActionListener(newjava.awt.event.ActionListener(){publicvoidactionPerformed(java.awt.event.ActionEventevt){jButton15ActionPerformed(evt);}});实验题2编写一个程序,有一个窗口,该窗口为BorderLayout布局。窗口的中心添加一个Panel容器:pCenter,pCenter的布局是7行7列的GridLayout布局,pCenter的中放置49个标签,用来显示日历。窗口北面添加一个Panel容器pNorth,其布局是FlowLayout布局,pNorth放置两个按钮:nextMonth和previousMonth按钮,单击nextMonth,可以显示当前月的下一个月的日历;单击previousMonth按钮,可以显示当前月的上一个月的日历。窗口的南面添加一个Panel容器pSouth,其布局是FlowLayout布局,pSouth中放置一个标签用来显示一些信息。运行结果如图所示。..图3.8运行结果图[基本要求]编写完整程序。运行结果:主要代码:privateJLabel[]buttonDay=newJLabel[42];privateJButton[]buttonWeek=newJButton[7];privateJLabellabelMonth=newJLabel();privateJButtonbuttonLastMonth=newJButton();privateJButtonbuttonNextMonth=newJButton();privateJPanelpCenter=newJPanel();privateJPanelpNorth=newJPanel();privateJPanelpSouth=newJPanel();privateJLabeltime=newJLabel();..publicCalender(){super(Calender);setBounds(250,200,600,500);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);buttonLastMonth.setText(上月);buttonLastMonth.addActionListener(this);pNorth.add(buttonLastMonth);buttonNextMonth.setText(下月);buttonNextMonth.addActionListener(this);pNorth.add(buttonNextMonth);getContentPane().add(pNorth,BorderLayout.NORTH);getContentPane().add(pCenter,BorderLayout.CENTER);pCenter.setLayout(newGridLayout(7,7));for(inti=0;i7;i++){buttonWeek[i]=newJButton();buttonWeek[i].setText(stringWeekCn[i]);pCenter.add(buttonWeek[i]);}for(inti=0;i42;i++){buttonDay[i]=newJLabel();buttonDay[i].setText();pCenter.add(buttonDay[i]);}实验题3实现如图3.9所示的布局方式功能:前两个文本框输入整型数据。第三个文本框存放前两个文本框数据之和。要求如下:第一个文本框的数据是[100,200],如果超出该范围弹出对话框提示用户。弹出提示对话框的时刻是光标离开第一个文本框时。..图3.9求和运行结果:检验输入数据范围:主要代码:classMouseHanderextendsMouseAdapter{publicMouseHander(JTextFieldc){curr

1 / 28
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功