![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
King of Portal
|
I have the following line of code in a class named TestGUI:
frame.setIconImage(Toolkit.getDefaultToolkit().createImage("images/grimserve.gif"));
__________________
Lo, there do I see my father. 'Lo, there do I see My mother, and my sisters, and my brothers. 'Lo, there do I see The line of my people... Back to the beginning. 'Lo, they do call to me. They bid me take my place among them. In the halls of Valhalla... Where the brave... May live... ...forever.. GrimBB | Mimesis |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
Join Date: Oct 2005
Posts: 134
Rep Power: 4
![]() |
If the "images" directory is in the top-level directory of the jar:
InputStream stream = getClass().getResourceAsStream("/images/grimserve.gif");Then, read the entire input stream into a byte array and pass that array to createImage(). If you remove the beginning "/", it'll treat the path as a relative path from the directory of the current class file. For more info on getResourceAsStream: http://www.javaworld.com/javaworld/j...-property.html |
|
|
|
|
|
#3 |
|
Hobbyist Programmer
Join Date: Apr 2006
Posts: 136
Rep Power: 0
![]() |
you must have the folder "images" in the same directory as the Jar file. Try changing the directory by just making the image the same place as the Jar.
Maybe that will help |
|
|
|
|
|
#4 |
|
King of Portal
|
I apologize, this whole getResource stuff is very cryptic to me and I read the javaworld tutorial/explanation you posted there Kaja Fumei, but had no luck understand it. I get lost in all the technical jargon. So I'm just going to show you what I'm working with.
Here is the full code of the program: import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.swing.*;
import java.awt.geom.*;
public class CBZGUI
{
private static void createAndShowGUI()
{
JFrame frame = new JFrame("GrimServe");
// BufferedImage icon = new BufferedImage(32, 32, BufferedImage.TYPE_INT_ARGB);
// Graphics2D g2 = icon.createGraphics();
// g2.setColor(new Color(0, 0, 0));
// g2.draw(new Line2D.Double(0, 0, 32, 32));
// frame.setIconImage(icon);
frame.setIconImage(Toolkit.getDefaultToolkit().createImage("images/grimserve.gif"));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
DisplayPanel dispPanel = new DisplayPanel();
frame.setContentPane(dispPanel);
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args)
{
javax.swing.SwingUtilities.invokeLater
(
new Runnable()
{
public void run()
{
createAndShowGUI();
}
}
);
}
}
class DisplayPanel extends JPanel implements KeyListener
{
public DisplayPanel()
{
setLayout(new BorderLayout());
textArea.setEditable(false);
JScrollPane scrollPane = new JScrollPane(textArea);
textArea.setToolTipText("GrimServe console display.");
textField.setToolTipText("GrimServe command input.");
textField.setFocusTraversalKeysEnabled(false);
textField.addKeyListener(this);
textArea.setText("-=GrimServe 2.0=-\n");
add(scrollPane, BorderLayout.CENTER);
add(textField, BorderLayout.SOUTH);
}
public void keyPressed(KeyEvent e)
{
// Enter key
if(e.getKeyCode() == 10)
{
textArea.append(textField.getText() + "\n");
textField.setText("");
}
}
public void keyReleased(KeyEvent e){}
public void keyTyped(KeyEvent e) {}
final JTextArea textArea = new JTextArea(15, 45);
final JTextField textField = new JTextField();
}META-INF/MANIFEST.MF CBZGUI$1.class CBZGUI.class DisplayPanel.class images/grimserve.gif
__________________
Lo, there do I see my father. 'Lo, there do I see My mother, and my sisters, and my brothers. 'Lo, there do I see The line of my people... Back to the beginning. 'Lo, they do call to me. They bid me take my place among them. In the halls of Valhalla... Where the brave... May live... ...forever.. GrimBB | Mimesis |
|
|
|
|
|
#5 |
|
Hobbyist Programmer
Join Date: Oct 2005
Posts: 134
Rep Power: 4
![]() |
getResourceAsStream is just a method primarily used for reading files stored inside the current jar.
long length = 1024; // change to the size in bytes of the actual gif
byte[] gif = new byte[length];
InputStream stream = getClass().getResourceAsStream("/images/grimserve.gif");
stream.read(gif);
frame.setIconImage(Toolkit.getDefaultToolkit().createImage(gif));There may be a simpler way of building an image from the InputStream but I'm not very familiar with the java GUI packages. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| OnlineTextEditor.Com! | Sane | Show Off Your Open Source Projects | 43 | Jun 16th, 2006 9:55 AM |
| Problem with file and array | Marek | C | 9 | Dec 28th, 2005 11:03 AM |
| Open File Problem :( | Silent | Visual Basic .NET | 17 | Dec 5th, 2005 3:30 AM |
| After execution - Error cannot locate /Skin File? | wchar | Visual Basic | 1 | Mar 5th, 2005 10:04 PM |
| airport Log program using 3D linked List : problem reading from file | gemini_shooter | C++ | 0 | Mar 2nd, 2005 5:12 PM |