View Single Post
  #2 (permalink)  
Old 03-21-2008, 09:42 AM
hardwired hardwired is offline
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
You can find the geek images at the bottom of this page: Using Swing Components: Examples
Code:
import java.awt.*; import java.awt.image.BufferedImage; import java.io.*; import javax.imageio.ImageIO; import javax.swing.*; public class ImageArray { BufferedImage[] images; public ImageArray(BufferedImage[] images) { this.images = images; } private JPanel getContent() { JPanel panel = new JPanel(new GridLayout(0,2,5,5)); panel.setBackground(Color.green.darker()); for(int i = 0; i < images.length; i++) { ImageIcon icon = new ImageIcon(images[i]); JLabel label = new JLabel(icon, JLabel.CENTER); panel.add(label); } return panel; } public static void main(String[] args) throws IOException { // Images are located in the geek folder // which is located in the images folder // which is located in the current directory. String prefix = "images/geek/geek"; String[] ids = { "-c---", "--g--", "---h-", "----t" }; String ext = ".gif"; BufferedImage[] images = new BufferedImage[ids.length]; for(int i = 0; i < images.length; i++) { String path = prefix + ids[i] + ext; images[i] = ImageIO.read(new File(path)); } ImageArray app = new ImageArray(images); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(app.getContent()); f.pack(); f.setLocation(200,200); f.setVisible(true); } }
Reply With Quote