plz help me n00b here


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 12 of 12

Thread: plz help me n00b here

Threaded View

  1. #1
    Join Date
    Dec 2005
    Posts
    6

    plz help me n00b here

    i started to make a applet for the game whack a mole i named that samckitt but this is giving me probs it compiles but it always give me -ve score i tried to debug this but of no use i think somthing wrong with the repaint method ( i dont know what wrong so i m submitting it so guys plz help me :


    Code:
    import java.awt.*;
    import javax.swing.*;
    import java.util.Random;
    import java.io.*;
    import java.awt.event.*;
    
    public class smackitt extends JApplet implements ActionListener,Serializable 
    {//smackitt
    JButton b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15,b16,b17,b18,b19,b20,b21,b22,b23,b24;
    int val,score=0,b;
    String str1;
    void gen()
    {
    GridLayout g1=new GridLayout(5,5);
    JPanel p1=new JPanel();
    getContentPane().add(p1);
    p1.setLayout(g1);
    
    JButton b0=new JButton("");
    JButton b1=new JButton("");
    JButton b2=new JButton("");
    JButton b3=new JButton("");
    JButton b4=new JButton("");
    JButton b5=new JButton("");
    JButton b6=new JButton("");
    JButton b7=new JButton("");
    JButton b8=new JButton("");
    JButton b9=new JButton("");
    JButton b10=new JButton("");
    JButton b11=new JButton("");
    JButton b12=new JButton("");
    JButton b13=new JButton("");
    JButton b14=new JButton("");
    JButton b15=new JButton("");
    JButton b16=new JButton("");
    JButton b17=new JButton("");
    JButton b18=new JButton("");
    JButton b19=new JButton("");
    JButton b20=new JButton("");
    JButton b21=new JButton("");
    JButton b22=new JButton("");
    JButton b23=new JButton("");
    JButton b24=new JButton("");
    
    p1.add(b0);
    p1.add(b1);
    p1.add(b2);
    p1.add(b3);
    p1.add(b4);
    p1.add(b5);
    p1.add(b6);
    p1.add(b7);
    p1.add(b8);
    p1.add(b9);
    p1.add(b10);
    p1.add(b11);
    p1.add(b12);
    p1.add(b13);
    p1.add(b14);
    p1.add(b15);
    p1.add(b16);
    p1.add(b17);
    p1.add(b18);
    p1.add(b19);
    p1.add(b20);
    p1.add(b21);
    p1.add(b22);
    p1.add(b23);
    p1.add(b24);
    
    b0.addActionListener(this);
    b1.addActionListener(this);
    b2.addActionListener(this);
    b3.addActionListener(this);
    b4.addActionListener(this);
    b5.addActionListener(this);
    b6.addActionListener(this);
    b7.addActionListener(this);
    b8.addActionListener(this);
    b9.addActionListener(this);
    b10.addActionListener(this);
    b11.addActionListener(this);
    b12.addActionListener(this);
    b13.addActionListener(this);
    b14.addActionListener(this);
    b15.addActionListener(this);
    b16.addActionListener(this);
    b17.addActionListener(this);
    b18.addActionListener(this);
    b19.addActionListener(this);
    b20.addActionListener(this);
    b21.addActionListener(this);
    b22.addActionListener(this);
    b23.addActionListener(this);
    b24.addActionListener(this);
    
    Random r=new Random();
    int val;
    val=r.nextInt(24);
    
    switch(val)
    {//switch
    case 0:
    	{
    	b0.setText("SmackIt");
    	}
    	break;
    
    case 1:
    	{
    	b1.setText("SmackIt");
    	}
    	break;
    	
    case 2:
    	{
    	b2.setText("SmackIt");
    	}
    	break;
    case 3:
    	{
    	b3.setText("SmackIt");
    	}
    	break;
    case 4:
    	{
    	b4.setText("SmackIt");
    	}
    	break;
    case 5:
    	{
    	b5.setText("SmackIt");
    	}
    	break;
    case 6:
    	{
    	b6.setText("SmackIt");
    	}
    	break;
    case 7:
    	{
    	b7.setText("SmackIt");
    	}
    	break;
    case 8:
    	{
    	b8.setText("SmackIt");
    	}
    	break;
    case 9:
    	{
    	b9.setText("SmackIt");
    	}
    	break;
    case 10:
    	{
    	b10.setText("SmackIt");
    	}
    	break;
    case 11:
    	{
    	b11.setText("SmackIt");
    	}
    	break;
    case 12:
    	{
    	b12.setText("SmackIt");
    	}
    	break;
    case 13:
    	{
    	b13.setText("SmackIt");
    	}
    	break;
    case 14:
    	{
    	b14.setText("SmackIt");
    	}
    	break;
    case 15:
    	{
    	b15.setText("SmackIt");
    	}
    	break;
    case 16:
    	{
    	b16.setText("SmackIt");
    	}
    	break;
    case 17:
    	{
    	b17.setText("SmackIt");
    	}
    	break;
    case 18:
    	{
    	b18.setText("SmackIt");
    	}
    	break;
    case 19:
    	{
    	b19.setText("SmackIt");
    	}
    	break;
    case 20:
    	{
    	b20.setText("SmackIt");
    	}
    	break;
    case 21:
    	{
    	b21.setText("SmackIt");
    	}
    	break;
    case 22:
    	{
    	b22.setText("SmackIt");
    	}
    	break;
    case 23:
    	{
    	b23.setText("SmackIt");
    	}
    	break;
    case 24:
    	{
    	b24.setText("SmackIt");
    	}
    	break;
    }//switch
    }
    public void init()
    {
    gen();
    b=40;
    }//init
    
    public void start()
    {}
    public void stop()
    {}
    
    public void paint(Graphics g)
    {
    gen();
    }
    
    
    public void actionPerformed(ActionEvent ae) 
    {//actionperformed
    Object obj;
    obj=ae.getSource();
    
         if (obj==b0)  b=0;
    else if (obj==b1)  b=1;
    else if (obj==b2)  b=2;
    else if (obj==b3)  b=3;
    else if (obj==b4)  b=4;
    else if (obj==b5)  b=5;
    else if (obj==b6)  b=6;
    else if (obj==b7)  b=7;
    else if (obj==b8)  b=8;
    else if (obj==b9)  b=9;
    else if (obj==b10)  b=10;
    else if (obj==b11)  b=11;
    else if (obj==b12)  b=12;
    else if (obj==b13)  b=13;
    else if (obj==b14)  b=14;
    else if (obj==b15)  b=15;
    else if (obj==b16)  b=16;
    else if (obj==b17)  b=17;
    else if (obj==b18)  b=18;
    else if (obj==b19)  b=19;
    else if (obj==b20)  b=20;
    else if (obj==b21)  b=21;
    else if (obj==b22)  b=22;
    else if (obj==b23)  b=23;
    else if (obj==b24)  b=24;
    
    try 
    {//try
    if(b==0 && val==0 || b==1 && val==1 || b==2 && val==2 || b==3 && val==3 || b==4 && val==4 
    || obj==b5 && val==5 || obj==b6 && val==6 || obj==b7 && val==7 || obj==b8 && val==8 || obj==b9 && val==9 
    || obj==b10 && val==10 || obj==b11 && val==11 || obj==b12 && val==13 || obj==b14 && val==14 || obj==b15 
    && val==15 || obj==b16 && val==16 || obj==b17 && val==17 || obj==b18 && val==18 || obj==b19 && val==19 
    || obj==b20 && val==20 || obj==b21 && val==21 || obj==b22 && val==22 || obj==b23 && val==23 || obj==b24 && val==24)
    {
    score=score+1;
    getAppletContext().showStatus("Your score is"+score);
    }
    else
    {
    score=score-1;	
    getAppletContext().showStatus("Your score is"+score);
    }
    }//try
    catch(Exception e)
    {
    System.out.println(""+e);
    }
    repaint();
    }//action performed
    }//smackitt

    plz plz help me (
    Last edited by Apocalyp5e; 12-20-2005 at 04:11 PM. Reason: using the code tag

Similar Threads

  1. plz help me to solve this problem
    By ankushbindra in forum ASP.NET
    Replies: 1
    Last Post: 11-30-2005, 06:13 PM
  2. plz help Newbie:object library not registered........
    By cooldude.i2k in forum VB Classic
    Replies: 1
    Last Post: 08-11-2005, 03:16 PM
  3. plz plz plz help me(java)
    By kamon in forum Java
    Replies: 4
    Last Post: 08-10-2005, 10:30 AM
  4. java applet... i'm in a fix, plz help
    By nsbscool in forum Java
    Replies: 1
    Last Post: 05-02-2005, 08:01 AM
  5. Plz Help!!!!
    By Kyle in forum Java
    Replies: 0
    Last Post: 05-14-2003, 03:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center