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 07-05-2008, 05:48 PM
Member
 
Join Date: May 2008
Posts: 22
amith is on a distinguished road
adding thread
i sincerely apologize for asking this question again and i am stuck by this program for past 3 days this time i am sending the .gif file so that u can easily understand what my idea is
here is the code
as u see in the picture the red image is fixed and yellow is sliding from top to bottom i can't make it out when i run the only one image is visible either red is fixed visible or yellow sliding from top is visible i just want two image as shown in picture
Code:
import java.util.*; import java.awt.*; import javax.swing.*; class load extends JFrame { Image r; Image ye; int y=329; int floor=329; int x=3; load() { super("some name"); r=new ImageIcon("red.png").getImage(); ye=new ImageIcon("yellow.png").getImage(); getContentPane().add(new display()); setVisible(true); setSize(175,400); setResizable(false); } class display extends JPanel //implements Runnable { //Thread t=new Thread(this); display() { repaint(); } public void paintComponent(Graphics q) { Graphics2D n=(Graphics2D)q; q.drawImage(r,x,y,this); } /* i just want to place the red image fixed at the bottom and start new yellow image thread i,e try { y=0; while(y!=floor) { y++; q.drawImage(b,x,y,this); Thread.sleep(10); } } catch(Exception e) { } */ } } class f { public static void main(String args[]) { new load(); } }
Attached Images
File Type: gif a.gif (16.7 KB, 12 views)
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-05-2008, 07:16 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: SW MO, USA
Posts: 1,616
Norm is on a distinguished road
Please repost the code for this question using the CODE tags to preserve indentation - to make it easier to read your code.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-05-2008, 08:07 PM
Senior Member
 
Join Date: Jun 2008
Posts: 462
Fubarable is on a distinguished road
Please at least delete the text in your other posts.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 07-05-2008, 10:10 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,189
hardwired is on a distinguished road
Code:
import java.util.*; import java.awt.*; import javax.swing.*; class LoadRx extends JFrame { Image red; Image yellow; int y=329; int floor=329; int x=3; int yLoc = 0; LoadRx() { super("some name"); red=new ImageIcon("red.png").getImage(); //"images/geek/geek--g--.gif").getImage(); yellow=new ImageIcon("yellow.png").getImage(); //"images/geek/geek---h-.gif").getImage(); getContentPane().add(new DisplayPanel()); // setVisible(true); setSize(175,400); // setResizable(false); // This should always be the last call. setVisible(true); } class DisplayPanel extends JPanel implements Runnable { DisplayPanel() { Thread t=new Thread(this); // To keep your gui responsive to user input. t.setPriority(Thread.NORM_PRIORITY); t.start(); } // Java wil be easier to learn if you will copy // these method signatures exactly as shown in // the javadocs. There is still plenty of room // to do things your way, eg, giving meaningful, // descriptive, verbose names to your variables. protected void paintComponent(Graphics g) { // Eliminate artifacts: super.paintComponent(g); // This cast not necessary here, but okay. //Graphics2D g2=(Graphics2D)g; // Draw fixed-location image: g.drawImage(red, x, y, this); // Draw moving image: // "yLoc" is controlled from within your // event code, here, the run method // of your Runnable. g.drawImage(yellow, x, yLoc, this); } // i just want to place the red image fixed at the bottom // and start new yellow image thread i,e // This is the implementation of the Runnable interface. // In java, when you implement an interface you must // provide an implementation of every method defined // in the interface. Runnable has a single method: [i]run{/i]. public void run() { // This resets your member variable "y" to zero. // You want it to be left alone so it will show // "red" at the bottom of the component. You could // reset the member variable "yLoc" here if you are // going to do multiple runs through this method. // y=0; while(yLoc != floor) { // The variable "y" was/is used to position "red". // If you change it here you will reposition "red". // y++; // Solution: use a different variable to locate "yellow". yLoc++; // Show the new location of "yellow". repaint(); try { // Draw only in paintComponent. // Adjust variables here in event code. // q.drawImage(b,x,y,this); Thread.sleep(50); } catch(InterruptedException e) { break; // get out of this while loop } } } } public static void main(String[] args) { new LoadRx(); } }
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
adding thread amith Java 2D 0 07-05-2008 05:44 PM
adding thread amith Java 2D 0 07-05-2008 05:33 PM
adding thread amith Java 2D 0 07-05-2008 05:31 PM
If JNI thread call the java object in another thread, it will crash. skaterxu Advanced Java 0 01-28-2008 08:02 AM
Creating a Thread (extending Java Thread Class) JavaForums Java Blogs 0 12-19-2007 10:31 AM


All times are GMT +3. The time now is 02:11 AM.


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