| | |
Eclipse IDE and GiF Files
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Nov 2008
Posts: 25
Reputation:
Solved Threads: 0
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.
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.
•
•
Join Date: Nov 2007
Posts: 16
Reputation:
Solved Threads: 1
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
File f = new File(".");
f.getCanonicalPath(); //gives you the current path
![]() |
Similar Threads
- Help with automatic update problem and more (Viruses, Spyware and other Nasties)
Other Threads in the Java Forum
- Previous Thread: Java tictactoe
- Next Thread: Compressing image
| Thread Tools | Search this Thread |
Tag cloud for Java
actionlistener android api apple applet application apps arguments array arrays automation balls binary bluetooth card chat class classes client code component consumer database draw eclipse ee error event exception file fractal free game gameprogramming gis givemetehcodez graphics gui helpwithhomework html ide image input integer j2me j2seprojects java javaprojects jmf jni jpanel julia jvm linux list loop machine map method methods migrate mobile mobiledevelopmentcreatejar myaggfun netbeans newbie nextline nls notdisplaying number oracle print problem program programming project recursion recursive scanner screen security server set size sms socket sort spamblocker sql sqlite string sun swing terminal test threads time tree trolltech windows






