1350340122 刘光宇 实验五.docx
《1350340122 刘光宇 实验五.docx》由会员分享,可在线阅读,更多相关《1350340122 刘光宇 实验五.docx(9页珍藏版)》请在冰豆网上搜索。
1350340122刘光宇实验五
院(系)计算机学院专业计科(嵌入式)班级13计科3班
姓名刘光宇学号1350340122同组人无
实验室S4305组号日期2015.11.11
课程Java程序设计指导教师余慧成绩
实验项目编号8103200405实验项目名称图形用户界面编程
一、实验目的
熟悉并掌握Java窗体和组件的定义,事件的定义。
二、实验环境
WindowsXP操作系统
Eclipse
三、实验原理
通过对界面的学习,对之前写过的buildinghouse进行界面化设计
四、算法设计
【任务一】在实验二BuildingHouse的基础上,添加界面。
如下图所示。
五、主要代码及说明
【任务一】
Buildinghouse.java中:
importjava.util.Scanner;
publicclassBuildHouse{
publicstaticvoidmain(String[]args){
Scannersc=newScanner(System.in);
Stringtest;
test="livingroom";
System.out.println("nowroom:
"+test);
System.out.print("Pleaseimportroomname:
");
Roomdining=newRoom("dining");
dining.decoration="Acrystalchandelier";
Roomwdlivingroom=newRoomwd("livingroom");
//livingroom.name="livingroom";
livingroom.decoration="Anantiquecarpe";
livingroom.ShowDoor("Anantiquecarpe");
Roomwdkitchen=newRoomwd("kitchen");
//kitchen.name="kitchen";
kitchen.decoration="stainlesssteelapplience";
kitchen.ShowDoor("Stainlesssteelappliance");
Outwdbackyard=newOutwd("backyard");
//backyard.name="backyard";
backyard.temperature="hot";
backyard.ShowDoor("Ascreendoor");
OutwdFrontYard=newOutwd("FrontYard");
//FrontYard.name="FrontYard";
FrontYard.temperature="nothot";
FrontYard.ShowDoor("Anoakdoorwithabrassknob");
Outsidegarden=newOutside("garden");
//garden.name="garden";
garden.temperature="nothot";
garden.aisle[0]=FrontYard;
garden.aisle[1]=backyard;
FrontYard.aisle[0]=livingroom;
FrontYard.aisle[1]=garden;
backyard.aisle[0]=kitchen;
backyard.aisle[1]=garden;
kitchen.aisle[0]=dining;
kitchen.aisle[1]=backyard;
livingroom.aisle[0]=dining;
livingroom.aisle[1]=FrontYard;
dining.aisle[0]=livingroom;
dining.aisle[1]=kitchen;
while(true)
{
Stringhouse=sc.nextLine();
if(house.equals(dining.name))
{
if(test.equals(dining.aisle[0].name)||test.equals(dining.aisle[1].name))
{
System.out.println(dining.GetDecription());
test=house;
System.out.println("nowroom:
"+test);
System.out.print("pleaseimportroomname:
");
}
else
{
System.out.println("youcanoutcomeintheroom");
System.out.print("Pleaseimportroomname:
");
}
}
elseif(house.equals(livingroom.name))
{
if(test.equals(livingroom.aisle[0].name)||test.equals(livingroom.aisle[1].name))
{
System.out.println(livingroom.GetDecription());
test=house;
System.out.println("nowroom:
"+test);
System.out.print("pleaseimportroomname:
");
}
else
{
System.out.println("youcanoutcomeintheroom");
System.out.print("Pleaseimportroomname:
");
}
}
elseif(house.equals(kitchen.name))
{
if(test.equals(kitchen.aisle[0].name)||test.equals(kitchen.aisle[1].name))
{
System.out.println(kitchen.GetDecription());
test=house;
System.out.println("nowroom:
"+test);
System.out.print("pleaseimportroomname:
");
}
else
{
System.out.println("youcanoutcomeintheroom");
System.out.print("Pleaseimportroomname:
");
}
}
elseif(house.equals(backyard.name))
{
if(test.equals(backyard.aisle[0].name)||test.equals(backyard.aisle[1].name))
{
System.out.println(backyard.GetDescription());
test=house;
System.out.println("nowroom:
"+test);
System.out.print("pleaseimportroomname:
");
System.out.print("Pleaseimportroomname:
");
}
else
{
System.out.println("youcanoutcomeintheroom");
}
}
elseif(house.equals(FrontYard.name))
{
if(test.equals(FrontYard.aisle[0].name)||test.equals(FrontYard.aisle[1].name))
{
System.out.println(FrontYard.GetDescription());
test=house;
System.out.println("nowroom:
"+test);
System.out.print("pleaseimportroomname:
");
}
else
{
System.out.println("youcanoutcomeintheroom");
System.out.print("Pleaseimportroomname:
");
}
}
elseif(house.equals(garden.name))
{
if(test.equals(garden.aisle[0].name)||test.equals(garden.aisle[1].name))
{
System.out.println(garden.GetDescription());
test=house;
System.out.println("nowroom:
"+test);
System.out.print("pleaseimportroomname:
");
}
else
{
System.out.println("youcanoutcomeintheroom");
System.out.print("Pleaseimportroomname:
");
}
}
else
{
System.out.println("youimportroomnameiserror!
");
System.out.print("Pleaseimportroomname:
");
}
if(house.equals("##")){
break;
}
}
}
}
House.java中:
publicabstractclassHouse{
protectedStringname;
protectedStringdescription;
protectedHouse[]aisle=newHouse[2];
protectedStringGetDescription()
{
for(inti=0;ithis.description="istandthe"+name
+"\niseetheaisle"+aisle[i].name+",";
}
returndescription;
}
}
IDoor.java中:
publicinterfaceIDoor{
publicvoidShowDoor(Stringdoor);
}
Outside.java中:
publicclassOutsideextendsHouse{
protectedStringtemperature;
protectedOutside(){
}
protectedOutside(Stringname){
this.name=name;
}
protectedStringGetDescription()
{
this.description=super.GetDescription()+
"\nithinkthetemperatureis:
"+temperature;
returndescription;
}
}
classOutwdextendsOutsideimplementsIDoor{
protectedOutwd(Stringname){
this.name=name;
}
Stringdoor;
publicvoidShowDoor(Stringdoor){
this.door=door;
}
publicStringGetDescription(){
this.description=super.GetDescription()+
"\nthisdooris:
"+door;
returndescription;
}
}
Room.java中:
publicclassRoomextendsHouse{
protectedStringdecoration;
protectedRoom(){
}
protectedRoom(Stringname){
this.name=name;
}
protectedStringGetDecription()
{
this.description=super.GetDescription()+"\niseethedecorationis:
"+decoration;
returndescription;
}
}
classRoomwdextendsRoomimplementsIDoor{
Stringdoor;
protectedRoomwd(Stringname){
this.name=name;
}
publicvoidShowDoor(Stringdoor){
this.door=door;
}
publicStringGetDescription(){
this.description=super.GetDescription()+
"\nthisdooris:
"+door;
returndescription;
}
}
六、实验小结
在这次界面设计中,了解了界面设计的各种组件,面板用法,也对界面布局有一定的认识,也知道了如何对事件进行监听。