第八章13编写程序,一个画圆,一个画椭圆。16模拟排队买票,球票5元,购票者持有5,10,20,50元的,售票员手里开始没有零钱。47修改例85程序,使一些暂时找不到零钱等待的顾客能按照先来先买的规则,排队等待购买纪念品。14
第八章
3编写程序,一个画圆,一个画椭圆。3编写程序,一个画圆,一个画椭圆。编写程序
程序运行结果:
Applet的源文件:Work8_3java
importjavaappletAppletimportjavaawtColorimportjavaawtGraphics83用一个红色笔画圆,同时用一个蓝色笔画椭圆publicclassWork8_3exte
dsAppletimpleme
tsRu
ableprivatestaticfi
allo
gserialVersio
UID1L两个线程,红笔线程,和蓝笔线程privateThreadred_threadblue_thread红色画笔、蓝色画笔privateGraphicsredPe
bluePe
蓝、红笔画时需要旋转角度privatei
tblue_a
gle0red_a
gle0红色画的图案的中心坐标privatei
ta_red100b_red100蓝色画的图案的中心坐标privatei
ta_blue300b_blue100圆形半径privatei
tradius_red80椭圆的两个半径
fprivatei
tradius1_blue150radius2_blue100publicvoidi
itred_thread
ewThreadthisblue_thread
ewThreadthisredPe
getGraphicsbluePe
getGraphicssetBackgrou
dColorwhitesetSize470240publicvoidstartred_threadstart两个线程开始blue_threadstartpublicvoidru
whiletrueifThreadcurre
tThreadred_threadredPe
drawOval2525160160绘制圆的边框。xywidthheighti
txgetXradius_redred_a
glea_redi
tygetYradius_redred_a
gleb_redredPe
setColorColorWHITEredPe
fillOvalxy1010用白色画一次,可以擦出痕迹red_a
gle3ifred_a
gle360red_a
gle0xgetX80red_a
gle100ygetY80red_a
gle100redPe
setColorColorREDredPe
fillOvalxy1010使用当前颜色填充外接指定矩形框的椭圆tryThreadsleep10catchI
terruptedExceptio
eelseifThreadcurre
tThreadblue_threadbluePe
drawOvala_blue25b_blue245radius1_blue2radius2_blue2绘制椭圆的边框。xywidthheighti
txgetXradius1_blueblue_a
glea_bluei
tygetYradius2_blueblue_a
gleb_bluebluePe
setColorColorWHITEbluePe
fillOvalxy1010擦除r