|
protected void paintComponent(Graphics g) {
super.paintComponent(g); display((Graphics2D) g); // display should do the drawing } |
public Dimension getPreferredSize() {
// within display method to
find current sizeRectangle rect = getBounds(); width = rect.width; height = rect.height; // early in display to erase the window graphics.setColor(clearColor); graphics.fillRect(0, 0, width, height); |
|
/** * @param name of an image file (with extension) store in images * @return reference to the image from the file */ private BufferedImage loadImage(String name) { String imgFileName = "../images/"+name; URL url = getClass().getResource(imgFileName); BufferedImage img = null; try { img = ImageIO.read(url); } catch (Exception e) { System.err.println("Failed attempt to read image: "+imgFileName); } return img; } |