public void actionPerformed(ActionEvent ae) { if (ae.getActionCommand() == "timer") { if (counter >= imagePaths.length) { timer.stop(); counter = 0; PlayStopButton.setText("Play"); } else { try { // if the array contains URLs if (imagePaths[counter].contains("http://")) { scrollPane.setToolTipText(imagePaths[counter]); imageIcon = new ImageIcon((new URL(imagePaths[counter++]))); scrollPane.setViewportView(new JLabel(imageIcon)); } // if the array contains local images else { image.setIcon(new ImageIcon(imagePaths[counter])); image.setToolTipText(imagePaths[counter++]); } } catch (MalformedURLException ex) { Logger.getLogger(Slideshow.class.getName()).log(Level.SEVERE, null, ex); image = new JLabel("?" + imagePaths); } } } }
private void setUpGui() { area = JokemonDriver.Area.Stringville; mouse = new Point(); int thingInt = 0; this.setTitle("Town Map"); this.setSize(195, 239); this.setResizable(false); this.setLayout(null); this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); this.setVisible(false); visible = false; this.setLocationRelativeTo(null); Container cp = this.getContentPane(); JLabel map = new JLabel(); map.setBounds(1, -5, 188, 176); map.setIcon(new ImageIcon(townMap.class.getResource("Logos/townmap.png"))); closeWindow = new JButton(); closeWindow.setText("Close Window"); closeWindow.setBounds(0, 192, 188, 20); areaDisplay = new JLabel(); areaDisplay.setText(area.toString().replace('_', ' ')); areaDisplay.setHorizontalAlignment(JLabel.CENTER); areaDisplay.setBounds(0, 171, 188, 20); addMouseMotionListener(this); closeWindow.addActionListener(this); cp.add(map); cp.add(closeWindow); cp.add(areaDisplay); }
public void loadImage(String filename) { theImage.setIcon(new MyImageIcon(filename)); }