Total members 9952 | Gratitudes |It is currently Sat Feb 11, 2012 1:29 pm Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 2 posts ] 
Author Question
 Question subject: i have a problem in this program...plz help
PostPosted: Thu Jul 23, 2009 4:18 pm 
Offline
Newbie
User avatar

Joined: Wed Jul 22, 2009 4:19 pm
Posts: 1
Has thanked: 0 time
Have thanks: 0 time

Code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.JApplet;
import java.util.Random;

class shootApplet extends JApplet
{
   public void init()
   {
      setContentPane(new game() );
      
   }

class game extends JPanel implements MouseListener
{
   private int width,height;
   int score=0;
   int x1,x2,x3,y1,y2,y3;
   int shot=0;
   int b_no[]=new int[3];
   int  x[]=new int[3];
   int  y[]=new int[3];
   private Ball ball;
   game()
   {
      setBackground(Color.yellow);
      
      ActionListener al=new ActionListener()
      {
         public void actionPerformed(ActionEvent ae)
            {
               if(ball!=null)
               {
                  ball.generateCoord();
               }
               repaint();
            }
      };
      
   }
      
   addMouseListener();   
   public void mouseClicked(MouseEvent me)
   {
      int x,y;
      x=me.getX();
      y=me.getY();
      if(x==x1&&y==y1)
      {
         b_no[0]=0;
         score=score+5;
         shot++;
      }
      else if(x==x2&&y==y2)
      {
         b_no[1]=0;
         score=score+5;
         shot++;
      }
      else if(x==x3&&y==y3)
      {
         b_no[2]=0;
         score=score+5;
         shot++;
      }
            
   }
      
   public void mousePressed(MouseEvent me)   {}
      
   public void mouseReleased(MouseEvent me){}
   
   public void mouseEntered(MouseEvent me){}
      
   public void mouseExited(MouseEvent me){}
      
   public void paintComponent(Graphics g)
   {
        super.paintComponent(g);  // Fill panel with background color, green.
        if (ball==null)
      {
              // The first time that paintComponent is called, it assigns
             // values to the instance variables.
            width = getWidth();
            height = getHeight();
            ball=new Ball();
      }
   
      if (hasFocus())
      {
         g.setColor(Color.BLUE);
      }
      else
      {
         g.setColor(Color.RED);
         g.drawString("Target Balls",230,300);
         g.drawString("By Shilpa Dahiya",220,350);
         g.drawString("CLICK TO ACTIVATE", 210, 400);
         g.setColor(Color.GRAY);
      }
      g.drawRect(0,0,width-1,height-1);
      g.drawRect(1,1,width-3,height-3);
      g.drawRect(2,2,width-5,height-5);
      g.setColor(Color.BLACK);
      g.drawString("Score  " + score, 15, 24);
    }

    class Ball
   {
         
         Random rand =new Random();
         int start;
         
         int z;
         
         Ball()
         {
            b_no[0]=1;
             b_no[1]=1;
             b_no[2]=1;
            this.start=1;
          }
         void generateCoord()
         {
            if(shot==3||start==1||y[0]>500||y[1]>500||y[2]>500)
            {
               shot=0;
               z=0;
               while(z<3)
               {
                  x[z]=(int)(Math.random()*400);
                  y[z]=(int)(Math.random()*400);
                  z++;
                  b_no[0]=1;
                  b_no[1]=1;
                  b_no[2]=1;
                  
               }
            }
            
         }
         
      
   
      void draw(Graphics g)
      {     
         if(b_no[0]!=0)
         {
            g.setColor(Color.red);
                g.drawOval(x[0],y[0],30,30);
                g.setColor(new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256)));
            g.fillOval(x[0],y[0],30,30);
            x1=x[0];
            y1=y[0];
            
            }                  
         if(b_no[1]!=0)
         {
            g.setColor(Color.red);
            g.drawOval(x[1],y[1],30,30);
            g.setColor(new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256)));
            g.fillOval(x[1],y[1],30,30);
            x2=x[1];
            y2=y[1];
            }
         if(b_no[2]!=0)
         {
            g.setColor(Color.red);
            g.drawOval(x[2],y[2],30,30);
            g.setColor(new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256)));
            g.fillOval(x[2],y[2],30,30);
            x3=x[2];
            y3=y[2];
         }
      
      }   
   }
   }
}






after compiling this is generating an error in line43 that it is an invalid method declaration and reutrn type is required....plz help me !!!!!


TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: i have a problem in this program...plz help
PostPosted: Wed Jul 29, 2009 10:20 am 
Offline
Mastermind
User avatar

Joined: Tue Mar 27, 2007 10:55 pm
Posts: 2103
Location: Earth
Has thanked: 39 time
Have thanks: 57 time
you have to specify the return type of the function ( void , int , String .... etc ) .

_________________
Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 2 posts ] 
Quick reply


  


 Similar topics
 Topic title   Forum   Author   Comments 
 C C++ program help using class  C-C++  Anonymous  0
 how to write a "c' program on fibannoic series  C-C++  Anonymous  2
 problem with JcheckBox method  Java  Anonymous  1
 Java Program for communicate PC and Mobile  Java  ArunaR  3
 client server problem  Java  bablu1790  0

All times are UTC [ DST ]


Users browsing similar posts

Users browsing this forum: Google Adsense [Bot] and 4 guests



Jump to:  
Previous Question | Next Question 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team