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-27-2008, 12:00 PM
Member
 
Join Date: May 2008
Posts: 22
amith is on a distinguished road
images
import java.awt.*;
import javax.swing.*;
class d extends JComponent implements Runnable
{
private Image r;
private Image g;
int x=0;
long floor=329;
boolean t=true;

public void run()
{
r=new ImageIcon("red.png").getImage();
g=new ImageIcon("red.png").getImage();
try
{
while(t)
{
repaint();
x++;
if(x==floor)
{
t=false;

q.drawImage(g,229,x-32,this);

}
Thread.sleep(20);
}}catch(Exception e)
{
}
}
public void paint(Graphics q)
{
q.drawImage(r,229,x,this);


}}
class f
{
public static void main(String args[])
{
d v=new d();
JFrame b=new JFrame("sdfdsf");
b.getContentPane().add(v);
b.setVisible(true);
b.setSize(300,400);
(new Thread(v)).start();
}
}

i just want ot place this images one by one i just wnat ot make fist image newfloor so that other image can lie on the top of the other image
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 06-27-2008, 05:40 PM
Member
 
Join Date: May 2008
Posts: 22
amith is on a distinguished road
images building
i am having five off screen images i had load it with the help of Imageicon class and i had drawn it using paint method
i just want the images to be placed on the top of each one in vertical format like a building using threads
could u plz help with this code and and each image width and height is of 32*32

import java.awt.*;
import javax.swing.*;
class d extends JComponent implements Runnable
{
Image r;
Image g;
Image n;
Image t;
int x=0;
long floor=329;

public void run()
{

r=new ImageIcon("1.png").getImage();
g=new ImageIcon("2.png").getImage();
n=new ImageIcon("3.png").getImage();
t=new ImageIcon("4.png").getImage();
try
{
while(x!=floor)
{x++;
repaint();
Thread.sleep(10);

}

}
catch(Exception e)
{
}
}

public void paint(Graphics q)
{
q.drawImage(r,229,x,this);
}
}
class f
{
public static void main(String args[])
{
d v=new d();
JFrame b=new JFrame("sdfdsf");
b.getContentPane().add(v);
b.setVisible(true);
b.setSize(300,400);
(new Thread(v)).start();
}
}
if the code is incomplete then plz help iam stuck in this program
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 06-27-2008, 08:34 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,141
hardwired is on a distinguished road
To stack the images you don't need a thread/Runnable.
Main trouble was that the letters "g" and "q" got mixed up.
Code:
import java.awt.*; import javax.swing.*; class dRx extends JComponent { Image r; Image q; Image n; Image t; int x=0; long floor=329; public dRx() { r=new ImageIcon("1.png").getImage(); q=new ImageIcon("2.png").getImage(); n=new ImageIcon("3.png").getImage(); t=new ImageIcon("4.png").getImage(); /* String z = "images/geek/geek"; r=new ImageIcon(z+"-c---.gif").getImage(); q=new ImageIcon(z+"--g--.gif").getImage(); n=new ImageIcon(z+"---h-.gif").getImage(); t=new ImageIcon(z+"----t.gif").getImage(); */ } protected void paintComponent(Graphics g) { super.paintComponent(g); int y = getHeight() - r.getHeight(this); System.out.println("y = " + y); g.drawImage(r,x,y,this); y -= r.getHeight(this); g.drawImage(q,x,y,this); y -= q.getHeight(this); g.drawImage(n,x,y,this); y -= n.getHeight(this); g.drawImage(t,x,y,this); } public static void main(String[] args) { dRx v=new dRx(); JFrame b=new JFrame("sdfdsf"); b.getContentPane().add(v); b.setSize(300,400); b.setVisible(true); } }
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 06-27-2008, 09:38 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: SW MO, USA
Posts: 928
Norm is on a distinguished road
General commet on your coding style.

Using single letters for variable makes it very hard to understand the logic of the program. Please take the time to think what a variable is used for and give it a descriptive name.
Personally I wouldn't bother trying to solve problems with this code as its too hard to follow what you are trying to do.

Another useful coding technique is to place comments in the code to describe what it is you are trying to do. Again, this code is void of comments.
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
XML Images JavaWizz XML 0 06-13-2008 04:07 AM
images amith AWT / Swing 1 05-20-2008 11:54 AM
Help using images in Java toby Advanced Java 1 08-07-2007 06:54 AM
Help with images... toby Java Applets 1 08-04-2007 06:25 AM
Images in JSP Daniel JavaServer Pages (JSP) and JSTL 1 06-05-2007 07:01 AM


All times are GMT +3. The time now is 12:44 PM.


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