¼Ò¼³ java.applet¼Ò½ºÄڵ堠Applet  ¾ÖÇø´¿¡¼­ ¿©·¯Àå À̹ÌÁö ·Îµù  

¾ÖÇø´¿¡¼­ ¿©·¯ÀåÀÇ À̹ÌÁö¸¦ ·ÎµùÇØ Çϳª¾¿ º¸¿©ÁÖ´Â ¿¹Á¦

ImageChange.java

import java.applet.*;
import 
java.awt.event.*;
import 
java.awt.*; 
public class ImageChange extends Applet implements 
ActionListener{
  
private Button b1=null
;
  
private Image img1,img2,img3 = null
;
  
private Image temp = null
;
  
private int myflag=1
;
  
public void 
init() {
    
this.b1 = new Button("Image Change"
);
    
this
.add(b1);
    
this.b1.addActionListener(this
);
    
this.img1 = this.getImage(this.getDocumentBase(), "./jabook02.gif"
);
    
this.img2 = this.getImage(this.getDocumentBase(), "./jabook01.gif"
);
    
this.img3 = this.getImage(this.getDocumentBase(), "./dukesign.gif"
);
  }
  
public void 
paint(Graphics g) {
    
if(temp!=null
)
      g.drawImage(temp, 
2235this
);
  }
  
public void 
actionPerformed(ActionEvent e) {
    
this.myflag += 1
;
    
if 
(myflag>3) {
      myflag = 
1
;
    }
if(myflag==1
) {
      temp = img1;
      repaint();
    }
else if(myflag==2
) {
      temp = img2;
      repaint();
    }
else if(myflag==3
) {
      temp = img3;
      repaint();
    }
  }
}

ImageChange.html

<html><head><title>Image Change Test</title></head>
<body>
<applet code="ImageChange.class" width=200 height=150
></applet>
</body>
</html>

C:\JavaExample\15>javac ImageChange.java
C:\JavaExample\15>appletviewer ImageChange.java

   

¾×¼Ç À̺¥Æ®¿Í getImage()¸Þ¼­µå¸¦ »ç¿ëÇÏ¿© ¼Õ½±°Ô ¿©·¯ÀåÀÇ À̹ÌÁö¸¦ µ¹·Á°¡¸ç º¸¿©ÁÙ ¼ö ÀÖ´Ù



jabookÀúÀÚ¸íÇÔ
Á¦¸ñ:¼Ò¼³°°Àº¹Ì´ÏÄÚµå
ÀÛ¼ºÀÚ:Àںϸâ¹ö ÀÌÇѼö