Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: need help quickly plz!!!

  1. #1
    Junior Member
    Join Date
    Feb 2010
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Unhappy need help quickly plz!!!

    i wrote a game and i have a cannot find symbol constuctor error. i need this by the morning or at the latest tommarow its for a school project.

    my code for the main class is

    //shooter game
    //main class
     
    import javax.swing.*;              //frame
    import java.awt.*;                //color
    import java.util.*;
    import java.awt.event.*;
    import java.io.*;
     
     
    public class Shooter extends JFrame implements KeyListener{
    		Image img;
    		Graphics dbi;
     
    		boolean u,d,w,s;
    		int S,E;
     
    	    Player p1=new Player(5,150,10,50,Color.RED,"LEFT.gif");
    	    Player p2=new Player(585,150,10,50,Color.GREEN,"RIGHT.gif");
    	    ArrayList<Bullets>b=new ArrayList<Bullets>();
     
    	public Shooter () {
    		setTitle("Shooter");
    		setSize(600,600);
    		setResizable(false);
    		setBackground(Color.BLACK);
    		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		addKeyListener(this);
    		u=d=w=s=false;
    		S=E=0;
     
    		setVisible(true);
    	}
     
    	public void paint(Graphics g){
    		img=createImage(getWidth(),getHeight());
    		dbi=img.getGraphics();
     
    		paintComponent(dbi);
    		g.drawImage(img,0,0,this);
    		repaint();
    	}
    	public void paintComponent(Graphics g){
    		if(p1.health>0&&p2.health>0){
    			for(Bullets b1:b){
    				b1.draw(g);
    			}
    			update();
    		}
    		else{
    			if(p1.health<=0){
    				g.setColor(p2.col);
    				g.drawString("PLAYER 2 WINS!",250,190);
    			}
    			else{g.setColor(p1.col);
    				g.drawString("PLAYER 1 WINS!",250,190);
     
    			}
    		}
    		p1.draw(g);
    		p2.draw(g);
     
    	}
    	public void update(){
    		if(w&&p1.y>24)p1.moveUp();
    		if(s&&p1.y<347)p1.moveDown();
    		if(u&&p2.y>24)p2.moveUp();
    		if(d&&p2.y<347)p2.moveDown();
    		if(E==1){
    			Bullets add=p2.getBull();
    			add.xVel=-3;
    			b.add(add);
    			E++;
    			E++;
    		}
    		if(S==1){
    			Bullets add=p1.getBull();
    			add.xVel=3;
    		}
    		for(int x=0;x<b.size();x++){
    			b.get(x).move();
    			if(b.get(x).rect.intersects(p1.rect)&&b.get(x).xVel<0){
    				p1.health--;
    				b.remove(x);
    				x--;
    				continue;
    			}
    			if(b.get(x).rect.intersects(p2.rect)&&b.get(x).xVel<0){
    				p2.health--;
    				b.remove(x);
    				x--;
    				continue;
    			}
     
     
    		}
    	}
    	public void keyTyped(KeyEvent e){}
    	public void keyPressed(KeyEvent e){
    		switch(e.getKeyCode()){
    			case KeyEvent.VK_UP:u=true;break;
    		case KeyEvent.VK_DOWN:d=true;break;
    		case KeyEvent.VK_W:w=true;break;
    		case KeyEvent.VK_S:s=true;break;
     
     
    		case KeyEvent.VK_SPACE:S++;break;
    		case KeyEvent.VK_ENTER:E++;break;
    		}
     
    	}
    	public void keyReleased(KeyEvent e){
    		switch(e.getKeyCode()){
    			case KeyEvent.VK_UP:u=false;
    			case KeyEvent.VK_DOWN:d=false;
    			case KeyEvent.VK_W:w=false;
    			case KeyEvent.VK_S:s=false;
     
    			case KeyEvent.VK_ENTER:E=0;break;
    			case KeyEvent.VK_SPACE:S=0;break;
     
    		}
    	}
     
     
     
    	public static void main(String[]beans){
    		KeyListener a=new Shooter ();
    	}
    }





    i get the error

    cannot find symbol constructor Player(int,int,int,int,java.awt.Color,java.lang.St ring)

    on lines 18 and 19
     Player p1=new Player(5,150,10,50,Color.RED,"LEFT.gif");
    	    Player p2=new Player(585,150,10,50,Color.GREEN,"RIGHT.gif");

    i have no clue what to do so any help would be great thanx


  2. #2
    Member
    Join Date
    Feb 2010
    Location
    Dehradun, India
    Posts
    37
    Thanks
    1
    Thanked 7 Times in 6 Posts

    Default Re: need help quickly plz!!!

    Hi,

    You are using a Player class which is not defined anywhere. Please define Player class first and then try to execute your Shooter class

  3. #3
    Junior Member
    Join Date
    Feb 2010
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: need help quickly plz!!!

    this is my Player class
    //shooter game
    //player class
    import java.awt.*;
     
    public class Player{
    	int x,y;                   
    	int height,width;          
    	int health;			       
    	Image img;				   
    	Rectangle rect;            
    	Color col;
     
     
    	public Player(){           
    		x=y=height=width=0;
    		img=null;
    		col=Color.WHITE;
    		health=10;
    		rect=new Rectangle(x,y,width,height);
     
    	}
     
    	public Player(int x,int y){       
    		this.x=x;
    		this.y=y;
    		height=width=0;
    		col=Color.WHITE;
    		img=null;
    		health=10;
    		rect=new Rectangle(x,y,width,height);
     
    	}
    	public Player(int x,int y,int wd,int ht){       
    		this.x=x;
    		this.y=y;
    		height=ht;
    		width=wd;
    		img=null;
    		col=Color.WHITE;		
    		health=10;
    		rect=new Rectangle(x,y,width,height);
     
    	}
    	public Player(int x,int y,int wd,int ht,String s){       
    		this.x=x;
    		this.y=y;
    		height=ht;
    		width=wd;
    		col=Color.WHITE;
    		health=10;
    		img=Toolkit.getDefaultToolkit().getImage(s);
    		rect=new Rectangle(x,y,width,height);
     
     
    	}
    	public Player(int x,int y,int wd,int ht,Color c,String s){       
    		this.x=x;
    		this.y=y;
    		height=ht;
    		width=wd;
    		col=c;
    		health=10;
    		img=Toolkit.getDefaultToolkit().getImage(s);
    		rect=new Rectangle(x,y,width,height);
     
     
    	}
     
     
    	public void draw(Graphics g){
    		g.drawImage(img,x,y,null);
    	}   
    	public void setImage(String s){
    		img=Toolkit.getDefaultToolkit().getImage(s);
    	}        
    	public void moveUp() {
    		y-=3;
    		rect.setLocation(x,y);
    	}                               
    	public void moveDown(){    					
    		y+=3;
    		rect.setLocation(x,y);
     
    	}  	
    	public Bullets getBull(){
    		return new Bullets(x+8,y+23,3,3,col);
    	}					
    }

  4. #4
    Member
    Join Date
    Feb 2010
    Location
    Dehradun, India
    Posts
    37
    Thanks
    1
    Thanked 7 Times in 6 Posts

    Default Re: need help quickly plz!!!

    Hi I used your player class but now it is giving an error on Bullets. What is Bullets now?

    Is it some another class?

  5. The Following User Says Thank You to jassi For This Useful Post:

    computerfreak.7777 (February 11th, 2010)

  6. #5
    Junior Member
    Join Date
    Feb 2010
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: need help quickly plz!!!

    yes here it is


    //shooter game
    //Bullets class
     
    import java.awt.*;
     
    public class Bullets{
    	int x,y;
    	int xVel;
    	int height,width;
    	Rectangle rect;
    	Color col;
     
    	public Bullets(){
    		x=y=height=width=0;
    		col=Color.WHITE;
    		rect=new Rectangle(x,y,width,height);
    	}
    	public Bullets (int x,int y,int wd,int ht,Color c){
    		this.x=x;
    		this.y=y;
    		this.xVel=0;
    		height=ht;
    		width=wd;
    		col=c;
    		rect=new Rectangle(x,y,width,height);
    	}
    		public Bullets (int x,int y,int wd,int ht,int xVel,Color c){
    		this.x=x;
    		this.y=y;
    		this.xVel=xVel;
    		height=ht;
    		width=wd;
    		col=c;
    		rect=new Rectangle(x,y,width,height);
    	}
    	public void draw(Graphics g){
    		g.setColor(col);
    		g.fillOval(x,y,width,height);
     
    	}
    	public void move(){
    		x=+xVel;
    		rect.setLocation(x,y);
    	}
    }

  7. #6
    Junior Member
    Join Date
    Feb 2010
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: need help quickly plz!!!

    i dont know what was happening but i recopied the code into a different workspace and now i have no errors thank you so much

  8. #7
    Member
    Join Date
    Feb 2010
    Location
    Dehradun, India
    Posts
    37
    Thanks
    1
    Thanked 7 Times in 6 Posts

    Default Re: need help quickly plz!!!

    Hi I want to run your program. Please give the necessary files like LEFT.gif and Right.gif. I want to try your program.