Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-24-2008, 05:53 PM
Member
 
Join Date: Mar 2008
Posts: 1
piachens is on a distinguished road
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!!
Attached Images
File Type: jpg fondo2.jpg (85.8 KB, 0 views)
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 03-24-2008, 07:28 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
The general idea is to draw it on the background of your contentPane.
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); } }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Include file from other proyect oleg_gunnar Advanced Java 1 03-08-2008 08:20 PM
TicTacToe Game Ebtihal New To Java 0 01-09-2008 01:01 PM
Implementing "Game Over" in Minesweeper game based on Gridworld framework. JFlash New To Java 0 11-16-2007 01:02 AM
Need help with random game! silverq_82 New To Java 4 08-07-2007 04:58 PM
Help with pong game Eric New To Java 2 07-03-2007 09:02 PM


All times are GMT +3. The time now is 06:21 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org