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

📄 testapplet.java

📁 开始学JAVA老师布置的作业一学期的哦希望新手有用
💻 JAVA
字号:
import java.applet.*;
import java.awt.*;
public class TestApplet extends Applet implements Runnable
{   
	Thread thread1,thread2;
	AudioClip m_audio;
	Image[] m_Images = new Image[5];
	int totalImages = 5;
	int currentImage = 0;
	String strname,strage,strsex,strnum,strphone;
	int rectWidth,rectHeight;
	public void init()
	{
		m_audio = getAudioClip(getCodeBase(),"sound/test.au");		
	    for(int i=0;i<=totalImages-1;i++)
	       m_Images[i] = getImage(getDocumentBase(),"IMAGES/p"+i+".gif");
		strname = getParameter("myname");
		strage  = getParameter("myage");
		strsex  = getParameter("mysex");
		strnum  = getParameter("mynum");
		strphone= getParameter("myphone");
		rectWidth = 100;
		rectHeight = 50;
	}
	public void start()
	{
		if(thread1 ==null)
		{
			thread1 = new Thread(this,"t1");
			thread1.start();
		}
		if(thread2 == null)
		{
			thread2 = new Thread(this,"t2");	
			thread2.start();
		}
	}
	public void run()
	{
		String s = Thread.currentThread().getName();
		System.out.println("--------"+s+"-----");
			if(s.equals("t1"))
			{
				while(true)
				{
					m_audio.play();
					try{
						Thread.sleep(3000);
					   }
					 catch(InterruptedException e) {}  			
				}
		    }
		    else if(s.equals("t2"))
		    {
				while(true)
				{
					repaint();
					try{
					     Thread.sleep(2000);
					   }
					 catch(InterruptedException e) {}  
				}
		    }
	}
	public void stop()
	{
		thread1 = null;
		thread2 = null;
	}
	public void destroy()
	{
	
	}
	public void paint(Graphics g)
	{
		Font f = new Font("仿宋_GB2312",0,20);
		g.setFont(f);
		g.setColor(Color.blue);
		g.drawString(strname,10,20);
		g.drawString(strage,10,40);
		g.drawString(strsex,10,60);
		g.drawString(strnum,10,80);
		g.drawString(strphone,10,100);
		
		for(int i=0;i<4;i++)
		for(int j=0;j<=i;j++)
		{
			g.drawString("*",300+(i-j)*20,20+i*20);
			g.drawString("*",300-(i-j)*20,20+i*20);
		}
		
		g.drawImage(m_Images[currentImage],200,150,this);
		currentImage = ++currentImage % totalImages;
		
		g.drawRect(10,120,rectWidth,rectHeight);
		g.drawOval(10,120,rectWidth,rectHeight);
		
	}
}

⌨️ 快捷键说明

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