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 05-16-2008, 07:32 PM
Member
 
Join Date: May 2008
Posts: 22
amith is on a distinguished road
icon
JFrame q=new JFrame( " Game");
ImageIcon c=new ImageIcon("red.png");
ImageIcon d=new ImageIcon("blue.png");
JLabel l= new JLabel(c);
JLabel j=new JLabel(d);
l.setBounds(50,50,90,50);
j.setBounds(100,50,90,50);
q.getContentPane().add(l);
q.getContentPane().add(j);
q.setVisible(true);
i just place in main it is executing correctly but i just want to get "red.png" (x,y,width,height) does there is any method AND also i just want to generate these icons in random order but how there are named as c,d how can i generate them
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-16-2008, 08:34 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,022
hardwired is on a distinguished road
Code:
import java.awt.*; import java.awt.image.BufferedImage; import java.util.Random; import javax.swing.*; public class RandomImagesTest2 { BufferedImage[] images; Random seed = new Random(); JLabel left; JLabel right; RandomImagesTest2() { makeImages(); new Thread(runner).start(); } private Runnable runner = new Runnable() { long delay = 1000; boolean animate = true; boolean firstTime = true; public void run() { while(animate) { try { Thread.sleep(delay); } catch(InterruptedException e) { animate = false; } left.setIcon(getIcon()); right.setIcon(getIcon()); if(firstTime && left.isVisible()) { Rectangle rL = left.getBounds(); Rectangle rR = right.getBounds(); System.out.printf("leftBounds = [%d, %d, %d, %d] " + "rightBounds = [%d, %d, %d, %d]%n", rL.x, rL.y, rL.width, rL.height, rR.x, rR.y, rR.width, rR.height); firstTime = false; } left.repaint(); right.repaint(); } } }; private void makeImages() { int alpha = 140; Color[] colors = { new Color(255, 0, 0, alpha), new Color(0, 0, 255, alpha) }; int w = 90, h = 50; int type = BufferedImage.TYPE_INT_ARGB; images = new BufferedImage[colors.length]; for(int i = 0; i < images.length; i++) { images[i] = new BufferedImage(w, h, type); Graphics2D g2 = images[i].createGraphics(); g2.setBackground(colors[i]); g2.clearRect(0,0,w,h); g2.dispose(); } } private JPanel getContent() { left = new JLabel(getIcon(), JLabel.CENTER); right = new JLabel(getIcon(), JLabel.CENTER); JPanel panel = new JPanel(null); panel.add(left); panel.add(right); left.setBounds(50,50,90,50); right.setBounds(100,50,90,50); return panel; } private ImageIcon getIcon() { int n = seed.nextInt(images.length); return new ImageIcon(images[n]); } public static void main(String[] args) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(new RandomImagesTest2().getContent()); f.setSize(300,300); f.setLocation(200,200); f.setVisible(true); } }
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
How to change Window Icon sharafat AWT / Swing 6 02-10-2008 07:13 AM
Changing icon of JOptionPane mew New To Java 3 12-21-2007 08:01 AM
How to set an Icon in a Label? Soda New To Java 2 12-07-2007 01:38 PM
how to remove an image icon cecily Advanced Java 1 08-05-2007 05:25 AM
To add an icon to my project Albert AWT / Swing 1 07-13-2007 04:14 PM


All times are GMT +3. The time now is 01:08 PM.


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