Hi guys, i am trying to add a image as the background for my project but cant get my code right, heres what I got so far
//beginning of 1
import java.awt.Graphics2D;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import javax.swing.JPanel;
/**
*/
public class makeB extends JPanel {
private BufferedImage buffer;
private void initialise() {
buffer = new BufferedImage(700, 500, BufferedImage.TYPE_INT_RGB);
}
private void drawBuffer() {
Graphics2D b = buffer.createGraphics();
createBackGround.makeBackground(b,this);
b.dispose();
}
private void drawScreen() {
Graphics2D g = (Graphics2D) this.getGraphics();
g.drawImage(buffer, 0, 0, this);
Toolkit.getDefaultToolkit().sync();
g.dispose();
}
public void startGame() {
initialise();
drawBuffer();
drawScreen();
}
}
//end
//beginning of 2
import javax.swing.JFrame;
/**
*/
public class gameScreen {
private makeB panel = new makeB();
private JFrame jFrame1;
public gameScreen(){
panel = new makeB ();
jFrame1 = new JFrame("&Wave&");
jFrame1.setSize(706, 528); //to account for the border; size is actually 800x600
jFrame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jFrame1.setLocationRelativeTo(null); //to make sure that it is in the centre of the screen
jFrame1.getContentPane().add(panel);
jFrame1.setResizable(false);
jFrame1.setVisible(true);
}
private void go() {
panel.startGame();
}
public static void main(String[] args) {
gameScreen newClass = new gameScreen();
newClass.go();
}
}
//end
//beginning of 3
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.ImageObserver;
import javax.swing.ImageIcon;
/**
*/
public class createBackGround {
private static String imageN = "#big-wave#";
private static Image backg = new ImageIcon(".\\data"+ imageN +".jpg").getImage();
public static void makeBackground(Graphics2D g2,ImageObserver o) {
g2.drawImage(backg, 0, 0, o);
}
}
//end
there are 3 classes there, can someone help me refine it to get it to work
where there is #...# the image goes there, and where there &...& some name goes there