Pane.java
00001 package edu.virtualschool.jwaa.swing;
00002 import java.awt.Dimension;
00003 import java.awt.FlowLayout;
00004 import java.awt.Graphics;
00005 import java.awt.Image;
00006 import java.awt.LayoutManager;
00007 import java.net.URL;
00008
00009 import javax.swing.ImageIcon;
00010 import javax.swing.JComponent;
00011
00012 import edu.virtualschool.jwaa.RuntimeFault;
00013 import edu.virtualschool.jwaa.resource.Resource;
00014
00018 public class Pane extends JComponent
00019 {
00020 final static boolean isMac = System.getProperty("mrj.version") != null;
00021 static Image image;
00022 final static String name = "Pane.png";
00023
00024 public Pane()
00025 {
00026 this(new FlowLayout());
00027 }
00028 public Pane(LayoutManager m)
00029 {
00030 setLayout(m);
00031 }
00032 public void paintComponent(Graphics graphic)
00033 {
00034 super.paintComponent(graphic);
00035 if (isMac) return;
00036
00037
00038
00039
00040 if (image == null)
00041 {
00042 URL url = Resource.class.getResource(name);
00043 if (url == null)
00044 throw new RuntimeFault(name+" not found");
00045 ImageIcon img = new ImageIcon(url, name);
00046 image = img.getImage();
00047 }
00048 Dimension dim = this.getSize();
00049 int dx = image.getWidth(this);
00050 int dy = image.getHeight(this);
00051 for (int x = 0; x < dim.width; x += dx)
00052 for (int y = 0; y < dim.height; y += dy)
00053 graphic.drawImage(image, x, y, this);
00054 }
00055 }