Drawers refactored. Imageloading is now in the Drawers instead of
inheriting from ImagePanel. ImagePanel.java deleted.
This commit is contained in:
		@@ -1,13 +1,19 @@
 | 
				
			|||||||
package cicaprojekt;
 | 
					package cicaprojekt;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.awt.Graphics;
 | 
				
			||||||
 | 
					import java.awt.image.BufferedImage;
 | 
				
			||||||
 | 
					import java.io.File;
 | 
				
			||||||
import java.io.IOException;
 | 
					import java.io.IOException;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class FieldDrawer extends ImagePanel implements Drawer {
 | 
					import javax.imageio.ImageIO;
 | 
				
			||||||
 | 
					import javax.swing.JPanel;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class FieldDrawer extends JPanel implements Drawer {
 | 
				
			||||||
 | 
					    private BufferedImage image;
 | 
				
			||||||
    Field field;
 | 
					    Field field;
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    public FieldDrawer(Field f) throws IOException {
 | 
					    public FieldDrawer(Field f) throws IOException {
 | 
				
			||||||
        super("Field.png");
 | 
					        image = ImageIO.read(new File("Field.png"));
 | 
				
			||||||
        field = f;
 | 
					        field = f;
 | 
				
			||||||
        setVisible(false);
 | 
					        setVisible(false);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -34,4 +40,15 @@ public class FieldDrawer extends ImagePanel implements Drawer {
 | 
				
			|||||||
        return field.getY();
 | 
					        return field.getY();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    protected void paintComponent(Graphics g) {
 | 
				
			||||||
 | 
					        super.paintComponent(g);
 | 
				
			||||||
 | 
					        g.drawImage(image, 0, 0, null); // see javadoc for more info on the parameters            
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    public void changeImage(String path) throws IOException {
 | 
				
			||||||
 | 
					        image = ImageIO.read(new File(path));
 | 
				
			||||||
 | 
					        repaint();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,13 +1,19 @@
 | 
				
			|||||||
package cicaprojekt;
 | 
					package cicaprojekt;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.awt.Graphics;
 | 
				
			||||||
 | 
					import java.awt.image.BufferedImage;
 | 
				
			||||||
 | 
					import java.io.File;
 | 
				
			||||||
import java.io.IOException;
 | 
					import java.io.IOException;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class GapDrawer extends ImagePanel implements Drawer{
 | 
					import javax.imageio.ImageIO;
 | 
				
			||||||
 | 
					import javax.swing.JPanel;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class GapDrawer extends JPanel implements Drawer{
 | 
				
			||||||
 | 
					    private BufferedImage image;
 | 
				
			||||||
    private Gap gap;
 | 
					    private Gap gap;
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    public GapDrawer(Gap g) throws IOException {
 | 
					    public GapDrawer(Gap g) throws IOException {
 | 
				
			||||||
        super("Gap.png");
 | 
					        image = ImageIO.read(new File("Gap.png"));
 | 
				
			||||||
        gap = g; 
 | 
					        gap = g; 
 | 
				
			||||||
        setVisible(false);
 | 
					        setVisible(false);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -27,4 +33,10 @@ public class GapDrawer extends ImagePanel implements Drawer{
 | 
				
			|||||||
        return gap.getY();
 | 
					        return gap.getY();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    protected void paintComponent(Graphics g) {
 | 
				
			||||||
 | 
					        super.paintComponent(g);
 | 
				
			||||||
 | 
					        g.drawImage(image, 0, 0, null); // see javadoc for more info on the parameters            
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,13 +1,19 @@
 | 
				
			|||||||
package cicaprojekt;
 | 
					package cicaprojekt;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.awt.Graphics;
 | 
				
			||||||
 | 
					import java.awt.image.BufferedImage;
 | 
				
			||||||
 | 
					import java.io.File;
 | 
				
			||||||
import java.io.IOException;
 | 
					import java.io.IOException;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class GateDrawer extends ImagePanel implements Drawer{
 | 
					import javax.imageio.ImageIO;
 | 
				
			||||||
 | 
					import javax.swing.JPanel;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class GateDrawer extends JPanel implements Drawer{
 | 
				
			||||||
 | 
					    private BufferedImage image;
 | 
				
			||||||
    Gate gate;
 | 
					    Gate gate;
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    public GateDrawer(Gate g) throws IOException {
 | 
					    public GateDrawer(Gate g) throws IOException {
 | 
				
			||||||
        super("ClosedGate.png");
 | 
					        image = ImageIO.read(new File("ClosedGate.png"));
 | 
				
			||||||
        gate = g;
 | 
					        gate = g;
 | 
				
			||||||
        setVisible(false);
 | 
					        setVisible(false);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -32,4 +38,15 @@ public class GateDrawer extends ImagePanel implements Drawer{
 | 
				
			|||||||
        return gate.getY();
 | 
					        return gate.getY();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    protected void paintComponent(Graphics g) {
 | 
				
			||||||
 | 
					        super.paintComponent(g);
 | 
				
			||||||
 | 
					        g.drawImage(image, 0, 0, null); // see javadoc for more info on the parameters            
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    public void changeImage(String path) throws IOException {
 | 
				
			||||||
 | 
					        image = ImageIO.read(new File(path));
 | 
				
			||||||
 | 
					        repaint();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,29 +0,0 @@
 | 
				
			|||||||
package cicaprojekt;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.awt.Graphics;
 | 
					 | 
				
			||||||
import java.awt.image.BufferedImage;
 | 
					 | 
				
			||||||
import java.io.File;
 | 
					 | 
				
			||||||
import java.io.IOException;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import javax.imageio.ImageIO;
 | 
					 | 
				
			||||||
import javax.swing.JPanel;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class ImagePanel extends JPanel{
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private BufferedImage image;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public ImagePanel(String path) throws IOException {                
 | 
					 | 
				
			||||||
        image = ImageIO.read(new File(path));
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    protected void paintComponent(Graphics g) {
 | 
					 | 
				
			||||||
        super.paintComponent(g);
 | 
					 | 
				
			||||||
        g.drawImage(image, 0, 0, null); // see javadoc for more info on the parameters            
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    public void changeImage(String path) throws IOException {
 | 
					 | 
				
			||||||
        image = ImageIO.read(new File(path));
 | 
					 | 
				
			||||||
        repaint();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,13 +1,19 @@
 | 
				
			|||||||
package cicaprojekt;
 | 
					package cicaprojekt;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.awt.Graphics;
 | 
				
			||||||
 | 
					import java.awt.image.BufferedImage;
 | 
				
			||||||
 | 
					import java.io.File;
 | 
				
			||||||
import java.io.IOException;
 | 
					import java.io.IOException;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class ScaleDrawer extends ImagePanel implements Drawer {
 | 
					import javax.imageio.ImageIO;
 | 
				
			||||||
 | 
					import javax.swing.JPanel;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class ScaleDrawer extends JPanel implements Drawer {
 | 
				
			||||||
 | 
					    private BufferedImage image;
 | 
				
			||||||
    Scale scale;
 | 
					    Scale scale;
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    public ScaleDrawer(Scale s) throws IOException {
 | 
					    public ScaleDrawer(Scale s) throws IOException {
 | 
				
			||||||
        super("Scale.png");
 | 
					        image = ImageIO.read(new File("Scale.png"));
 | 
				
			||||||
        scale = s;
 | 
					        scale = s;
 | 
				
			||||||
        setVisible(false);
 | 
					        setVisible(false);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -32,4 +38,15 @@ public class ScaleDrawer extends ImagePanel implements Drawer {
 | 
				
			|||||||
        return scale.getY();
 | 
					        return scale.getY();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    protected void paintComponent(Graphics g) {
 | 
				
			||||||
 | 
					        super.paintComponent(g);
 | 
				
			||||||
 | 
					        g.drawImage(image, 0, 0, null); // see javadoc for more info on the parameters            
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    public void changeImage(String path) throws IOException {
 | 
				
			||||||
 | 
					        image = ImageIO.read(new File(path));
 | 
				
			||||||
 | 
					        repaint();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,13 +1,19 @@
 | 
				
			|||||||
package cicaprojekt;
 | 
					package cicaprojekt;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.awt.Graphics;
 | 
				
			||||||
 | 
					import java.awt.image.BufferedImage;
 | 
				
			||||||
 | 
					import java.io.File;
 | 
				
			||||||
import java.io.IOException;
 | 
					import java.io.IOException;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class WallDrawer extends ImagePanel implements Drawer {
 | 
					import javax.imageio.ImageIO;
 | 
				
			||||||
 | 
					import javax.swing.JPanel;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class WallDrawer extends JPanel implements Drawer {
 | 
				
			||||||
 | 
					    private BufferedImage image;
 | 
				
			||||||
    Wall wall;
 | 
					    Wall wall;
 | 
				
			||||||
 
 | 
					 
 | 
				
			||||||
    public WallDrawer(Wall w) throws IOException {
 | 
					    public WallDrawer(Wall w) throws IOException {
 | 
				
			||||||
        super("Wall.png");
 | 
					        image = ImageIO.read(new File("Wall.png"));
 | 
				
			||||||
        wall = w;
 | 
					        wall = w;
 | 
				
			||||||
        setVisible(false);
 | 
					        setVisible(false);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -46,4 +52,15 @@ public class WallDrawer extends ImagePanel implements Drawer {
 | 
				
			|||||||
        return wall.getY();
 | 
					        return wall.getY();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
   
 | 
					   
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    protected void paintComponent(Graphics g) {
 | 
				
			||||||
 | 
					        super.paintComponent(g);
 | 
				
			||||||
 | 
					        g.drawImage(image, 0, 0, null); // see javadoc for more info on the parameters            
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    public void changeImage(String path) throws IOException {
 | 
				
			||||||
 | 
					        image = ImageIO.read(new File(path));
 | 
				
			||||||
 | 
					        repaint();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user