⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 appletdemo5.java

📁 java程序设计语言源代码
💻 JAVA
字号:
//Example 5 of Chapter 6

import  java.awt.*;
import  java.awt.event.*;
import  javax.swing.*;

public  class  AppletDemo5  extends  JApplet  implements  ActionListener
{
	private  ImageIcon  cat[], flower[];
	private  int  Numbercat = 8, Numberflower = 4, current1 = 0, current2 = 0;
	private  int  delay1 = 200, delay2 = 300;
	private  int  width1, width2, height1, height2;
	private  Timer  timer1, timer2;
	
	public  void  init()
	{
		getContentPane().setBackground( Color.white );
		cat = new ImageIcon[ Numbercat ];
		flower = new ImageIcon[ Numberflower ];
		for (int i = 0; i<cat.length; i++)
		cat[i] = new ImageIcon( "gifmovies/" + "02_0" + i +".gif" );
		for (int i = 0; i<flower.length; i++)
		flower[i] = new ImageIcon( "gifmovies/" + "18_0" + i + ".gif" );
		
		width1 = cat[0].getIconWidth();
		height1 = cat[0].getIconHeight();
		width2 = flower[0].getIconWidth();
		height2 = flower[0].getIconHeight();
	}
	
	public  void  paint( Graphics  g )
	{
		super.paint( g );
		g.setFont( new Font( "Dialog", Font.BOLD, 16 ));
		g.drawString( "Animation Demonstration" , 15 , 15);
		
		cat[ current1 ].paintIcon( this, g, 10, 22 );
		if( timer1.isRunning() ) current1 = ( current1 + 1 ) % Numbercat;
		flower[ current2 ].paintIcon( this, g, 150, 22 );
		if( timer2.isRunning() ) current2 = ( current2 + 1 ) % Numberflower;
	}
	
	public  void  start()
	{
		if( timer1 == null )
		{
			current1 = 0;
			timer1 = new Timer( delay1, this );
			timer1.start();
		}
		else
		{
			if ( ! timer1.isRunning() ) timer1.restart();
		}
		
		if( timer2 == null )
		{
			current2 = 0;
			timer2 = new Timer( delay2, this );
			timer2.start();
		}
		else
		{
			if ( ! timer2.isRunning() ) timer2.restart();
		}
	}

	public  void  stop()
	{
		timer1.stop();
		timer2.stop();
	}
	
	public  void  actionPerformed( ActionEvent  e )
	{
		repaint();
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -