imageicon

Java Swing ImageIcon, where to put images?

六月ゝ 毕业季﹏ 提交于 2020-01-09 11:07:46
问题 I'm following this tutorial for java swing games: http://zetcode.com/tutorials/javagamestutorial/movingsprites/ At this point: ImageIcon ii = new ImageIcon(this.getClass().getResource()); image = ii.getImage(); I just don't know what kind of path I have to write and where should I save my images (which directory). Would you help me please? Would you give an example? 回答1: In your src folder, create a folder called "images" or "files" then put the image in there. Then use this: ImageIcon(this

Updating JButton on a timer in a do-while loop

一个人想着一个人 提交于 2020-01-08 18:03:47
问题 I'm having some trouble getting a JButton to update repeatedly (used with a timer) in a do-while loop. I'm working on a simple game, played on a 10 * 10 grid of tile objects which correspond to a JButton arrayList with 100 buttons. This part of the program handles simple pathfinding (i.e. if I click on character, then an empty tile, the character will move through each tile on its way to the destination). There is a delay between each step so the user can see the character's progress. In the

Updating JButton on a timer in a do-while loop

孤街醉人 提交于 2020-01-08 18:03:07
问题 I'm having some trouble getting a JButton to update repeatedly (used with a timer) in a do-while loop. I'm working on a simple game, played on a 10 * 10 grid of tile objects which correspond to a JButton arrayList with 100 buttons. This part of the program handles simple pathfinding (i.e. if I click on character, then an empty tile, the character will move through each tile on its way to the destination). There is a delay between each step so the user can see the character's progress. In the

Updating JButton on a timer in a do-while loop

匆匆过客 提交于 2020-01-08 18:03:02
问题 I'm having some trouble getting a JButton to update repeatedly (used with a timer) in a do-while loop. I'm working on a simple game, played on a 10 * 10 grid of tile objects which correspond to a JButton arrayList with 100 buttons. This part of the program handles simple pathfinding (i.e. if I click on character, then an empty tile, the character will move through each tile on its way to the destination). There is a delay between each step so the user can see the character's progress. In the

How to reference a local image in java?

孤者浪人 提交于 2020-01-05 13:08:27
问题 jLabel5.setIcon(new javax.swing.ImageIcon("./i/login.png")); I'm trying to reference that image. The path is correct, and the image actually exists. When I use the full path (I.E. "C:/ blah blah" it works, but this doesn't? The image folder is in the bin folder. 回答1: //This will retuns the URL of the image file inside your project this.getClass().getResource("/i/login.png"); So, your code will be : URL imageUrl = this.getClass().getResource("/i/login.png"); jLabel5.setIcon(new javax.swing

change pictures every 2 sec

别等时光非礼了梦想. 提交于 2020-01-04 04:24:33
问题 I stack a bit so if anyone has any ideas it would be helpful. So currently the program is compiling and running but I do not know how to finish it. I am using eclipse. What i want to do is when i start the program to change 4 different pictures in every 2 seconds so if you have any advices do not be shy. Here is the program. /** Here is the GUI of the program * class name SlideShowGui.java * @author Kiril Anastasov * @date 07/03/2012 */ import java.awt.*; import java.awt.event.ActionEvent;

Overlay a JButton over JLabel in Java Swing?

爱⌒轻易说出口 提交于 2020-01-03 11:47:07
问题 Is it possible to overlay a Button over a Label in Swing? For example, if have a JLabel with image and no text, and i want to overlay my button over this JLabel. Label is defined something like: myLabel = new javax.swing.JLabel(new ImageIcon( myPicture )); If not, then any ideas how can i realize this, thank you. EDIT: Actually i read about adding JPanel to a JLabel, when i add a Panel with button layout, it compiles fine but nothing is visible, just the JLabel with image UPDATE: As suggested

Overlay a JButton over JLabel in Java Swing?

淺唱寂寞╮ 提交于 2020-01-03 11:47:07
问题 Is it possible to overlay a Button over a Label in Swing? For example, if have a JLabel with image and no text, and i want to overlay my button over this JLabel. Label is defined something like: myLabel = new javax.swing.JLabel(new ImageIcon( myPicture )); If not, then any ideas how can i realize this, thank you. EDIT: Actually i read about adding JPanel to a JLabel, when i add a Panel with button layout, it compiles fine but nothing is visible, just the JLabel with image UPDATE: As suggested

Java - Draw text in the center of an image

夙愿已清 提交于 2020-01-02 04:08:19
问题 I need to write text in the center of an image. The text to write is not always the same. The code I'm using is here: // Here I first draw the image g.drawImage(img, 22, 15, 280, 225, null); // I get the text String text = photoText.getText(); // Set the text color to black g.setColor(Color.black); // I draw the string g.drawString(text, 79.5F, 220.0F); The problem is that the text isn't at the center of the image, what can I do? I only need to draw the text at the horizontal center. 回答1:

Get other application icon image in my Application

感情迁移 提交于 2020-01-01 16:45:10
问题 In my application, I am showing some applications list which are on app store. I want to get those application's icon image in my application. I just search but not getting any relevant post on this. Is there any way to get it? Apple allows to get? Please suggest if there is any way. Thanks for the help. 回答1: apple has an JSON Service for that, where you get a lot of meta data for every application This is the URL for the Facebook App http://itunes.apple.com/lookup?id=284882215 and this a the