Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Aug 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question random images in java

    I would like to display random images in a java applet i am doing. i have to create a card game called 'snap'. I would like 2 random cards to appear on the applet every time the 'Next' button is pressed which i will be creating. This is the skeleton program i was given to start this program., Thanks in advance.


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

    public class CardGame extends Applet implements ActionListener /*NB other interfaces may be added*/
    {
    int MAX= some_value;
    MyObj myObjects[];

    public void start()
    {
    myObjects=new MyObj[MAX];

    //instantiate objects here
    myObjects[0]=new MyObj(/*some_arguments*/);
    }

    public void actionPerformed(ActionEvent e)
    {
    }

    public void paint(Graphics g)
    {
    }
    }

    class MyObj {
    MyObj(/*some_arguments*/) {
    }
    }

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,050
    Thanks
    0
    Thanked 251 Times in 247 Posts
    This is JavaScript forum not Java.

  • #3
    New Coder
    Join Date
    Jan 2004
    Posts
    61
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I would created a Array of String of the image URL, then randome pick out using

    double i = Math.random()*array.length-1;
    int k = (int) i;

    then do the if & else statement

    **Title does does said "JAVA"**


  •  

    Posting Permissions

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