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, 06:14 AM
Member
 
Join Date: May 2008
Posts: 7
deathnote11 is on a distinguished road
Picture help
Hi I've been having a problem getting pictures to overlap eachother
lets say i have 2 pictures 1 is the background, and the other is the person
How do I place both pictures on the same spot while being able to see the person infront of the background??

At the moment I've been trying to put imageicons into a JLabel..but that doesn't seem to work properly.

Thanks a lot!
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-16-2008, 06:30 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,532
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
The way you tried is ok. Use JLabel for that. What you have done up to now and what you get there.


__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
(Close on July 27, 2008)
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 05-16-2008, 06:45 AM
Member
 
Join Date: May 2008
Posts: 7
deathnote11 is on a distinguished road
the thing is I tried using 2 panels and have the 2 labels at the same spot..
but they just overlap eachother and I can't make the one on top visible
I went browsing a bit, and it talked about RootPanes and Glasspanes Im not sure if that will help though...
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 05-16-2008, 06:49 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,532
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Using GlassPanes you can do it.

Basically what you want to do is, on a frame you have a background image. It covered full area of the frame. Part of that you want to add an image. Am I correct?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
(Close on July 27, 2008)
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 05-16-2008, 06:52 AM
Member
 
Join Date: May 2008
Posts: 7
deathnote11 is on a distinguished road
Okay well, you know DDR? (dance dance revolution)
kinda like this:

FFR The Game FlashFlashRevolution.com

Im trying to get the arrows go under the 'top' arrows
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 05-16-2008, 07:08 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,532
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
There all going on flash.

To do this on Java, better to check on GlassPane. I think it's possible. But I never do such thing before. Better to check that moving arrow is possible on GlassPane.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
(Close on July 27, 2008)
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 05-16-2008, 07:10 AM
Member
 
Join Date: May 2008
Posts: 7
deathnote11 is on a distinguished road
I'm not sure, but could it be possible to
paint an image and then setting it on a Jframe using X and Y coordinates?
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 05-16-2008, 07:16 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,532
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Using x,y coordinates it's possible to set an image in a JFrame. Using swing timer you can move the image. I'm worried about the transparent look of images as your link shows.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
(Close on July 27, 2008)
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 05-16-2008, 07:43 AM
Member
 
Join Date: May 2008
Posts: 7
deathnote11 is on a distinguished road
if I want to use the X Y coordinate method how would I do that?
would I first add the JLabel into the frame, and then use Jlabel.setLocation(x, y)?
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 05-16-2008, 07:51 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,532
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
The best way is this. Add a panel on to the frame first. Because it's the container most of the time use. Much easy to work with.

Then add your image to the label and set the label location as you said. I think it's clear to you.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
(Close on July 27, 2008)
Bookmark Post in Technorati
Reply With Quote
  #11 (permalink)  
Old 05-16-2008, 05:51 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,027
hardwired is on a distinguished road
Code:
import java.awt.*; import java.awt.image.BufferedImage; import java.io.*; import javax.imageio.ImageIO; import javax.swing.*; public class OverlappingImages extends JPanel { BufferedImage bgImage; BufferedImage fgImage; OverlappingImages(BufferedImage[] images) { bgImage = images[0]; fgImage = images[1]; } protected void paintComponent(Graphics g) { super.paintComponent(g); int x = 100; int y = 100; g.drawImage(bgImage, x, y, this); x = 150; y = 150; g.drawImage(fgImage, x, y, this); } public static void main(String[] args) throws IOException { String[] ids = { "--g--", "---h-" }; String prefix = "images/geek/geek"; String ext = ".gif"; BufferedImage[] images = new BufferedImage[ids.length]; for(int i = 0; i < images.length; i++) { String path = prefix + ids[i] + ext; images[i] = ImageIO.read(new File(path)); } OverlappingImages test = new OverlappingImages(images); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(test); f.setSize(300,300); f.setVisible(true); } }
Bookmark Post in Technorati
Reply With Quote
  #12 (permalink)  
Old 05-20-2008, 05:09 PM
Member
 
Join Date: May 2008
Posts: 7
deathnote11 is on a distinguished road
wow thanks it works!
but how would I call the paint componet method again?
I'm not sure how the method can pass a parameter to itself...
How can graphics g be passed by the method..inside the method?
thanks
Bookmark Post in Technorati
Reply With Quote
  #13 (permalink)  
Old 05-20-2008, 07:41 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,027
hardwired is on a distinguished road
The proper way to "call" painting methods is to tell the enclosing class to repaint. For this to work then you must make changes to member variable in the class to control what/how you want the painting behavior to be. You can change the images or use boolean flags to control which images are displayed. The graphics component paints itself acccording the the state which are member variables used to control what happens in the method. Swing handles everything with the graphics context, g.
Bookmark Post in Technorati
Reply With Quote
  #14 (permalink)  
Old 06-03-2008, 06:46 PM
Member
 
Join Date: May 2008
Posts: 7
deathnote11 is on a distinguished road
Okay So, I've managed to get it to work, but then sometimes
it doesn't create the images smoothly..
What can I do to make it produce the pictures smoothly?
Code:
import java.awt.*; import java.awt.image.BufferedImage; import java.io.*; import javax.imageio.ImageIO; import javax.swing.*; import java.lang.*; import java.util.Timer; import java.util.TimerTask; import java.awt.event.*; //action listener. import java.util.*; class DdrJ implements ActionListener, KeyListener { int depth=1; ArrayList Alist = new ArrayList() ImageIcon bgIMAGE = new ImageIcon (getClass().getResource("test2G.gif")); ImageIcon p4IMAGE = new ImageIcon(getClass().getResource("p4.gif")); ImageIcon p4ModIMAGE = new ImageIcon(getClass().getResource("p4Mod.gif")); JLabel bgL ; int x; int y; APane pane; JButton btn2 = new JButton("coordinates"); public static void main(String[] args) { new DdrJ(); } DdrJ() { x=10; y=10; JFrame gameFrame = new JFrame("DdrJ"); pane = new APane(x, y, new JLabel( new ImageIcon(getClass().getResource("p4.gif"))) ); gameFrame.setContentPane(pane); pane.setLayout(null); Insets insets = pane.getInsets(); //backgroudn pic and size JLabel bgL = new JLabel(bgIMAGE,new Integer(0)); Dimension bgSIZE = bgL.getPreferredSize(); //region pic and size JLabel regL = new JLabel(p4ModIMAGE,new Integer(10)); Dimension regSIZE = regL.getPreferredSize(); //set where it is regL.setBounds(300,300+insets.top,regSIZE.width,regSIZE.height); bgL.setBounds(0+insets.left,0+insets.top,bgSIZE.width,bgSIZE.height); pane.add(bgL, new Integer(0)); pane.add(regL,new Integer(1)); // label = new JLabel(image); // label2 = new JLabel( new ImageIcon(getClass().getResource("test1G.gif") ) ); gameFrame.addKeyListener(this); pane.addKeyListener(this); gameFrame.setSize(500,500); gameFrame.setVisible(true); gameFrame.setSize(500,500); gameFrame.setVisible(true); for(int i=0;i<100;i++) { try { Thread.sleep(500); make(); } catch(Exception w) { } } pane.requestFocus(); } public void keyTyped ( KeyEvent p ) { } public void keyPressed ( KeyEvent p) { if(p.getKeyCode()==KeyEvent.VK_UP) { try { } catch(Exception m) { } for(int i=0;i<Alist.size();i++) { if( ((UP)(Alist.get(i) ) ).getY()>=250 ) { System.out.println("________________________"); if( ((UP)(Alist.get(i))).getY() >=260 && ((UP)(Alist.get(i))).getY()<=290 ) { System.out.println("Too early"); ( (UP)Alist.get(i) ).quick(); ( (UP)Alist.get(i) ).stop(); Alist.remove(i); } else if( ((UP)(Alist.get(i))).getY() >=290 && ((UP)(Alist.get(i))).getY()<=300 ) { System.out.println("Hit right on"); ( (UP)Alist.get(i) ).quick(); ( (UP)Alist.get(i) ).stop(); Alist.remove(i); } else if( ((UP)(Alist.get(i))).getY() >=300 && ((UP)(Alist.get(i))).getY()<=320 ) { System.out.println("A little too late"); ( (UP)Alist.get(i) ).quick(); ( (UP)Alist.get(i) ).stop(); Alist.remove(i); } } if( ((UP)(Alist.get(i) ) ).getY()>=500 ) { ( (UP)Alist.get(i) ).quick(); ( (UP)Alist.get(i) ).stop(); Alist.remove(i); } System.out.println(Alist.size()); } } } public void keyReleased ( KeyEvent p ) { } public void make() { try { pane.labChng( new JLabel(new ImageIcon(getClass().getResource("p4.gif")))); pane.add(pane.label,new Integer(depth)); UP arrow1 = new UP(pane); Alist.add(arrow1); ( (UP)Alist.get(Alist.size()-1) ).start(); depth++; } catch(Exception ex) { } pane.requestFocus(); } public void actionPerformed(ActionEvent e) { pane.requestFocus(); } } class APane extends JLayeredPane { int x=500; int y=250; JLabel label; APane(int x, int y, JLabel label) { this.x=x; this.y=y; this.label=label; } public void labChng(JLabel lab) { this.label=lab; } } class UP extends Thread { APane pane; UP(APane pane) { pane = new APane(pane.x,pane.y,pane.label); this.pane=pane; } public void run() { try { while(pane.y<400) { move(10); } } catch(Exception ex) { } quick(); stop(); System.gc(); } void move(int delay) throws InterruptedException { Thread.currentThread().sleep(delay); Insets insets=pane.getInsets(); Dimension size = pane.label.getPreferredSize(); pane.y++; pane.label.setBounds(300,pane.y+insets.top,size.width,size.height); } public void quick() { pane.label.setIcon(null); } public int getY() { return pane.y; } }

Thanks!
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
Picture in a JFrame problem saytri New To Java 3 01-12-2008 10:44 AM
Print a picture file oli001 New To Java 0 11-26-2007 02:40 PM
how to import a picture into an applet cecily Java Applets 1 08-03-2007 10:51 PM


All times are GMT +3. The time now is 07:06 AM.


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