9 package micropolisj.gui;
12 import java.awt.image.*;
16 import micropolisj.engine.*;
41 static final BufferedImage backgroundImage = loadImage(
"/demandg.png");
42 static BufferedImage loadImage(String resourceName)
45 Image refImage =
new ImageIcon(iconUrl).getImage();
47 BufferedImage bi =
new BufferedImage(refImage.getWidth(null), refImage.getHeight(null),
48 BufferedImage.TYPE_INT_RGB);
49 Graphics2D gr = bi.createGraphics();
50 gr.drawImage(refImage, 0, 0, null);
55 static final Dimension MY_SIZE =
new Dimension(
56 backgroundImage.getWidth(),
57 backgroundImage.getHeight()
78 static final int UPPER_EDGE = 19;
79 static final int LOWER_EDGE = 28;
80 static final int MAX_LENGTH = 16;
81 static final int RES_LEFT = 8;
82 static final int COM_LEFT = 17;
83 static final int IND_LEFT = 26;
84 static final int BAR_WIDTH = 6;
88 Graphics2D gr = (Graphics2D) gr1;
89 gr.drawImage(backgroundImage, 0, 0, null);
97 int ry0 = resValve <= 0 ? LOWER_EDGE : UPPER_EDGE;
98 int ry1 = ry0 - resValve/100;
100 if (ry1 - ry0 > MAX_LENGTH) { ry1 = ry0 + MAX_LENGTH; }
101 if (ry1 - ry0 < -MAX_LENGTH) { ry1 = ry0 - MAX_LENGTH; }
104 int cy0 = comValve <= 0 ? LOWER_EDGE : UPPER_EDGE;
105 int cy1 = cy0 - comValve/100;
108 int iy0 = indValve <= 0 ? LOWER_EDGE : UPPER_EDGE;
109 int iy1 = iy0 - indValve/100;
113 Rectangle resRect =
new Rectangle(RES_LEFT, Math.min(ry0,ry1), BAR_WIDTH, Math.abs(ry1-ry0));
114 gr.setColor(Color.GREEN);
116 gr.setColor(Color.BLACK);
122 Rectangle comRect =
new Rectangle(COM_LEFT, Math.min(cy0,cy1), BAR_WIDTH, Math.abs(cy1-cy0));
123 gr.setColor(Color.BLUE);
125 gr.setColor(Color.BLACK);
131 Rectangle indRect =
new Rectangle(IND_LEFT, Math.min(iy0,iy1), BAR_WIDTH, Math.abs(iy1-iy0));
132 gr.setColor(Color.YELLOW);
134 gr.setColor(Color.BLACK);