java基础实验报告册

更新时间:2023-06-04 11:38:01 阅读量: 实用文档 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

学 生 实 验 报 告

课程名称:

学生学号:

所属院部:

(理工类)

Java程序设计试验 专业班级:

学生姓名:

指导教师:

20 14 ——20 15 学年 第 一 学期

金陵科技学院教务处制

实验报告书写要求

实验报告原则上要求学生手写,要求书写工整。若因课程特点需打印的,要遵照以下字体、字号、间距等的具体要求。纸张一律采用A4的纸张。

实验报告书写说明

实验报告中一至四项内容为必填项,包括实验目的和要求;实验仪器和设备;实验内容与过程;实验结果与分析。各院部可根据学科特点和实验具体要求增加项目。

填写注意事项

(1)细致观察,及时、准确、如实记录。 (2)准确说明,层次清晰。

(3)尽量采用专用术语来说明事物。

(4)外文、符号、公式要准确,应使用统一规定的名词和符号。 (5)应独立完成实验报告的书写,严禁抄袭、复印,一经发现,以零分论处。

实验报告批改说明

实验报告的批改要及时、认真、仔细,一律用红色笔批改。实验报告的批改成绩采用百分制,具体评分标准由各院部自行制定。

实验报告装订要求

实验批改完毕后,任课老师将每门课程的每个实验项目的实验报告以自然班为单位、按学号升序排列,装订成册,并附上一份该门课程的实验大纲。

实验项目名称: Java编程基础 实验学时: 同组学生姓名: 实验地点: 实验日期: 实验成绩: 批改教师: 批改时间:

《Java程序设计实验》指导书

实验1 Java编程基础

一、实验目的和要求

(1) 熟练掌握JDK编写调试Java应用程序及Java小程序的方法。 (2) 熟练掌握Java应用程序及小程序的结构。

(3) 了解Java语言的特点,基本语句、运算符及表达式的使用方法。 (4) 熟练掌握常见数据类型的使用。

(5) 熟练掌握if-else、switch、while、do-while、for、continue、break、return

语句的使用方法。

二、实验要求

(1)调试程序要记录调试过程中出现的问题及解决办法;

(2)编写程序要规范、正确,上机调试过程和结果要有记录,不断积累编程及调试经验;

(3)做完实验后给出本实验的实验报告。

三、实验设备、环境

奔腾以上计算机,Windows 2000 、J2SDK、IE浏览器

四、实验步骤及内容

(1)输入并用JDK编译运行下面的程序 class HelloWorld{ public static void main(String[] args){ System.out.println(“Hello,world”); } }

(2)2-18

import java.util.Scanner; public class Text5 { int x=43; int[] array;

Text5(){

Scanner reader=new Scanner(System.in); x=reader.nextInt();

array=new int[x]; //耕根据输入的数字初始化数组大小,保存素数 }

public void output(){ int temp=0; int arr=0;

int n=0;

System.out.println("请出入整数"); if(x<=2){ if(x==2)

System.out.println("2"); else

System.out.println("Error"); }

for(int m=2;m<=x;m++) { //以下是求素数 temp=(int)Math.sqrt(m); for(n=2;n<=temp;n++ ){ if(m%n==0) break; }

if(n>temp) {array[arr]=m;arr++;} //保存素数到数组 } }

public void PrintArray() {

for(int i=0;i<array.length;i++) {

if(array[i]>1)

System.out.print(" "+array[i]+" "); } }

public static void main(String[] args){ Text5 num=new Text5(); num.output(); num.PrintArray(); } }

(3)2-19

public class yanghuisanjiao{

public static void main(String[] args){ int[][] a=new int[10][10]; for(int i=0;i<10;i++) for(int j=0;j<10;j++){ if (j<i){ a[i][j]=1; if(j==0){ a[i][j]=1; } else{

a[i][j]=a[i-1][j-1]+a[i-1][j]; } } else{ a[i][j]=1; } } for(int i=0;i<10;i++) { for(int k=1;k<=10-i;k++) System.out.printf(" "); for(int j=0;j<=i;j++){ System.out.printf("%3d ",a[i][j]); } System.out.printf("\n"); } } } (4) 2-28

import java.util.Scanner; public class huiwen { public static void main(String[] args){ int i,j,n=0; System.out.println("请输入一个字符串"); Scanner in =new Scanner(System.in); String str=in.next(); for(i=0,j=str.length()-1;i<str.length()-1||j>0;i++,j--) { if(str.charAt(i)!=str.charAt(j)) { n=-1;break; } } if(n==0) System.out.println("是回文字符串"); else System.out.println("不是回文字符串"); } }

(5)2-32

public class shishuzifuchuan{ public static double parseDouble(String s){ int i=0, sign=s.charAt(0)=='-' ? -1 : 1; if (s.charAt(0)=='+' || s.charAt(0)=='-') i++; double value=0, power=0.1; while (i<s.length() && s.charAt(i)>='0' && s.charAt(i)<='9') value = value*10+s.charAt(i++)-'0'; if (i<s.length() && s.charAt(i)=='.'){ i++; while (i<s.length() && s.charAt(i)>='0' && s.charAt(i)<='9'){ value += (s.charAt(i)-'0')*power;

i++; power*=0.1; } } value *=sign; if (i<s.length() && (s.charAt(i)=='E' || s.charAt(i)=='e')){ i++; power = (s.charAt(i)=='-') ? 0.1 :10; if (s.charAt(i)=='+' || s.charAt(i)=='-') i++; int exp=0; while (i<s.length() && s.charAt(i)>='0' && s.charAt(i)<='9') exp = exp*10+s.charAt(i++)-'0'; for (int j=0; j<exp; j++) value*=power; } return value; } public static double toDouble(String s){ int j=s.indexOf('.'), k=s.indexOf('E'); if (k==-1) k=s.indexOf('e'); if (j==-1 && k==-1) return MyInteger.parseInt(s); int i=0, sign = s.charAt(0)=='-' ? -1 : 1; if (s.charAt(0)=='+' || s.charAt(0)=='-') i++; double value=0, power=0.1; if (j!=-1){ value=MyInteger.parseInt(s.substring(i,j)); j++; while (j<s.length() && s.charAt(j)>='0' && s.charAt(j)<='9'){ value += (s.charAt(j)-'0')*power; j++; power*=0.1; } } value *=sign; if (k!=-1){ if (j==-1) value=MyInteger.parseInt(s.substring(0,k)); k++; power = (s.charAt(k)=='-') ? 0.1 :10; if (s.charAt(k)=='+' || s.charAt(k)=='-') k++; int exp=MyInteger.parseInt(s.substring(k)); for (j=0; j<exp; j++) value*=power; } return value; } }

五、实验结果与分析

(1)运行结果:Hello,world

(2)运行结果:Please input a number:15

1 3 5 7 11 13

(3)运行结果: 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 1 6 15 20 15 6 1 1 7 21 35 35 21 7 1 1 8 28 56 70 56 28 8 1 1 9 36 84 126 126 84 36 9 1 (4)

运行结果:请输入一个字符串 abcddcba 是回文字符串

六、讨论、思考题

(1) 比较Java语言与C的程序结构

Java语言是基于C++语言发展而来,而c++语言又是从C语言发展而来。因此java语 言与C语言程序在变量定义、关键字的使用、方法,函数,定义、基本数据类型的使用、 条件语句、循环语句的使用有着千丝万缕的关系,相似又不同。Java的结构无关性、真正的面向对象和与Internet的协同工作等特性比上述任何一种语言更显得完善。Java的许多术语来自于C ,其语法也来自于C 。Java比C/C 易学、易用,且有强大的内建功能,同时,Java的代码可以重用。Java的主要缺点是解释执行,所以,C 的性能仍是较为突出的。然而,由于C即时编译器的开发,这一性能的沟壑也随之填平了。 这里先介绍几个不同 1:指针包含变量的地址,指针在 C 编程过程中可能引起许多错误,容易造成内存崩溃。Java取消了指针,但仍可以遍历所有的对象和数组。 2:Java没有函数,但是Java的类和方法能够实现C/C 用函数实现的任何任务。C语言编程人员希望在标准库中找到的函数,Java用各种类的静态方法来实现。 3:在C 语言中有三种复杂的数据类型:联合、结构和类;而在Java中只采用了类,其中在C中用联合和结构实现的工作,Java都用类来实现。 4Java语言不允许数据类型的自动强制转换。

(2) Java语言中的数组与C语言中的数组相比有什么不同,它的优点是什么? Java的数组是引用数据类型,一个数组变量采用引用方式保存多个数组元素,数组元素的数据类型既可以是基本数据类型,也可以是引用数据类型,对数组元素所能进行的操作取决于数组元素所属的数据类型。Java的数组元素都是动态数组,再在声明数组变量之后,使用new运算符申请数组存储空间。 Java不支持c/c++语言中的指针类型,所以对数组的操作只能使用下标,不能使用指针。引用数据类型与基本数据类型变量的不同点在于,存储单元的分配方式不同,两个变量之间的复制方式也不同。基本数据类型的传值赋值,获得存储单元的方式是静态的数组变量引用赋值,获得存储单元的方式都是动态的,必须使用new运算符。引用变量保存地址、长度、引用计数等特性。

(3) 比较Java各种流程控制语句的特点,它们的适用场合

,语句按书写次序依次顺序执行。

,决定是否执行该选择语句中包含的子

句。选择语句有两种,if语句和switch语句。当有两种选择并且需要根据条件选择是否执行时,通常使用if语句,当有两种以上选择并且有表达式的值决定是否执行时通

常使用switch语句。

java提供了三种循环语句while、do-while、for实现循环结构。共同特

点是根据循环条件来判断是否执行循环体,实际应用中应该根据具体问题的要求选择合适的循环语句,有些问题,三种都适用。While语句的特点是“先判断后执行”,当条件满足时执行循环体,do-while语句特点是“先执行后判断”,for语句将循环控制变量初值。循环条件和变量的变化规律都以表达式形式写在循环体之前。 java语言提供三种三种无条件转移语句,return、break和continue。 Returnbreak和continue语句用于控制流程转移。在switch语句的某个case子句中,或在while、repeat、for语句的循环体中,如果遇到break语句,则立即退出当前switch语句或循环语句。在while、repeat、for语句的循环体中,如果遇到continue语句,则本次循环结束,回到循环条件,继续判断是否执行下一次循环。

实验项目名称: 类与对象 实验学时: 同组学生姓名: 实验地点: 实验日期: 实验成绩: 批改教师: 批改时间:

实验2 类与对象

一、实验目的

(1) 熟练掌握Java语言类定义的基本语法

(2) 熟练掌握类数据成员的访问控制,对象建立的方法 (3) 熟练掌握类构造函数的定义,类方法的访问控制重载 (4) 掌握静态成员的特点

(5) 了解Java语言的垃圾回收机制。

(6) 熟练掌握类继承的基本、语法包和接口的使用,掌握protected成员的特点,

了解抽象方法和抽象类。

二、实验要求

(1)调试程序要记录调试过程中出现的问题及解决办法;

(2)编写程序要规范、正确,上机调试过程和结果要有记录,不断积累编程及调试经验;

(3)做完实验后给出本实验的实验报告。

三、实验设备、环境

奔腾以上计算机,Windows 2000 、J2SDK、IE浏览器

四、实验步骤及内容

(1) 3-32 完善例3.2的日期类MyDate。

class MyDate{ private int year, month, day; private static int thisYear; static{

thisYear=2009; }

public MyDate(int year,int month,int day){ this.set(year,month,day); }

public MyDate(){ this(1970,1,1); }

public MyDate(MyDate d){ this.set(d); }

public void set(int y,int m,int d){ this.year=y; this.month=((m>=1)&(m<=12))?m:1; this.day=((d>=1)&(d<=31))?d:1; }

public void set(MyDate d){ set(d.year,d.month,d.day); }

public int getYear(){ return this.year; }

public int getMonth(){

return this.month; }

public int getDay(){ return this.day; }

public String toString(){ return this.year+"年"+this.month+"月"+this.day+"日"; }

public static int getThisYear(){ return thisYear; }

public static boolean isLeapYear(int year){ return year%400==0||year%100!=0&&year%4==0; }

public boolean isLeapYear(){ return isLeapYear(this.year); }

public boolean equals(MyDate d){ return

this==d||d!=null&&this.year==d.year&&this.month==d.month&&this.day==d.day; }

public static int daysOfMonth(int year,int month){ switch(month){ case 1:case 3:case 5:case 7:case 8: case 10:case 12:case 31:return 31; case 4:case 6: case 9:case 11:return 30; case 2:return isLeapYear(year)?29:28; default:return 0; } }

public int daysOfMonth(){ return daysOfMonth(this.year,this.month); }

public void tomorrow(){ this.day++; if(day>this.daysOfMonth()){ day=1; month++; if(month>12){ month=1; year++; } } }

public MyDate yestoday(){ MyDate yes=new MyDate(this); yes.day--; if(yes.day==0){ yes.month--; if(yes.month==0){ yes.month=12; yes.year--; } yes.day=daysOfMonth(yes.year,yes.month); } return yes; }

public int getWeek(MyDate d) { int c,y,m,n; c=d.year/100; y=d.year%100; m=d.month; n=d.day; return (c/4-2*c+y+y/4+26*(m+1)/10+n-1)%7; }

public String WeekString(MyDate d) { String[] a=new String[6]; a[0]="星期日";a[1]="星期一";a[2]="星期二";a[3]="星期三";a[4]="星期四";a[5]="星期五";a[6]="星期六"; return a[getWeek(d)]; } }

class MyDate_ex{

public static void main(String args[]){

System.out.println("今年是

"+MyDate.getThisYear()+","+MyDate.isLeapYear(MyDate.getThisYear())); MyDate d1=new MyDate(2008,8,8); MyDate d2=new MyDate(d1);

System.out.println(d2+",

"+d2.isLeapYear());d2.WeekString(d2);

System.out.print(d2+"的昨天是"+d2.yestoday()+"\n"+d2+"的明天是");

d2.tomorrow();

System.out.println(d2); } }

(2) 3-34 设计一个复数类,成员包括实部和虚部,成员方法包括复数加法、减法、

比较、转换成字符串等运算或操作。 class complex{ double x,y;

complex(double a,double b){x=a;y=b;} }

public class Complex2 {

public static void main(String[] args) {

complex num1=new complex(6,-23); complex num2=new complex(1,-7);

System.out.println("num1的realpart="+"6"+" 其imagepart="+"-23i"); System.out.println("num2的realpart="+"1"+" 其imagepart="+"-7i"); double realpart=num1.x+num2.x; double imagepart=num1.y+num2.y;

System.out.println("相加后 realpart="+realpart+" imagepart="+imagepart+"i");

realpart=num1.x-num2.x; imagepart=num1.y-num2.y;

System.out.println("相减后 realpart="+realpart+" imagepart="+imagepart+"i"); } }

(3) 3-35,3-36

3-35

public class Color{ private int value; public Color(int red,int green,int blue){ value = 0xff000000 | ((red & 0xFF)<<16) | ((green & 0xFF)<<8) | blue & 0xFF; }

public Color(int rgb){

value = 0xff000000|rgb; }

public int getRGB(){ return value; }

public int getRed(){ return (getRGB()>>16) & 0xFF; }

public int getGreen(){ return (getRGB()>>8) & 0xFF; }

public int getBlue(){

return getRGB() & 0xFF; } } 3-36

public class Point { private int x,y; public Point(){} public Point(int x,int y) { this.set(x, y); } public void set(int x,int y) { this.x=x; this.y=y; } public String toString() { return "("+this.x+","+this.y+")"; } public static void main(String[] args) { Point p=new Point(5,6); Pixel p1=new Pixel("黑"); p1.set(3,4); p1.set1("红"); System.out.println("Point的像素点为:"+p); System.out.println("Pixel的像素点为:"+p1.toString()); System.out.println("Pixel的像素点为:"+p1); System.out.println("Pixel的颜色为:"+p1.toString1()); } }

class Pixel extends Point { private String color; // public Pixel(){} public Pixel(String color) {

this.set1(color); } public void set1(String color) { this.color=color; } public String toString1() { return color; } }

(4) 3-38

public class Student { private static int m=1,n=1,k=1;//h=1,i=0,j=0; public String Message(String speciality,String name,int score1,int score2,int score3) { if(speciality=="软件") {System.out.println(name+","+speciality+",000"+k+",高数:"+score1+",英语:"+score2+",C语言:"+score3);k++;} else if(speciality=="商院") {System.out.println(name+","+speciality+",000"+m+",高数:"+score1+",英语:"+score2+",C语言:"+score3);m++;} else if(speciality=="艺术") {System.out.println(name+","+speciality+",000"+n+",高数:"+score1+",英语:"+score2+",C语言:"+score3);n++;} //else newMessage(speciality,name,score1,score2,score3); return null; } public static void main(String[] args) { Student s=new Student(); s.Message("软件","王敏" ,90,89,80); s.Message("软件","张华",60,70,79); s.Message("商院","李天",98,76,85); s.Message("艺术","盛妮",87,78,79); s.Message("艺术","东方琴",67,88,69); s.Message("商院","毕白飞",80,87,72); } }

(5) 4-17

interface Area { public abstract double area(); }

interface Volume { public abstract double volume(); }

public class yuanzhui extends Object implements Area,Volume {

private double radius; private double length; private double height;

public yuanzhui(double radius,double length,double height) {

this.radius = radius; this.length = length; this.height = height; }

public yuanzhui() {

this(0,0,0); }

public double area() //计算圆锥的表面积,实现Area接口中的抽象方法 {

return Math.PI*this.radius*this.length+Math.PI*this.radius* this.radius ; }

public double volume() //计算圆锥的体积,实现Volume接口中的抽象方法 {

return Math.PI * this.radius * this.radius * this.height/3; }

public String toString() {

return "一个圆锥,半径"+this.radius+",高"+this.height+",斜边,"+this.length+"表面积为"+this.area()+",体积为"+this.volume(); }

public static void main(String args[]) { System.out.println(new yuanzhui().toString());

System.out.println(new yuanzhui(10,5,3).toString()); } }

五、实验结果与分析

(1)运行结果:今年是2009,false 2008年8月8日,true ,星期五 2008年8月8日的昨天是2008年8月7日 2008年8月8日的明天是2008年8月9日

(2)运行结果:num1的realpart=6 其imagepart=-23i num2的realpart=1 其imagepart=-7i

相加后 realpart=7.0 imagepart=-30.0i 相减后 realpart=5.0 imagepart=-16.0i (3)Point的像素点为:(5,6) Pixel的像素点为:(3,4) Pixel的像素点为:(3,4) Pixel的颜色为:红

(4)王敏,软件,0001,高数:90,英语:89,C语言:80 张华,软件,0002,高数:60,英语:70,C语言:79 李天,商院,0001,高数:98,英语:76,C语言:85

盛妮,艺术,0001,高数:87,英语:78,C语言:79 东方琴,艺术,0002,高数:67,英语:88,C语言:69 毕白飞,商院,0002,高数:80,英语:87,C语言:72

(5)一个圆锥,半径0.0,高0.0,斜边,0.0表面积为0.0,体积为0.0

一个圆锥,半径10.0,高3.0,斜边,5.0表面积为471.23889803846896,体积为314.1592653589793

六、讨论、思考题

(1) 类的继承有什么好处?

子类继承后可以重写,也可以不重写,看需要决定。如果重写的话在实例中调用的是新写的方法如果不重写的话在实例中调用的是父类的方法。

被包含对象通过包含他们的类来访问。黑盒重用,因为被包含对象的内部细节是不可见的。具有很好的封装。通过获得和被包含对象的类型相同的对象引用,可以在运行时动态定义组合的方式。

(2) 抽象类与接口的共同点是什么?不同点表现在哪些地方?

,都可以通过继承实现其抽象方法。都是面向抽象编

程的技术基础,实现了诸多的设计模式。

不同点

;抽象类不能实现多继承。接口只能定义抽象规则;类既

可以定义规则,还可能提供已实现的成员。接口是一组行为规范;抽象类是一个不完全的类。着重族的概念。 接口可以用于支持回调;抽象类不能实现回调,因为继承不支持。 接口只包含方法、属性、索引器、事件的签名,但不能定义字段和包含实现的方法;抽象类可以定义字段、属性、包含有实现的方法。接口可以作用于值类型和引用类型;抽象类只能作用于引用类型。例如,Struct就可以继承接口,而不能继承类。

实验项目名称: 图形用户界面 实验学时: 同组学生姓名: 实验地点: 实验日期: 实验成绩: 批改教师: 批改时间:

实验3 图形用户界面

一、实验目的

(1) (2) (3) (4)

掌握AWT组件的使用方法

熟练掌握AWT中常用界面元素如窗口、菜单、对话框的使用方法 掌握用户界面动作与事件的处理程序的编写方法。 熟练掌握构造用户界面的方法和常见界面元素的使用。

二、实验要求

(1)调试程序要记录调试过程中出现的问题及解决办法;

(2)编写程序要规范、正确,上机调试过程和结果要有记录,不断积累编程及调试经验;

(3)做完实验后给出本实验的实验报告。

三、实验设备、环境

奔腾以上计算机,Windows 98 、J2SDK、IE浏览器

四、实验步骤及内容

编写并调试如下程序(界面采用awt实现):

(1) 6-31设计一个图形界面的计算器程序,要求能够实现加减乘除等基本运算。 (2) import java.awt.*; (3) import java.awt.event.*; (4) import javax.swing.*;

(5) public class Calculator extends Frame implements ActionListener (6) //,WindowListener //定义一个继承Frame主程序类并实现按钮监听器和窗口

监听器接口 (7) {

(8) private Container container;//定义一个私有的抽象组件类container (9) private GridBagLayout layout;//定义一个私有的面板类

(10)private GridBagConstraints constraints;//定义一个私有类用于添加和删除 (11)private JTextField displayField; //计算结果显示区 (12)private String lastCommand; //保存+,-,*,/,=命令0 (13)private double result; //保存计算结果 (14)private boolean start; //判断是否为数字的开始 (15)private JMenuBar menubar;//定义类用于放置菜单 (16)Dialog dialog;//用于对话框的设置 (17)private JButton

(18)button_plusminus,button_cancel,button_1,button_2,

(19)button_3,button_4,button_5,button_6,button_7,button_8,button_9,button_

0,

(20)button_plus,button_minus,button_multiply,button_divide,button_point, (21)button_equal,button_yu;//定义按钮

(22)public Calculator() //构造方法设置布局、为按钮注册事件监听器 (23){

(24)super("Calculator");//调用父类中的calculator方法 (25)this.setLocation(240,200);//设置初始化 (26)this.setSize(350,300);//设置窗口大小

(27)this.setResizable(true);//设置位置可重置说明框架大小可被用户改变 (28)this.setLayout(new GridLayout(7,1));//建立GridLayou版面配置格子 (29)this.addmyMenu(); //调用成员方法添加菜单 (30)displayField=new JTextField(20);//创建文本对象 (31)this.add(displayField);//调用成员方法并添加对象 (32)displayField.setEditable(true);//设置用户可编程文本 (33)start=true; (34)result=0;

(35)lastCommand = "=";//初始化变量 (36)JPanel panel0=new JPanel();//声明对象

(37)panel0.setLayout(new GridLayout(1,1));//使用边框布局指定行数和列数 (38)JPanel panel1=new JPanel();

(39)panel1.setLayout(new GridLayout(1,3,4,4));//使用边框布局和流布局指定行

数、列数和水平垂直间距

(40)this.add(panel1);//调用成员方法并添加panel1 (41)button_cancel=new JButton("CE");//声明按钮对象 (42)button_plusminus=new JButton("+/-"); (43)button_yu=new JButton("%"); (44)JPanel panel2=new JPanel();

(45)panel2.setLayout(new GridLayout(1,4,4,4)); (46)this.add(panel2);

(47)button_7=new JButton("7"); (48)button_8=new JButton("8"); (49)button_9=new JButton("9"); (50)button_divide=new JButton("/"); (51)JPanel panel3=new JPanel();

(52)panel3.setLayout(new GridLayout(1,4,4,4)); (53)this.add(panel3);

(54)button_4=new JButton("4"); (55)button_5=new JButton("5"); (56)button_6=new JButton("6"); (57)button_multiply=new JButton("*"); (58)JPanel panel4=new JPanel();

(59)panel4.setLayout(new GridLayout(1,4,4,4)); (60)this.add(panel4);

(61)button_1=new JButton("1"); (62)button_2=new JButton("2"); (63)button_3=new JButton("3"); (64)button_minus=new JButton("-"); (65)JPanel panel5=new JPanel();

(66)panel5.setLayout(new GridLayout(1,4,4,4)); (67)this.add(panel5);

(68)button_0=new JButton("0"); (69)button_point=new JButton("."); (70)button_equal=new JButton("="); (71)button_plus=new JButton("+");

(72)panel1.add(button_cancel);//把按钮添加到panel上 (73)panel1.add(button_plusminus); (74)panel1.add(button_yu); (75)panel2.add(button_7); (76)panel2.add(button_8); (77)panel2.add(button_9); (78)panel2.add(button_divide); (79)panel3.add(button_4); (80)panel3.add(button_5); (81)panel3.add(button_6); (82)panel3.add(button_multiply); (83)panel4.add(button_1); (84)panel4.add(button_2); (85)panel4.add(button_3);

本文来源:https://www.bwwdw.com/article/f4l1.html

Top