Results 1 to 2 of 2
Thread: Stand O' Food Game Proyect
- 03-24-2008, 03:53 PM #1
Member
- Join Date
- Mar 2008
- Posts
- 1
- Rep Power
- 0
Stand O' Food Game Proyect
Hi!!
Well Im going to tell you what Im doing
In the university give me a task, to make a game in Java (lenguage Im learning)
I choose the Stand O' Food

As you can see is and ambitious proyect to me, but I want to try.
The idea of the proyect is to make the game and olso with thread make a step by step tutorial
To beging my first step is to make the backgruond of the game and thats were the problems starts, because i dont know how to putit
what i have is this..
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
public class StandOFood{
public static final int WIDTH = 1026;
public static final int HEIGHT = 757;
public StandOFood() {
JFrame ventana = new JFrame("Stand O' Foof");
ventana.setBounds(0,0,WIDTH,HEIGHT);
ventana.setVisible(true);
ventana.addWindowListener( new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
public static void main(String[] args) {
StandOFood inv = new StandOFood();
}
}
So the cuestion is.. how can i put a background image that i attach on my screen??
THX!!!! very much!!
- 03-24-2008, 05:28 PM #2
The general idea is to draw it on the background of your contentPane.
Java Code:import java.awt.*; import java.awt.image.BufferedImage; import java.io.IOException; import javax.imageio.ImageIO; import javax.swing.*; public class StandOFoodRx { public static final int WIDTH = 1026; public static final int HEIGHT = 757; public StandOFoodRx() { JFrame ventana = new JFrame("Stand O' Foof"); ventana.setContentPane(getContentPane()); ventana.setBounds(0,0,WIDTH,HEIGHT); ventana.setVisible(true); ventana.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } private JComponent getContentPane() { // Image file must be in your classpath. // Here it's in the current directory. BufferedImage image = getImage("stand-o-food-screenshot2.jpg"); ImageBackground cp = new ImageBackground(image); cp.setLayout(new BorderLayout()); // contentPanes must be opaque. cp.setOpaque(true); return cp; } private BufferedImage getImage(String path) { BufferedImage image = null; try { java.net.URL url = getClass().getResource(path); System.out.println("url = " + url); image = ImageIO.read(url); } catch(IOException e) { System.out.println("read error: " + e.getMessage()); } return image; } public static void main(String[] args) { StandOFoodRx inv = new StandOFoodRx(); } } class ImageBackground extends JPanel { BufferedImage image; ImageBackground(BufferedImage image) { this.image = image; } protected void paintComponent(Graphics g) { super.paintComponent(g); int x = (getWidth() - image.getWidth())/2; int y = (getHeight() - image.getHeight())/2; g.drawImage(image, x, y, this); } }
Similar Threads
-
Implementing "Game Over" in Minesweeper game based on Gridworld framework.
By JFlash in forum New To JavaReplies: 2Last Post: 08-05-2010, 04:49 AM -
Include file from other proyect
By oleg_gunnar in forum Advanced JavaReplies: 1Last Post: 03-08-2008, 06:20 PM -
TicTacToe Game
By Ebtihal in forum New To JavaReplies: 0Last Post: 01-09-2008, 11:01 AM -
Need help with random game!
By silverq_82 in forum New To JavaReplies: 4Last Post: 08-07-2007, 02:58 PM -
Help with pong game
By Eric in forum New To JavaReplies: 2Last Post: 07-03-2007, 07:02 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks