JavaSE series code 65: display images in applets

§ create a thread object in two ways: - declare a subclass of a thread class and override the run () method. Class myThread extends Thread {public void run() {/ * overrides the method * /}} - declares a class that implements the runnable interface and implements the run() method. Class myThread implements runnable {public void run() {/ * implements the method * /}}}

import java.awt.*; 
import java.applet.Applet;
public class Javase_65 extends Applet   //定义主类
{
  Image img;
  public void init()  //初始化操作,将图像"jpp.jpg"装入img中
  {
    img=getImage(getCodeBase(),"jpp.jpg");
  }
  public void paint(Graphics g)
  {
    g.drawString("java",50,15);       //在小程序窗口显示文字
    g.drawImage(img,30,30,200,200,this);  //将img显示在窗口中
    play(getDocumentBase(),"mus.mid");   //播放音乐"mus.mid"
  }
}

<Javase_65 .html>
<html>
<applet code="Javase_65 .class"
        width=300
        height=250 >
</applet>
</html>
Published 73 original articles · praised 189 · 10,000+ views

Guess you like

Origin blog.csdn.net/blog_programb/article/details/105568424