imageicon

Java ImageIcons and actioin listeners

夙愿已清 提交于 2019-11-29 17:01:12
I am creating a simple game where a person clicks on an image the score increases by one. It seems simple enough, right? Here's the catch-- the images will be hidden partially behind other images! Currently, I'm using several imageIcons to set up my scene. For instance, my foreground has an image "foreground.png," my background is "background.png", and my image that is hiding between the two is "hiding.png". My first thought was to simply get the coordinates of the imageIcon hiding, add the height() and width() to them, and create a mouse listener that would only work in that specified region.

MouseEvents and Icon / ImageIcon

廉价感情. 提交于 2019-11-29 15:45:25
Please is possible to listening for MouseEvents from Icon / ImageIcon (in API aren't implemented any notifiers), without listening from container ( JPanel , JLabel ) or by converting events by using SwingUtilities , implements and to add XxxListener to plain vanilla Icon / ImageIcon EDIT something like as code (@pietblok) , but maybe not an answer to my question, I'm not sure if create an Graphics Object, BufferedImage and paintIcon is last of property (I saw a few similair code, this is in SSCCE form) import java.awt.Color; import java.awt.Component; import java.awt.Graphics; import java.awt

Changing ImageIcon to another picture with button click

不羁的心 提交于 2019-11-29 11:14:35
So I want to replace an ImageIcon in a JLabel every time a button is pressed. I made it so the image, label, and GridBagConstraints are public. When I try to change it though nothing happens. Am I going about this the wrong way or? Thanks! package hi.low; import java.awt.*; import java.awt.event.*; import java.util.ArrayList; import javax.swing.*; import java.util.Random; import java.util.ArrayList; public class Card_panel extends JPanel implements ActionListener { private final int WIDTH = 400, HEIGHT = 200; private static String[] imageList = { "images/2h.png", "images/3h.png", "images/4h

Animated GIF on a JButton, play it when mouse is hovered

▼魔方 西西 提交于 2019-11-29 10:51:56
Icon icon = new ImageIcon(getClass().getResource( "/img/icon.gif" ) ); aButton = new JButton("Its a button", icon); Is there some kind of method that can stop an animated from playing? I was thinking of assigning a static jpg of the gif, then when I hover, assign the animated gif, but I don't think there is an event for taking off mouse in MouseMotionListener so I can load back the static jpg. The gif loops in the button, however, if I hover over it, it disappears. How can I make the gif static if my mouse cursor is not on the button? If I use MouseMotionListener , does it fire an event if I

Converting an ImageIcon to a BufferedImage

♀尐吖头ヾ 提交于 2019-11-29 03:59:09
I've been trying to convert a ImageIcon to BufferedImage ... And I've had no luck. I have a pre-existing ImageIcon that needs to be converted to a Buffered Image for the vast amount of BufferedImage operations that exist. I have found a few ways, but all of them are hugely CPU intensive. What's wrong with: BufferedImage bi = new BufferedImage( icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_RGB); Graphics g = bi.createGraphics(); // paint the Icon to the BufferedImage. icon.paintIcon(null, g, 0,0); g.dispose(); See ImageIcon , Image and BufferedImage : ImageIcon yourImage;

Java: Add Background image to frame [duplicate]

二次信任 提交于 2019-11-28 14:50:16
Possible Duplicate: java swing background image drawing your own buffered image on frame I am trying to add a back ground image to my frame, but nothing that I have done works. I designed a slot machine consisting of several panels added to the container. Now, I am trying to add a nice background to the frame. I tried using the paint method. But, since I am already using the paint method to paint the reel images, it is not working on the background. I also tried adding a JLabel, but when I do it overwrites everything or get overwritten depending on how I call it. Following is my code; any help

ImageIcon Help + Close a JOptionPane

筅森魡賤 提交于 2019-11-28 14:42:42
I'm trying to get the PayPal logo come up when you click the 'rightbutton' is clicked. Unfortunately, all that shows is the default Java logo with the cup of coffee and a pen. Also, how can I make it so once you click "OK" or "Cancel" it closes the JOptionPane, currently, when you click "OK" nothing happens, it keeps giving you the "OK" / "Cancel" option. rightbutton = new JButton("Right."); add(rightbutton); rightbutton.addActionListener( new ActionListener(){ public void actionPerformed(ActionEvent event){ //what do we want to happen when we //click the button final ImageIcon icon = new

how to auto change image in java swing?

安稳与你 提交于 2019-11-28 14:35:00
Hi i am creating a java desktop application where i want to show image and i want that all image should change in every 5 sec automatically i do not know how to do this here is my code public class ImageGallery extends JFrame { private ImageIcon myImage1 = new ImageIcon ("E:\\SOFTWARE\\TrainPIS\\res\\drawable\\yellow.png"); private ImageIcon myImage2 = new ImageIcon ("E:\\SOFTWARE\\TrainPIS\\res\\drawable\\d.jpg"); private ImageIcon myImage3 = new ImageIcon ("E:\\SOFTWARE\\TrainPIS\\res\\drawable\\e.jpg"); private ImageIcon myImage4 = new ImageIcon ("E:\\SOFTWARE\\TrainPIS\\res\\drawable\f.jpg

not redisplaying an image s

蹲街弑〆低调 提交于 2019-11-28 14:25:10
Hi everybody I am a bit of stack here. When I run the program and press the button submit it is supposed to change 4 pictures in every 2 seconds.However it is not redisplaying the images. If anyone can give me a hand it would be great. I am using eclipse and the program is compiling and running. Here is the code. /** 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; import java.awt.event.ActionListener; import javax.swing.*; public class SlideShowGui extends JPanel implements

Displaying an ImageIcon

女生的网名这么多〃 提交于 2019-11-28 14:03:58
I am trying to display an image on a JPanel . I'm using an ImageIcon for rendering the image, and the image is in the same directory as the class file. However, the image is not being displayed, and there are no errors occuring. Could anyone please assist in working out what's wrong with my code... package ev; import java.awt.Graphics; import javax.swing.ImageIcon; import javax.swing.JPanel; public class Image extends JPanel { ImageIcon image = new ImageIcon("peanut.jpg"); int x = 10; int y = 10; public void paintComponent(Graphics g) { super.paintComponent(g); image.paintIcon(this, g, x, y);