Advertisement
Psycho_Coder

Set Background Image in Applet

Oct 10th, 2014
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.54 KB | None | 0 0
  1. import java.awt.Graphics;
  2. import java.awt.Graphics2D;
  3. import java.awt.Image;
  4. import javax.swing.ImageIcon;
  5. import javax.swing.JApplet;
  6.  
  7. public class SetImage extends JApplet {
  8.  
  9.     private Image image;
  10.  
  11.     @Override
  12.     public void init() {
  13.         image = null;
  14.     }
  15.  
  16.     @Override
  17.     public void paint(Graphics g) {
  18.         Graphics2D g2d = (Graphics2D) g;
  19.         ImageIcon icon = new ImageIcon(SetImage.class.getResource("avatar.png"));
  20.         image = icon.getImage();
  21.         g2d.drawImage(image, 0, 0, null);
  22.     }
  23.  
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement