public class InventoryList extends JPanel { public static final int EQUIPMENT = 3; public static final int STORE = 13; public static final int HOME = 6; public static final ImageIcon PCI = ImageLoader.getImageIcon("images/pci.png"); public static final ImageIcon FOLDER = ImageLoader.getImageIcon("images/folderBig.png"); public static final ImageIcon TEXT = ImageLoader.getImageIcon("images/textfile.png"); public static final ImageIcon FIREWALL = ImageLoader.getImageIcon("images/firewallHome.png"); public static final ImageIcon SCRIPT = ImageLoader.getImageIcon("images/scriptHome.png"); private int x = 2, y = 5, last = 0, count = EQUIPMENT; private boolean paint = true; public InventoryList() { setLayout(null); } // public void setInventory( public void addInventory(Inventory inv) { add(inv); inv.setBounds(x, y, 47, 42); if (last != count) { x += 50; last += 1; } else { x = 2; y += 50; last = 0; } setPreferredSize(new Dimension(82 * count, y + 30)); } public void setPaint(boolean paint) { this.paint = paint; } public void setCount(int count) { this.count = count; } public void reset() { removeAll(); x = 2; y = 5; last = 0; repaint(); } public void paintComponent(Graphics g) { if (paint) { try { Rectangle vis = getVisibleRect(); File fi = ImageLoader.getFile("images/inventoryback.png"); BufferedImage bg = ImageIO.read(fi.toURL()); g.drawImage(bg, vis.x, vis.y, null); } catch (Exception e) { } } } }
public void paintComponent(Graphics g) { if (paint) { try { Rectangle vis = getVisibleRect(); File fi = ImageLoader.getFile("images/inventoryback.png"); BufferedImage bg = ImageIO.read(fi.toURL()); g.drawImage(bg, vis.x, vis.y, null); } catch (Exception e) { } } }