Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-29-2008, 03:14 PM
Member
 
Join Date: May 2008
Posts: 22
amith is on a distinguished road
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);
}
}
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 06-29-2008, 10:13 PM
Nicholas Jordan's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Southwest
Posts: 422
Nicholas Jordan is on a distinguished road
something like this, not necessarily exactly
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]);
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
A few java probs Mezzie New To Java 4 06-11-2008 08:59 AM


All times are GMT +3. The time now is 08:40 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org