Eclipse IDE and GiF Files

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Nov 2008
Posts: 25
Reputation: curtissumpter is an unknown quantity at this point 
Solved Threads: 0
curtissumpter curtissumpter is offline Offline
Light Poster

Eclipse IDE and GiF Files

 
0
  #1
Feb 18th, 2009
Hi People,

I am trying to run this file but I am having trouble getting the program to incorporate the gif file that I need. Here's the program.

// Demonstrating JDesktopPane

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;

public class DesktopTest extends JFrame
{
public DesktopTest()
{
super("Using a JDesktopPane");

JMenuBar bar = new JMenuBar();
JMenu addMenu = new JMenu("Add");
JMenuItem newFrame = new JMenuItem("Internal Frame");
addMenu.add(newFrame);
bar.add(addMenu);
setJMenuBar(bar);

final JDesktopPane theDesktop = new JDesktopPane();
getContentPane().add(theDesktop);

newFrame.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
JInternalFrame frame = new JInternalFrame("Internal Frame", true, true, true, true);
Container c = frame.getContentPane();
MyJPanel panel = new MyJPanel();
c.add(panel, BorderLayout.CENTER);
frame.setSize(
panel.getImageWidthHeight().width,
panel.getImageWidthHeight().height);
frame.setOpaque(true);
theDesktop.add(frame);
}
}
);

setSize(500, 400);
setVisible(true);

addWindowListener(
new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
);
}

public static void main(String args[])
{
new DesktopTest();
}

class MyJPanel extends JPanel
{
private ImageIcon imgIcon;

public MyJPanel()
{
imgIcon = new ImageIcon("jhtp3.gif");
}

public void paintComponent(Graphics g)
{
imgIcon.paintIcon(this, g, 0, 0);
}

public Dimension getImageWidthHeight()
{
return new Dimension (imgIcon.getIconWidth(),
imgIcon.getIconHeight());
}
}
}

// Here is the location of the gif file.

// http://www.pkidd.com/556/EXAMPLES/ch26/images/
// the file is: jhtp3.gif

I am using the eclipse IDE.

I would like to continue using the Eclipse IDE.

My path is /Users/mariafpinheiro/Documents/workspace/exercises/Chapter_13_Advanced_GUI/Figure_13_10

Thanks.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 1,596
Reputation: BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all 
Solved Threads: 202
BestJewSinceJC BestJewSinceJC is online now Online
Posting Virtuoso

Re: Eclipse IDE and GiF Files

 
0
  #2
Feb 18th, 2009
if you just say

imgIcon = new ImageIcon("jhtp3.gif");

it's probably going to assume that jhtp3.gif is located somewhere under your current project. So download it and put it there, or at least download it to your computer and specify the pathname in your argument to ImageIcon.

Also, use code tags.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,477
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 514
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Eclipse IDE and GiF Files

 
0
  #3
Feb 18th, 2009
You may want to read through this section of the Sun tutorials:
Loading Images Using getResource.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 1,596
Reputation: BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all 
Solved Threads: 202
BestJewSinceJC BestJewSinceJC is online now Online
Posting Virtuoso

Re: Eclipse IDE and GiF Files

 
0
  #4
Feb 18th, 2009
Good point. You can also put it under the current project though, right? I seem to remember doing that a few times in the past and having no problems with it.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 25
Reputation: curtissumpter is an unknown quantity at this point 
Solved Threads: 0
curtissumpter curtissumpter is offline Offline
Light Poster

Re: Eclipse IDE and GiF Files

 
0
  #5
Feb 18th, 2009
Originally Posted by BestJewSinceJC View Post
Good point. You can also put it under the current project though, right? I seem to remember doing that a few times in the past and having no problems with it.

That doesn't work.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 16
Reputation: danielernesto is an unknown quantity at this point 
Solved Threads: 1
danielernesto danielernesto is offline Offline
Newbie Poster

Re: Eclipse IDE and GiF Files

 
0
  #6
Feb 19th, 2009
Did you try puttin the image in a local directory. for example in "/home/myImgage/jhtp3.gif" directly, becouse doing it the othre way will go until the current directory, or up to your classpath directory, also you can use creating a new object File, which can give you the current directory. And that can be very helpfull.

File f = new File(".");
f.getCanonicalPath(); //gives you the current path
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC