1350340122 刘光宇 实验五.docx

上传人:b****6 文档编号:5994796 上传时间:2023-01-02 格式:DOCX 页数:9 大小:32.84KB
下载 相关 举报
1350340122 刘光宇 实验五.docx_第1页
第1页 / 共9页
1350340122 刘光宇 实验五.docx_第2页
第2页 / 共9页
1350340122 刘光宇 实验五.docx_第3页
第3页 / 共9页
1350340122 刘光宇 实验五.docx_第4页
第4页 / 共9页
1350340122 刘光宇 实验五.docx_第5页
第5页 / 共9页
点击查看更多>>
下载资源
资源描述

1350340122 刘光宇 实验五.docx

《1350340122 刘光宇 实验五.docx》由会员分享,可在线阅读,更多相关《1350340122 刘光宇 实验五.docx(9页珍藏版)》请在冰豆网上搜索。

1350340122 刘光宇 实验五.docx

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;i

this.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;

}

}

 

六、实验小结

在这次界面设计中,了解了界面设计的各种组件,面板用法,也对界面布局有一定的认识,也知道了如何对事件进行监听。

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 教学研究 > 教学反思汇报

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1