embedded-resource

Using Font from my JAR

99封情书 提交于 2020-01-16 19:03:27
问题 I have added a font to my JAR file from eclipse and am trying to use the font within JTextFields. The setText isn't being drawn when I run the application, just a - in the JTextField. I based my code off Exporting font to jar in eclipse. Below is my code: //lets load the font Font font = Font.createFont(Font.TRUETYPE_FONT, Main.class.getClassLoader().getResourceAsStream("Coalition_v2.ttf")); font.deriveFont(Font.PLAIN, 14); txtBrain = new JTextField(); txtBrain.setFont(font); txtBrain.setText

Loading images in a jar

ぐ巨炮叔叔 提交于 2020-01-16 18:19:31
问题 I am using eclipse and I use the following code to load my image from a folder. getClass().getResource("/images/image.jpg").getFile()) The image folder is located inside the bin folder in the project folder. It works fine when loading in eclipse, but when I export it to a jar it does not load. I have tried puting the image folder in all possible places in the jar, but it does not. How do I load an image folder in a jar? 回答1: You can use getResourceAsStream() method instead to get InputStream

Cannot read an image in jar file

て烟熏妆下的殇ゞ 提交于 2020-01-15 08:15:52
问题 when i build a jar file and run it ,it shows a null pointer exception due to imageicon not found new ImageIcon(getClass().getClassLoader().getResource("icons/exit.png"))); this is the error what i get when i run the jar file Exception in thread "main" java.lang.NullPointerException at javax.swing.ImageIcon.<init>(Unknown Source) at mediaplayer.MediaPlayer.buildtoolbar(MediaPlayer.java:130) at mediaplayer.MediaPlayer.<init>(MediaPlayer.java:81) at mediaplayer.MediaPlayer.main(MediaPlayer.java

FindResource works, LoadBitmap doesn't, LoadImage from disk works

时光毁灭记忆、已成空白 提交于 2020-01-14 14:55:26
问题 I am trying to use LoadBitmap to load an image from a resource file. I've verified that the resource is linked correctly -- examining the final EXE with a hex editor shows that the bitmap is packed inside the EXE correctly. I've also verified that the bitmap is valid -- using LoadImage with LR_LOADFROMFILE to load the bitmap from disk at runtime works fine and I see it appear when I add it to a gui element later. I've verified that the ID that I use to access the resource is valid as well --

How do I access resources in a console application?

百般思念 提交于 2020-01-14 10:43:34
问题 How do I gain access to .Properties.Resources in a console application? This is to use resource files attached to the solution. Here's exactly what I can see: The first syntax error isn't the one I'm concerned with ( Only assignment, call, increment, decrement, and new object expressions can be used as a statement ). The one that I'm trying to fix is the second: The name 'Properties' does not exist in the current context 回答1: Edited answer (after your edit): You don't have resources. Right

Using embedded resources in C# console application

[亡魂溺海] 提交于 2020-01-14 07:18:06
问题 I'm trying to embed an XML file into a C# console application via Right clicking on file -> Build Action -> Embedded Resource. How do I then access this embedded resource? XDocument XMLDoc = XDocument.Load(???); Edit: Hi all, despite all the bashing this question received, here's an update. I managed to get it working by using XDocument.Load(new System.IO.StreamReader(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("Namespace.FolderName.FileName.Extension"))) It

Java Exception Reading Stream from Resource .wav

情到浓时终转凉″ 提交于 2020-01-13 18:26:29
问题 I guess my code is okay, and my .jar file its okay with the .wav inside it.. But when I try to load it using getResourceAsStream I get a error.. this is my error: java.io.IOException: mark/reset not supported at java.util.zip.InflaterInputStream.reset(Unknown Source) at java.io.FilterInputStream.reset(Unknown Source) at com.sun.media.sound.SoftMidiAudioFileReader.getAudioInputStream(Unkno wn Source) at javax.sound.sampled.AudioSystem.getAudioInputStream(Unknown Source) at operation

How to Play .wav File with JButton?

梦想与她 提交于 2020-01-11 13:59:11
问题 So recently, I have been trying to make my own Mario game (for myself, possibly to show my other friends). Games include buttons. When I click on a button in other games, it plays a sound. I would love to add that feature to my game. The problem is, it doesn't play. My source code is: import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import javax.sound.sampled.AudioInputStream; import javax.sound.sampled.AudioSystem; import javax.sound.sampled.Clip;

Where have I to put an image to use it to create a new Swing ImageIcon object?

我怕爱的太早我们不能终老 提交于 2020-01-11 12:05:14
问题 I am studying Java Swing library and I have a problem. In an example program it create an ImageIcon object by this line: ImageIcon icon = new ImageIcon(getClass().getResource("exit.png")); Whe I execute my program I obtain the following error caused by the fact that in the project the exit.png is missing: Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at javax.swing.ImageIcon.<init>(ImageIcon.java:205) at com.andrea.second.SimpleMenu.initUI(SimpleMenu.java:23) at com

Packaging a program containing images

一曲冷凌霜 提交于 2020-01-11 10:26:26
问题 I'm having massive issues packaging my java program which contains images into a jar for conversion into and executable file. The images have been used in the background of the program and buttons. Please see the diagram below which shows the program I desire to convert to a jar. IMAGE As you see above the program runs OK. I created the same program with no custom background and custom buttons containing no images and I successfully packaged it into a jar and subsequently into an .exe file.