91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

資源簡介

6. 模擬風扇(滿分50分) 版本1:滿分 15 分 模擬實現電風扇,可以調 3 檔速度(慢速、中速、快速);開關按鈕;定時吹風;描述 風扇的扇葉大小、顏色等。 設計Fan 類,屬性包括:3 個常量 SLOW (1)、MEDIUM(2)、FA ST(3)代表風扇的 速度;1 個int 屬性speed 指定速度,默認值為 SLOW ;1 個boolean屬性 on 指定開關機,默 認值false ;1 個double 屬性 radius 指定風扇扇葉大小;1 個String 屬性 color指定扇葉顏色, 默認值為 blue 。方法包括這些屬性的訪問器、構造函數、重寫 Object 類的 toString() 和equals() 方法等。運行測試代碼: public static void main(String[] args) { Fan1 fan1 = new Fan1(); fan1.setSpeed(Fan1.FAST); fan1.setRadius(10); fan1.setColor("yellow" ); fan1.setOn( true); System.out .println(fan1.toString()); } 版本2:滿分 15 分 修改版本 1 中Fan 類,讓其繼承 JPanel 類,并且把 color屬性設置為 Color類型,默認 屬性為 red。隨機產生 radius ,取值范圍為 1-5;隨機產生顏色,取值范圍為 red、blue 、yellow 、 green、orange ;根據 color、radius 屬性值繪制風扇。運行如下圖: 版本3:滿分 20 分 讓版本 2 中的風扇轉起來。創建一個 FanControl 類包含以下內容:Start 、Stop 、Reverse 按鈕,用于開啟、關閉、反轉控制;一個滾動條控制速度。運行示例如下:

資源截圖

代碼片段和文件信息

import?java.awt.Color;
import?java.awt.Graphics;

import?javax.swing.JPanel;

/**
?*?
?*/

/**
?*?@Project?name?AnalogFan
?*?@class?name?Fan
?*?@author?X-Hay
?*?@Date?2013-8-24
?*?@CQUT
?*?@UP.
?*/
public?class?Fan?extends?JPanel?implements?Runnable{

public?static?final?int?SLOW?=?10;
public?static?final?int?MEDIUM?=?5;
public?static?final?int?FAST?=?1;
private?int?speed?=?MEDIUM;
private?boolean?off?=?true;//是否關閉
private?int?radius;
private?Color?color?=?Color.green;
private?int?dushu?=?1;
private?boolean?reverse?=?false;
public?Fan()?{
//創建并開始線程
new?Thread(this).start();
}

public?Fan(int?speed?boolean?off?int?radius?Color?color)?{
this.speed?=?speed;
this.off?=?off;
this.radius?=?radius;
this.color?=?color;
}

/**
?*?@return?the?speed
?*/
public?int?getSpeed()?{
return?speed;
}

/**
?*?@param?speed?the?speed?to?set
?*/
public?void?setSpeed(int?speed)?{
this.speed?=?speed;
}

/**
?*?@return?the?on
?*/
public?boolean?isOff()?{
return?off;
}

/**
?*?@param?on?the?on?to?set
?*/
public?void?setOff(boolean?off)?{
this.off?=?off;
}

/**
?*?@return?the?color
?*/
public?Color?getColor()?{
return?color;
}

/**
?*?@param?color?the?color?to?set
?*/
public?void?setColor(Color?color)?{
this.color?=?color;
}

/**
?*?@return?the?radius
?*/
public?int?getRadius()?{
return?radius;
}

/**
?*?@param?radius?the?radius?to?set
?*/
public?void?setRadius(int?radius)?{
this.radius?=?radius;
}

/**
?*?@return?the?reverse
?*/
public?boolean?isReverse()?{
return?reverse;
}

/**
?*?@param?reverse?the?reverse?to?set
?*/
public?void?setReverse(boolean?reverse)?{
this.reverse?=?reverse;
}

@Override
protected?void?paintComponent(Graphics?g)?{
//?TODO?Auto-generated?method?stub
super.paintComponent(g);


radius?=?(int)(Math.min(getSize().width?getSize().height)*0.4);


int?x=getWidth()/2?-?radius;
int?y=getHeight()/2-radius;
g.setColor(Color.black);
g.drawOval(x-20?y-20?2*radius+40?2*radius+40);
g.setColor(color);
g.fillArc(x?y?2*radius?2*radius?0+dushu?30);
g.fillArc(x?y?2*radius?2*radius?90+dushu?30);
g.fillArc(x?y?2*radius?2*radius?180+dushu?30);
g.fillArc(x?y?2*radius?2*radius?270+dushu?30);
}

@Override
public?void?run()?{
//?TODO?Auto-generated?method?stub
try?{
while?(true)?{
if(reverse){
dushu+=1;
}else?{
dushu-=1;
}
repaint();
Thread.sleep(speed);
//每次檢查是否需要暫停
waiting();
}
}?catch?(Exception?e)?{
//?TODO:?handle?exception
}
}
//繼續轉動風扇(線程恢復)
public?synchronized?void?resume()?{?
if?(off)?{?
off?=?false;?
notify();?//恢復所有線程
}
}
//停止轉動風扇(線程暫停)
public?synchronized?void?suspend(){?
off?=?true;?
}
//讓線程等待達到停止轉動的效果
private?synchronized?void?waiting()?throws?InterruptedException?{?
while?

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----

?????文件????????301??2013-08-24?11:02??AnalogFan\.classpath

?????文件????????385??2013-08-24?11:02??AnalogFan\.project

?????文件????????598??2013-08-24?11:02??AnalogFan\.settings\org.eclipse.jdt.core.prefs

?????文件???????5272??2013-08-24?11:08??AnalogFan\.settings\org.eclipse.jdt.ui.prefs

?????文件???????3216??2013-08-27?09:49??AnalogFan\bin\Fan.class

?????文件???????2037??2013-08-27?09:49??AnalogFan\bin\Fan1.class

?????文件???????2562??2013-08-27?09:49??AnalogFan\bin\Fan2.class

?????文件????????710??2013-08-27?09:49??AnalogFan\bin\FanControl$1.class

?????文件????????711??2013-08-27?09:49??AnalogFan\bin\FanControl$2.class

?????文件????????844??2013-08-27?09:49??AnalogFan\bin\FanControl$3.class

?????文件????????837??2013-08-27?09:49??AnalogFan\bin\FanControl$4.class

?????文件???????2061??2013-08-27?09:49??AnalogFan\bin\FanControl.class

?????文件????????141??2013-08-24?12:02??AnalogFan\bin\java.policy.applet

?????文件????????982??2013-08-27?09:49??AnalogFan\bin\Test1.class

?????文件????????849??2013-08-27?09:49??AnalogFan\bin\Test2.class

?????文件???????1132??2013-08-24?20:59??AnalogFan\bin\uml.umr

?????文件???????3165??2013-08-24?15:07??AnalogFan\src\Fan.java

?????文件???????1678??2013-08-24?11:20??AnalogFan\src\Fan1.java

?????文件???????2780??2013-08-24?20:55??AnalogFan\src\Fan2.java

?????文件???????2334??2013-08-24?15:06??AnalogFan\src\FanControl.java

?????文件????????459??2013-08-24?11:44??AnalogFan\src\Test1.java

?????文件????????580??2013-08-24?20:49??AnalogFan\src\Test2.java

?????文件???????1132??2013-08-24?20:59??AnalogFan\src\uml.umr

?????目錄??????????0??2013-08-24?11:08??AnalogFan\.settings

?????目錄??????????0??2013-08-27?09:49??AnalogFan\bin

?????目錄??????????0??2013-08-24?20:59??AnalogFan\src

?????目錄??????????0??2013-08-24?11:02??AnalogFan

-----------?---------??----------?-----??----

????????????????34766????????????????????27



............此處省略0個文件信息

評論

共有 條評論