Code not running~~Help


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Code not running~~Help

  1. #1
    Join Date
    Jan 2004
    Posts
    1

    Arrow Code not running~~Help

    i try to display a random images on the applet using array to store all the pictures name.
    what's wrong with the code?

    package test;

    import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;

    public class Applet extends java.applet.Applet
    {
    Image thisFlag;
    String images[]= {"0.gif", "1.gif"};

    public void init()
    {
    int value;
    value=(int)(java.lang.Math.random()*images.length);
    thisFlag = getImage(getCodeBase(), images[value]);
    }

    public void paint(Graphics g)
    {
    g.drawImage(thisFlag,20,20,this);
    }
    }

  2. #2
    Join Date
    Jan 2004
    Posts
    1
    I got this to work by changing the line..

    Code:
    thisFlag = getImage(getCodeBase(), images[value]);
    to

    Code:
    thisFlag=Toolkit.getDefaultToolkit().createImage(images[value]);
    Also make sure your images are in the classes folder.

    Hope this helps.

    GP

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center