|
最初にイメージを描いてやると、あとから上書き回転しません。 最初のイメージを描いた「//の箇所」の工夫の仕方を他のプログラムを参考にしたかっただけですけど。
以外に皆さんのご意見って厳しいですネ!! 困ってるから皆さんのチョッとした助けが欲しいと、このサイトに来ただけなんですけど( ..)φ(-_-)/~~~ピシー!ピシー!
===========================================================================================================
public class Slot3 extends Applet implements ActionListener , Runnable { Image[] img1 = new Image[3] ; Image[][] img2 = new Image[3][3] ;
Button sta ; Button stp1 ; Button stp2 ; Button stp3 ; Font font1 ; Font font2 ;
Thread runner ; int sleeptime = 300 ; int frag1 = 0 ; int frag2 = 1 ; int frag3 = 2 ; boolean rotate1 = false ; boolean rotate2 = false ; boolean rotate3 = false ; Graphics g = getGraphics() ;
String cmd ; int fr ; public void init() { setLayout(null); setBackground( new Color( 73 , 128 , 128 ) ); font1 = new Font( "Courier" , Font.BOLD , 30 ) ; stp1 = new Button( "STOP1" ) ; stp1.setBackground( new Color( 149 , 64 , 183 ) ) ; stp1.setForeground(Color.yellow) ; setFont( font1 ); add( stp1 ) ; stp1.addActionListener( this ) ; stp1.setBounds( 300 , 265 , 150 , 50 ) ; stp2 = new Button( "STOP2" ) ; stp2.setBackground( new Color( 0xC7,15,85 ) ) ; stp2.setForeground(new Color(99,32,0xCC)) ; add( stp2 ) ; stp2.addActionListener( this ) ; stp2.setBounds( 450 , 265 , 150 , 50 ) ; stp3 = new Button( "STOP3" ) ; stp3.setBackground(Color.orange) ; stp3.setForeground( new Color( 80,00,80 ) ) ; add( stp3 ) ; stp3.addActionListener( this ) ; stp3.setBounds( 600 , 265 , 150 , 50 ) ; sta = new Button( "S T A R T" ) ; font2 = new Font( "Serif" , Font.BOLD | Font.ITALIC , 40 ) ; sta.setBackground(Color.magenta) ; sta.setForeground(Color.cyan) ; setFont(font2); add( sta ) ; sta.addActionListener( this ) ; sta.setBounds( 300 , 325 , 450 , 50 ) ; getImage1(); getImage2(); } public void getImage1() { img1[0] = getImage( getDocumentBase() , "r0.jpg" ) ; img1[1] = getImage( getDocumentBase() , "r1.jpg" ) ; img1[2] = getImage( getDocumentBase() , "r2.jpg" ) ; } public void paint( Graphics g ) { // g.drawImage( img1[0] , 300 , 100 , 150 , 150 , this ) ; // g.drawImage( img1[1] , 450 , 100 , 150 , 150 , this ) ; // g.drawImage( img1[2] , 600 , 100 , 150 , 150 , this ) ; g.setColor(Color.red); g.drawRect( 300 , 100 , 150 , 150 ) ; g.drawRect( 450 , 100 , 150 , 150 ) ; g.drawRect( 600 , 100 , 150 , 150 ) ; } public void getImage2() { for( int j = 0 ; j <= 2 ; j ++ ) { for( int i = 0 ; i <= 2 ; i ++ ) { img2[i][j] = img1[i] ; img2[i][j] = img1[i] ; img2[i][j] = img1[i] ; } } } public void run( ) { while( runner != null) { if( rotate1 == true ) { frag1 ++ ; if( frag1 > 2 ) frag1 = 0 ; try { dispImage1(frag1) ; } catch(Exception e) { } repaint(); } if(rotate2 == true ) { frag2 ++ ; if( frag2 > 2 ) frag2 = 0 ; try { dispImage2(frag2) ; } catch(Exception e) { } repaint(); } if(rotate3 == true) { frag3 ++ ; if( frag3 > 2 ) frag3 = 0 ; try { dispImage3(frag3) ; } // { g.drawImage(img2[2][frag3] , 600 , 100 , 150 , 150 , this ) ; } catch(Exception e) { } repaint(); } try{ runner.sleep( sleeptime ) ; } catch( Exception e ){ } } } public void dispImage1( int i ) { Graphics g = getGraphics() ; fr = i; g.drawImage(img2[fr][0] , 300 , 100 , 150 , 150 , this ) ; } public void dispImage2( int i ) { Graphics g = getGraphics() ; fr = i; g.drawImage(img2[fr][1] , 450 , 100 , 150 , 150 , this ) ; } public void dispImage3( int i ) { Graphics g = getGraphics() ; fr = i; g.drawImage(img2[fr][2] , 600 , 100 , 150 , 150 , this ) ; } //実行開始 public void start() { if( runner == null ) { runner = new Thread( this ) ; runner.start() ; } } //実行停止 public void stop() { if(runner != null) runner = null ; } public void update( Graphics g ) { paint(g); }
//Actionevent public void actionPerformed( ActionEvent ev ) { // if(String cmd == ev.getActionCommand("S T A R T")) // {sta_ActionPerformed(ev) ;} Object obj = ev.getSource() ; if(obj.equals(sta)) sta_ActionPerformed(ev) ; else if(obj.equals(stp1)) stp1_ActionPerformed(ev) ; else if(obj.equals(stp2)) stp2_ActionPerformed(ev) ; else if(obj.equals(stp3)) stp3_ActionPerformed(ev) ; System.out.println( "obj = sta" ) ; } public void sta_ActionPerformed(ActionEvent ev) { if( ( ! rotate1 ) && ( ! rotate2 ) && (! rotate3 ) ) { rotate1 = rotate2 = rotate3 = true ; } } public void stp1_ActionPerformed(ActionEvent ev) { rotate1 = false ; } public void stp2_ActionPerformed(ActionEvent ev) { rotate2 = false ; } public void stp3_ActionPerformed(ActionEvent ev) { rotate3 = false ; } }
|