DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  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

Bookmarks

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


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links