Results 1 to 6 of 6

Thread: Need Help with Importing Image

Threaded View

  1. #4
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    Re: Need Help with Importing Image

    Each time i refresh firefox i get a new image.
    Code:
     import java.io.*; 
     import java.awt.*; 
     import java.util.*;
     import javax.swing.*; 
    
     public class AppletEx extends JApplet{
      private Image image; 
      private String[] filenames; 
      private File imgdir; 
      private int dirlength; 
      private Random r;
      private int imageindex;
      
      public void init(){
       imgdir = new File("C:\\Pics");
       filenames = imgdir.list(); 
       dirlength = filenames.length; 
       r = new Random(); 
       imageindex = r.nextInt(dirlength);
       image = Toolkit.getDefaultToolkit().getImage(imgdir.getPath() + "//" + filenames[imageindex]); 
      }
      public void paint(Graphics gfx){
       gfx.drawImage(image,50,50,this);
      }
     }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width