Name: Anonymous 2007-11-10 20:50
can't figure out what's wrong with this java app, maybe you can... trying to put background.png as the background
---
package ball;
import java.awt.image.BufferedImage;
/**
* Chapter 7: BallPanel.java
* Creates the panel to be placed inside the BallApp window.
* Used (with modifications) in all programs later in this book.
* Version 3 of 3
*/
public class BallPanel extends javax.swing.JPanel implements Mover {
private final int INIT_X = 75; // attributes
private final int INIT_Y = 75;
private final int DIAMETER = 20;
private final int INTERVAL = 10;
private BouncingBall _ball; // components
private MoveTimer _timer;
private BufferedImage background;
public BufferedImage loadImage(String "background.png") {
BufferedImage bfImg=null;
try {
bfImg = ImageIO.read(new File(background.png));
} catch (IOException e) {
}
return bfImg;
}
public BallPanel () {
super();
_ball = new BouncingBall (java.awt.Color.green, this);
_timer = new MoveTimer(INTERVAL, this);
this.setBackground(java.awt.Color.white);
_ball.setLocation(INIT_X, INIT_Y);
_ball.setSize(DIAMETER, DIAMETER);
_timer.start();
background = this.loadImage("background.png");
}
---
package ball;
import java.awt.image.BufferedImage;
/**
* Chapter 7: BallPanel.java
* Creates the panel to be placed inside the BallApp window.
* Used (with modifications) in all programs later in this book.
* Version 3 of 3
*/
public class BallPanel extends javax.swing.JPanel implements Mover {
private final int INIT_X = 75; // attributes
private final int INIT_Y = 75;
private final int DIAMETER = 20;
private final int INTERVAL = 10;
private BouncingBall _ball; // components
private MoveTimer _timer;
private BufferedImage background;
public BufferedImage loadImage(String "background.png") {
BufferedImage bfImg=null;
try {
bfImg = ImageIO.read(new File(background.png));
} catch (IOException e) {
}
return bfImg;
}
public BallPanel () {
super();
_ball = new BouncingBall (java.awt.Color.green, this);
_timer = new MoveTimer(INTERVAL, this);
this.setBackground(java.awt.Color.white);
_ball.setLocation(INIT_X, INIT_Y);
_ball.setSize(DIAMETER, DIAMETER);
_timer.start();
background = this.loadImage("background.png");
}