1 Attachment(s)
how i could make this play ,please?!!
Hi! i really need help please .. i am doing a program that kinda of a game .... i am tying to import some images that is make an animation game ....
i am making a Snow man kick a ball trying to hit a tree ... when it came in the right place .... the tree vanishes ... and thats the code ... but there is no images displayed ... is it right when i put the pic. in the same package ?!
and if u guyz help and that will be awesome .... i need a slope (a math method that i don't know how it could be :D) in this game to make the game depend on the slope .... "like rocket man if someone know it"
that's the code ::::
Code:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication17;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Image;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
/**
*
* @author MonDo
*/
class Main
{
public static void main( String[] args ) {
JFrame frame = new JFrame( "Harbin Game" );
frame.add(new HarbinComponent(),BorderLayout.CENTER);
frame.setSize( 500, 500 );
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
frame.setVisible( true );
}
// Inner Class: Displaying a String
static class HarbinComponent extends JPanel {
private String message;
Image tree;
Image snowman;
public HarbinComponent(){
message="Welcome to Harbin!";
try {
tree = ImageIO.read(new File("harbin.jpg"));
}
catch (IOException e) {
}
try {
snowman = ImageIO.read(new File("snowman.jpg"));
}
catch (IOException e) {
}
this.setLayout(new BorderLayout());
JPanel p1=new JPanel(new FlowLayout());
JTextField jtfTest= new JTextField("Enter the slope here");
p1.add(jtfTest);
JButton jbtTest= new JButton("Play");
p1.add(jbtTest);
JButton jbtTest1= new JButton("New Game");
p1.add(jbtTest1);
this.add(p1,BorderLayout.SOUTH);
}
public void paintComponent( Graphics g ) {
super.paintComponent(g);
g.setColor(Color.WHITE);
g.fillRect(0, 0, this.getWidth(), this.getHeight());
g.drawImage(tree, 0, 0, this);
g.drawImage(snowman, 0, 580, this);
g.drawString( message, 10,330 );
}
}
}
and there is pic to understand more ... thanks alot for just reading , sorry abt long speech
game explanation:
first the ball roll over the black bar and falls in front of the snow man then it kicks the ball and hit the tree to be vanished ..
and thx again