Results 1 to 2 of 2

Thread: probs

  1. #1
    amith is offline Member
    Join Date
    May 2008
    Posts
    24
    Rep Power
    0

    Default probs

    i just want to load these images with switch case but it is not working can u solve the problem

    import java.util.*;
    import java.awt.*;
    import javax.swing.*;
    class load extends JComponent
    {

    Image r1;
    Image b1;
    Image p1;
    Image g1;
    Image y1;
    Image f1;
    Image temp;
    int c;
    int y=329;

    int x=3;
    int n=3;

    load()
    {

    r1=new ImageIcon("red.png").getImage();
    b1=new ImageIcon("blue.png").getImage();
    p1=new ImageIcon("pink.png").getImage();
    g1=new ImageIcon("green.png").getImage();
    y1=new ImageIcon("yellow.png").getImage();
    f1=new ImageIcon("cursor.png").getImage();

    Random pic=new Random();
    c=pic.nextInt(n);
    switch(c)
    {
    case 0:



    void paint(Graphics q)
    {
    q.drawImage(r1,x,y,this);
    q.drawImage(b1,x+32,y,this);
    q.drawImage(p1,x+64,y,this);
    q.drawImage(g1,x+96,y,this);
    q.drawImage(y1,x+128,y,this);
    q.drawImage(f1,10,257,this);
    }
    break;

    case 1:


    void paint(Graphics q)
    {
    q.drawImage(r1,x,y,this);
    q.drawImage(b1,x+32,y,this);
    q.drawImage(p1,x+64,y,this);
    q.drawImage(g1,x+96,y,this);
    q.drawImage(y1,x+128,y,this);
    q.drawImage(f1,10,257,this);
    } break;

    case 2:


    void paint(Graphics q)
    {
    q.drawImage(r1,x,y,this);
    q.drawImage(b1,x+32,y,this);
    q.drawImage(p1,x+64,y,this);
    q.drawImage(g1,x+96,y,this);
    q.drawImage(y1,x+128,y,this);
    q.drawImage(f1,10,257,this);
    } break;
    }


    }

    }
    class f
    {
    public static void main(String args[])
    {
    load v=new load();
    JFrame b=new JFrame("sdfdsf");
    b.getContentPane().add(v);
    b.setVisible(true);
    b.setSize(175,400);
    b.setResizable(false);
    }
    }

  2. #2
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default something like this, not necessarily exactly

    Java Code:
    final private int NUMBER_OF_IMAGES = ;//
    ImageIcon[] IMAGE_ICON_ARRAY = new ImageIcon[NUMBER_OF_IMAGES];
    
    IMAGE_ICON_ARRAY[0]=new ImageIcon("red.png").getImage();
    IMAGE_ICON_ARRAY[1]=new ImageIcon("blue.png").getImage();
    IMAGE_ICON_ARRAY[2]=new ImageIcon("pink.png").getImage();
    IMAGE_ICON_ARRAY[3]=new ImageIcon("green.png").getImage();
    IMAGE_ICON_ARRAY[4]=new ImageIcon("yellow.png").getImage();
    IMAGE_ICON_ARRAY[5]=new ImageIcon("cursor.png").getImage();
    
    int nextImage  = Random.nextInt(NUMBER_OF_IMAGES)
    g.drawImage(IMAGE_ICON_ARRAY[nextImage]);

Similar Threads

  1. A few java probs
    By Mezzie in forum New To Java
    Replies: 4
    Last Post: 06-11-2008, 07:59 AM

Posting Permissions

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