imageicon

Updating JButton on a timer in a do-while loop

人走茶凉 提交于 2019-11-26 23:18:14
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 current state of things, the movement is correct, but the JButton is only updated when the character

Spring behavior simulation

£可爱£侵袭症+ 提交于 2019-11-26 23:06:47
Basically, i want to simulate spring behavior on painted image. I want to make it run through a few iterations scaling it up and down (like it is fixed on a spring). All of the examples i found on the net lead to this class - FloatSpring.java It should provide the needed calculations to move point A to point B applying spring-like effect which depends on various FloatSpring class settings. The problem is that i didn't find a single clear example how to use it properly. I made this small example to test FloatSpring on: public static void main ( String[] args ) { // Some image to bounce final

Java Path ImageIcon URL .JAR

笑着哭i 提交于 2019-11-26 21:58:19
问题 I may have made of try, none works.. The file is: /Users/Toto/Desktop/Titi/IUT/Java/TP2/project/src/fichierPointJava/img1.png fichierPointJava is the name of the package . I launch the ant when I am situated in project which contains the build.xml Here are the codes that I tested: URL urlImage1=this.getClass().getClassLoader.getResource("/src/fichierPointJava/img1.png"); URL urlImage1=this.getClass().getClassLoader.getResource("/fichierPointJava/img1.png"); URL urlImage1=this.getClass()

What is the correct path to display an ImageIcon png file for Windows 7?

試著忘記壹切 提交于 2019-11-26 18:37:04
问题 I wanted to test having a program with a simple png image on it. I wrote a short program that does this, but I can't seem to get the path right. I have checked, checked again, rechecked, and quadruple checked my path name as to not get it right, but this image will not display, no matter what I do. I used a short class wrote by Oracle in the ImageIcon documentation (the creaetImageIcon() ) to accomplish this, but it doesn't seem to help. I'll post the entire program below, as it is very short

How to get Icon from JTable

狂风中的少年 提交于 2019-11-26 17:34:21
问题 I have changed the cell render in JTable to show image instead of text using the following code: base_table.getColumnModel().getColumn(3).setCellRenderer(new TableCellRenderer() { @Override public Component getTableCellRendererComponent(JTable jtable, Object value, boolean bln, boolean bln1, int i, int i1) { JLabel lbl = new JLabel(); lbl.setIcon((ImageIcon) value); return lbl; } }); Now, I'd like to be able to get the image for each row in the JTable in order to save it in database. How

Customize JOptionPane Dialog

非 Y 不嫁゛ 提交于 2019-11-26 17:06:01
问题 I am learning java swing. The code below is a catch block which handles an IOException and shows a error message. catch(IOException e) { System.out.println("IOException"); JOptionPane.showMessageDialog(null,"File not found",null, JOptionPane.ERROR_MESSAGE); } I was thinking of declaring and customizing a JOptionPane of my own inside the catch block like the code below: JOptionPane jop=new JOptionPane(); jop.setLayout(new BorderLayout()); JLabel im=new JLabel("Java Technology Dive Log", new

Creating custom JButton from images containing transparent pixels

假如想象 提交于 2019-11-26 14:44:17
问题 Read edit 2 for what I'm actually missing to make it work I'm currently trying to create some custom JButtons using images created in photoshop that have an alpha parameter. So far, overriding the paint() method to draw the image has worked in the sense that the button is drawn showing the correct image. I'd like to improve it, though, by making its shape (clickable area) the same as the visible pixels on the image (right now if I draw the button's border, it's a square). Is there an easy way

Displaying an image in Java Swing

最后都变了- 提交于 2019-11-26 14:22:50
问题 public class MinesweeperMenu extends MinesweeperPanel{ private JPanel picture = new JPanel(); private JButton play = new JButton("Play"); private JButton highScores = new JButton("High Score and \nStatistics"); private JButton changeMap = new JButton("Create Custom \nor Change Map"); private JButton difficulty = new JButton("Custom or\nChange Difficulty"); private JButton user = new JButton("Change User"); Image img; public MinesweeperMenu() { // Set Layout for the menu LayoutManager

How to set Icon to a JLabel from an image from a folder?

让人想犯罪 __ 提交于 2019-11-26 13:52:28
I am trying to set an icon to a JLabel from a folder of images whenever an item is selected from a JComboBox. The name of items in the JComboBox and name of the images in the folder are same. So whenever an item is selected from the JComboBox, the corresponding image with the same name should be set as an icon to the JLabel. I am trying to do something like this. private void cmb_movieselectPopupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt){ updateLabel(cmb_moviename.getSelectedItem().toString()); } protected void updateLabel(String name) { ImageIcon icon = createImageIcon("C:\

Mirroring animated gif on load in Java - ImageIcon

烂漫一生 提交于 2019-11-26 12:48:23
问题 So I have an animated gif that I load into an ImageIcon like this: Image image = new ImageIcon(\"image.gif\").getImage(); and I can draw it using this: g.drawImage(image, x, y, null); I know that I can mirror it on the fly using AffineTransform, but I need to be able to mirror it horizontally after loading, so that I can draw the mirrored one instead if needed without the overhead of transforming it every time it gets redrawn. Is there a way to do this using swing/awt? A library that could do