001 package viewguitest; 002 import java.awt.Container; 003 import java.awt.Dimension; 004 import java.awt.Graphics; 005 import java.awt.Image; 006 import java.awt.event.ActionEvent; 007 import java.awt.event.ActionListener; 008 import java.util.ArrayList; 009 010 import javax.swing.JFrame; 011 import javax.swing.JPanel; 012 013 import antichess.viewgui.ImageMap; 014 015 /** 016 * The MainView class handles all of the GUI, the rendering 017 * the management of options etc. More specifications to come 018 * 019 * @author nlharr 020 * 021 * 022 * 023 */ 024 025 public class ImageMapTest implements ActionListener { 026 027 028 private class ImageViewClass extends Container{ 029 private Image img; 030 public ImageViewClass(Image img){ 031 this.img = img; 032 } 033 public void paint(Graphics g) { 034 Dimension size = getSize(); 035 g.drawImage(img, 036 0, 0, size.width, size.height, 037 0, 0, img.getWidth(null), img.getHeight(null), 038 null); 039 } 040 041 042 /* We want to size the component around the text. */ 043 public Dimension getPreferredSize() { 044 045 return new Dimension(img.getWidth(null), img.getHeight(null)); 046 } 047 048 private static final long serialVersionUID = 4647775122186039615L; 049 } 050 051 /** 052 * @return the content plane for the GUI 053 */ 054 055 private ImageMap imageMap; 056 public Container getContentPane(){ 057 JPanel cpanel = new JPanel(); 058 imageMap = new ImageMap("..\\viewguitest\\imagetestfolder"); 059 for (int i=0; i<2; i++){ 060 imageMap.loadImage("test"+Integer.toString(i)); 061 } 062 ArrayList<String> strList = new ArrayList<String>(); 063 strList.add("test2"); 064 strList.add("test4"); 065 strList.add("test3"); 066 imageMap.loadImageList(strList); 067 for (int i=0; i<5; i++){ 068 069 cpanel.add(new ImageViewClass( imageMap.getImage("test"+Integer.toString(i)) ) ); 070 } 071 return cpanel; 072 } 073 074 075 /** 076 * Handles events for the TimerLabelTest 077 */ 078 public void actionPerformed(ActionEvent e) { 079 080 } 081 082 083 /** 084 * Create the GUI and shows it. 085 */ 086 087 public static void createAndShowGUI() { 088 //Create and set up the window 089 JFrame.setDefaultLookAndFeelDecorated(true); 090 JFrame frame = new JFrame("AntiChessImageMapTest"); 091 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 092 093 //Create and set up the content pane and menu bar 094 ImageMapTest gui = new ImageMapTest(); 095 frame.setContentPane(gui.getContentPane()); 096 //Display the window 097 frame.setSize(400, 400); 098 frame.setVisible(true); 099 } 100 101 102 /** 103 * Tests the basics of loading images and getting images with the 104 * ImageMap class 105 * 106 * Tests loadImage, getImage, loadImageList 107 * 108 */ 109 110 111 public static void main(String args[]){ 112 113 javax.swing.SwingUtilities.invokeLater(new Runnable() { 114 public void run() { 115 createAndShowGUI(); 116 } 117 }); 118 } 119 120 }