资源描述:
《JAVA多线程demo》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、packagemultimediademo;importjava.net.*;importjava.applet.*;importjava.applet.Applet;importjava.awt.image.*;importjava.awt.*;importmultimediademo.ImageFilter;importjavax.swing.*;/***
Title:
*
Description:
*
Copyright:Copyright(c)2003
*
Company:
*@authornotattributab
2、le*@version1.0*/publicclassDemoThreadextendsThread{//********************************类变量**********************************//四个私有变量:滚动面板对象、图像类对象、图形对象和动画类型值privateJScrollPanem_scroll;privateImagesourceImage,filteredImage;privateGraphicsm_graph;//1表示缩放平移动画,2表示不擦除平移动画,3表示淡入淡出动画privateintm
3、_demoType;//申明一个图像过滤器//ImageFilterimageFilter;//定义初始点intstartX=50;intstartY=50;booleanREPAINT_MARK;intimageWidth,imageHeight;intpanelWidth,panelHeight;intm_imageWidth,m_imageHeight;intSTEP=10;//********************************类方法**********************************//默认构造函数publicDemoThre
4、ad(){}//重载构造函数publicDemoThread(Imageimage,JScrollPanescrollPanel,intdemoType){//给私有变量赋值sourceImage=image;filteredImage=image;m_scroll=scrollPanel;m_demoType=demoType;//获取图形对象m_graph=m_scroll.getGraphics();//获取面板对象和图像的尺寸imageWidth=filteredImage.getWidth((Component)m_scroll);imageHeight
5、=filteredImage.getHeight((Component)m_scroll);panelWidth=m_scroll.getWidth();panelHeight=m_scroll.getHeight();}//重载线程操作函数publicvoidrun(){initializeRun();//moveDirect表示图像水平移动的方向:取true表示由左向右移动,false则表示相反的方向booleanmoveDirect=true;while(true){//画动画的第一副图像if(!REPAINT_MARK){m_graph.drawImage
6、(filteredImage,startX,startY,m_imageWidth,m_imageHeight,m_scroll);try{Thread.sleep(1000);}catch(InterruptedExceptione){}REPAINT_MARK=true;}//画动画的其他图像://m_demoType表示动画类型,1表示缩放平移动画,2表示不擦除平移动画,3表示淡入淡出动画else{switch(m_demoType){//水平移动缩放动画case1:if(moveDirect){//图像由左向右移动并缩小m_graph.clearRect(
7、startX,startY,m_imageWidth,m_imageHeight);startX+=STEP;//判断动画移动是否反向if((startX+m_imageWidth)>panelWidth){startX-=STEP;moveDirect=false;m_graph.clearRect(startX,startY,m_imageWidth,m_imageHeight);try{Thread.sleep(1000);}catch(InterruptedExceptione){}}else{m_imageWidth=(int)(m_imageWidth
8、*0.9)