new bingo card

switching the place of joptionpane

Page 1 of 1

2 Replies - 1332 Views - Last Post: 31 March 2010 - 01:50 AM Rate Topic: -----

#1 mary anne  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 5
  • Joined: 13-March 10

new bingo card

Posted 27 March 2010 - 01:37 AM

good afternoon to all...At last,my problems are over!!Thanks for helping me out for the last time..
I have a new code for the bingo program..if you want,please check it out for you to see..thanks...

 
import java.util.Random;
import javax.swing.*;
import java.lang.*;
import java.awt.*;
import java.awt.event.*;

public class BingoGame extends JFrame implements ActionListener
{
	    JButton tf [],tf2[];
        JTextField tf3,tf4,tf5,tf6,tf7, choice;
        Random group7= new Random();
        JButton resetcard, pick ;
        
        int num []={15,15,15,15,15};
        int [] call = new int[75];
        int ctr = 0,num1=0, num2=0, val, sub;
        int [] history = new int[75];
        int [] bCard = new int[25];
        int numX=1;
        int holder[],holderb[];
        int x, y= 1;
        
        String B= "  B  ";
        String I= "  I  ";
        String N= "  N  ";
        String G= "  G  ";
        String O= "  O  "; 
       
      BingoGame()
        {
                addWindowListener (new WindowAdapter ()
                {
                        public void windowClosing(WindowEvent e)
                        {
                                System.exit(0);
                        }
                });
       
       
        setVisible (true);
        setSize (800,800);
        setLayout (null);
        setBackground(Color.BLUE);
       
        choice = new JTextField();
        add(choice);
        choice.setBounds(247, 600, 50, 25);
        choice.setEditable(false);
       
        tf3=new JTextField();
        tf3=new JTextField(B)/>;
        add (tf3);
        tf3.setBounds(39,37, 60,60);
        tf3.setBackground(Color.yellow);
        tf4=new JTextField();
        tf4=new JTextField(I);
        add (tf4);
        tf4.setBounds(105,37, 60, 60);
        tf4.setBackground(Color.green);
        tf6=new JTextField();
        tf6=new JTextField(N);
        add (tf6);
        tf6.setBounds(171,37, 60, 60);
        tf6.setBackground(Color.yellow);
        tf5=new JTextField(G);
        add (tf5);
        tf5.setBounds(237,37, 60, 60);
        tf5.setBackground(Color.green);
        tf7=new JTextField(O);
        add (tf7);
        tf7.setBounds(303,37, 60, 60);
        tf7.setBackground(Color.yellow);
        tf=new JButton[25];
     
       
        for (int a=0; a<25; a++)
        {
                tf[a]=new JButton();
                add (tf[a]);
                tf[a].setBounds(40+((a/5)*65), 110+((a%5)*65),60, 60);
                
        }
          tf2=new JButton[75];
       
        for (int b=0; b<75; b++)
        {
                tf2[b]=new JButton();
                add (tf2[b]);
                tf2[b].setBounds(450+((b/15)*49),40+((b%15)*49), 49, 49);
                
               
        }
        holder=new int[75];
        holderb=new int[75];
       
        resetcard=new JButton("Reset The Card");
        resetcard.setBackground(Color.magenta);
        pick=new JButton("PICK");
        pick.setBackground(Color.green);
     
        add(resetcard);
        add(pick);
     
        resetcard.addActionListener(this);
        resetcard.setBounds(230,500, 140, 35);
       
        pick.addActionListener(this);
        pick.setBounds(230, 550, 140, 35);

          int n = JOptionPane.showConfirmDialog(null,"Do you want to play Bingo?","",
          JOptionPane.YES_NO_OPTION);
         
          if (n==JOptionPane.YES_OPTION)
            {
                  init();
                  createBoard();
                  createBoardb();
                  validate();
            }
          else
            {
                  System.exit(0);
            }
}    
      public void init()
        {
                for(int a=0; a<75; a++)
                {
                        if (a<=4)
                                num[a]=15;
                                holder[a]=a+1;
                }     
        }
       
        public void createBoard() {
   
          sub=0;
        do{
            val = group7.nextInt(16);
            while(val==bCard[0] || val==bCard[1] || val==bCard[2] || val==bCard[3]
              || val==bCard[4] || val==0 )
            {
                val = group7.nextInt(16);
            }
            bCard[sub] = val;
            sub++;
          }
          while(sub<5);
        sub=5;
        do{
            val = group7.nextInt(31);
            while(val==bCard[5] || val==bCard[6] || val==bCard[7] || val==bCard[8]
              || val==bCard[9] || val==0 || val<16 )
            {
                val = group7.nextInt(31);
            }
            bCard[sub] = val;
            sub++;
          }
          while(sub<10);
        sub=10;
        do{
            val = group7.nextInt(46);
            while(val==bCard[10] || val==bCard[11] || val==bCard[12] || val==bCard[13]
              || val==bCard[14] || val==0 || val<31)
            {
                val = group7.nextInt(46);
            }
            bCard[sub] = val;
            sub++;
          }
          while(sub<15);
        sub=15;
        do{
            val = group7.nextInt(61);
            while(val==bCard[15] || val==bCard[16] || val==bCard[17] || val==bCard[18]
              || val==bCard[19] || val==0 || val<46)
            {
                val = group7.nextInt(61);
            }
            bCard[sub] = val;
            sub++;
          }
          while(sub<20);
        sub=20;
        do{
            val = group7.nextInt(76);
            while(val==bCard[20] || val==bCard[21] || val==bCard[22] || val==bCard[23]
              || val==bCard[24] || val==0 || val<61)
            {
                val = group7.nextInt(76);
            }
            bCard[sub] = val;
            sub++;
          }
          while(sub<25);
         
        for(x=0; x<25; x++)
        {
            tf[x].setText(""+bCard[x]);
        } 
          bCard[12]=0;
          tf[12].setText("free"); 
    }
       
     
public void createBoardb()
    {
   
      for(x=0; x<75; x++)
      {
          history[x] = x+1;
          tf2[x].setText(""+history[x]);
      }
    }
     public void pick()
        {
              resetcard=null;
              num1 = group7.nextInt(76);
             
                          for(x=0; x<75; x++)   
                          {
                              for(sub=0; sub<75; sub++)
                              {
                                  while(num1==call[x] || num1==call[sub]|| num1==0)
                                  num1 = group7.nextInt(76);     
                              }
                          }
                          call[ctr] = num1;
                          choice.setText(""+call[ctr]+"");
                          ctr++;
                         
                          for(x=0;x<75;x++)
                          {
                              if(num1==history[x])
                              {
                                  tf2[x].setBackground(Color.MAGENTA);
                              }
                          }
                          for(x=0; x<25; x++)
                          {
                              if(num1==bCard[x])
                              {
                                  tf[x].setBackground(Color.BLUE);
                                  numX++;
                                  
                                  if(numX==25)
                                  {
                                  	JOptionPane.showMessageDialog(null,
                                  "BINGO!!!!", "Message",
                                      	JOptionPane.WARNING_MESSAGE);
                                      	
                                      	System.exit(0);

                                  }
                              }
                          }
                        }
                           
         public void actionPerformed(ActionEvent e)
        {
       
           
                Random gen= new Random();
                if (e.getSource()==resetcard)
                {
                        init();
                        createBoard();
                }
             
                else if (e.getSource()==pick)
                {
                        pick();
                }
                     
        }
                        
    public static void main (String args[])
        {
              JFrame aFrame= new BingoGame();
              aFrame.setBackground(Color.GREEN);
        }
     
     
}



although this one is a successful program,this program lets you play just ONCE after you run the program and exits automatically.But I have encountering this problem so far:
In the JOptionPane part of the code,instead that part is suppose to be in the last part so that it will loop back to the game itself for you to play it again--that's because we're running out of time,my classmate who helped me on this few days ago,he put it on the start of the of the program.And my problem now is what would I do when transfering that code at the end of the program and should I use a for loop at the end part of the JOptionPane code to return to the game itself when I play it again if I want it to...And I almost forgot,my classmate suggests me to use JLabel for the word B-I-N-G-O instead of String.Is that possible?

GUYS,NEED YOUR HELPING HANDS OUT THERE FOR THE 2ND TIME....

THANK YOU VERY MUCH!!!

Is This A Good Question/Topic? 0
  • +

Replies To: new bingo card

#2 Get.carter()  Icon User is offline

  • New D.I.C Head

Reputation: 5
  • View blog
  • Posts: 31
  • Joined: 17-June 09

Re: new bingo card

Posted 27 March 2010 - 03:34 AM

Hi mary anne, Im on my way out but had a quick look at it...try this.


import java.util.Random;
import javax.swing.*;
import java.lang.*;
import java.awt.*;
import java.awt.event.*;

public class BingoGame extends JFrame implements ActionListener
{
            JButton tf [],tf2[];
        JTextField tf3,tf4,tf5,tf6,tf7, choice;
        Random group7= new Random();
        JButton resetcard, pick ;
        
        int num []={15,15,15,15,15};
        int [] call = new int[75];
        int ctr = 0,num1=0, num2=0, val, sub;
        int [] history = new int[75];
        int [] bCard = new int[25];
        int numX=1;
        int holder[],holderb[];
        int x, y= 1;
        
        String B= "  B  ";
        String I= "  I  ";
        String N= "  N  ";
        String G= "  G  ";
        String O= "  O  "; 
       
      BingoGame()
        {
                addWindowListener (new WindowAdapter ()
                {
                        public void windowClosing(WindowEvent e)
                        {
                                System.exit(0);
                        }
                });
       
       
        setVisible (true);
        setSize (800,800);
        setLayout (null);
        setBackground(Color.BLUE);
       
        choice = new JTextField();
        add(choice);
        choice.setBounds(247, 600, 50, 25);
        choice.setEditable(false);
       
        tf3=new JTextField();
        tf3=new JTextField(B)/>;
        add (tf3);
        tf3.setBounds(39,37, 60,60);
        tf3.setBackground(Color.yellow);
        tf4=new JTextField();
        tf4=new JTextField(I);
        add (tf4);
        tf4.setBounds(105,37, 60, 60);
        tf4.setBackground(Color.green);
        tf6=new JTextField();
        tf6=new JTextField(N);
        add (tf6);
        tf6.setBounds(171,37, 60, 60);
        tf6.setBackground(Color.yellow);
        tf5=new JTextField(G);
        add (tf5);
        tf5.setBounds(237,37, 60, 60);
        tf5.setBackground(Color.green);
        tf7=new JTextField(O);
        add (tf7);
        tf7.setBounds(303,37, 60, 60);
        tf7.setBackground(Color.yellow);
        tf=new JButton[25];
     
       
        for (int a=0; a<25; a++)
        {
                tf[a]=new JButton();
                add (tf[a]);
                tf[a].setBounds(40+((a/5)*65), 110+((a%5)*65),60, 60);
                
        }
          tf2=new JButton[75];
       
        for (int b=0; b<75; b++)
        {
                tf2[b]=new JButton();
                add (tf2[b]);
                tf2[b].setBounds(450+((b/15)*49),40+((b%15)*49), 49, 49);
                
               
        }
        holder=new int[75];
        holderb=new int[75];
       
        resetcard=new JButton("Reset The Card");
        resetcard.setBackground(Color.magenta);
        pick=new JButton("PICK");
        pick.setBackground(Color.green);
     
        add(resetcard);
        add(pick);
     
        resetcard.addActionListener(this);
        resetcard.setBounds(230,500, 140, 35);
       
        pick.addActionListener(this);
        pick.setBounds(230, 550, 140, 35);
        replay();//just here to continue flow of code
      }
      public void replay()
{
          int n = JOptionPane.showConfirmDialog(null,"Do you want to play Bingo?","",
          JOptionPane.YES_NO_OPTION);
         
          if (n==JOptionPane.YES_OPTION)
            {
                  init();
                  createBoard();
                  createBoardb();
                  validate();
            }
          else
            {
                  System.exit(0);
            }}   
      public void init()
        {
                for(int a=0; a<75; a++)
                {
                        if (a<=4)
                                num[a]=15;
                                holder[a]=a+1;
                }     
        }
       
        public void createBoard() {
   
          sub=0;
        do{
            val = group7.nextInt(16);
            while(val==bCard[0] || val==bCard[1] || val==bCard[2] || val==bCard[3]
              || val==bCard[4] || val==0 )
            {
                val = group7.nextInt(16);
            }
            bCard[sub] = val;
            sub++;
          }
          while(sub<5);
        sub=5;
        do{
            val = group7.nextInt(31);
            while(val==bCard[5] || val==bCard[6] || val==bCard[7] || val==bCard[8]
              || val==bCard[9] || val==0 || val<16 )
            {
                val = group7.nextInt(31);
            }
            bCard[sub] = val;
            sub++;
          }
          while(sub<10);
        sub=10;
        do{
            val = group7.nextInt(46);
            while(val==bCard[10] || val==bCard[11] || val==bCard[12] || val==bCard[13]
              || val==bCard[14] || val==0 || val<31)
            {
                val = group7.nextInt(46);
            }
            bCard[sub] = val;
            sub++;
          }
          while(sub<15);
        sub=15;
        do{
            val = group7.nextInt(61);
            while(val==bCard[15] || val==bCard[16] || val==bCard[17] || val==bCard[18]
              || val==bCard[19] || val==0 || val<46)
            {
                val = group7.nextInt(61);
            }
            bCard[sub] = val;
            sub++;
          }
          while(sub<20);
        sub=20;
        do{
            val = group7.nextInt(76);
            while(val==bCard[20] || val==bCard[21] || val==bCard[22] || val==bCard[23]
              || val==bCard[24] || val==0 || val<61)
            {
                val = group7.nextInt(76);
            }
            bCard[sub] = val;
            sub++;
          }
          while(sub<25);
         
        for(x=0; x<25; x++)
        {
            tf[x].setText(""+bCard[x]);
        } 
          bCard[12]=0;
          tf[12].setText("free"); 
    }
       
     
public void createBoardb()
    {
   
      for(x=0; x<75; x++)
      {
          history[x] = x+1;
          tf2[x].setText(""+history[x]);
      }
    }
     public void pick()
        {
              resetcard=null;
              num1 = group7.nextInt(76);
             
                          for(x=0; x<75; x++)   
                          {
                              for(sub=0; sub<75; sub++)
                              {
                                  while(num1==call[x] || num1==call[sub]|| num1==0)
                                  num1 = group7.nextInt(76);     
                              }
                          }
                          call[ctr] = num1;
                          choice.setText(""+call[ctr]+"");
                          ctr++;
                         
                          for(x=0;x<75;x++)
                          {
                              if(num1==history[x])
                              {
                                  tf2[x].setBackground(Color.MAGENTA);
                              }
                          }
                          for(x=0; x<25; x++)
                          {
                              if(num1==bCard[x])
                              {
                                  tf[x].setBackground(Color.BLUE);
                                  numX++;
                                  
                                  if(numX==25)
                                  {
                                  JOptionPane.showMessageDialog(null,
                                  "BINGO!!!!", "Message",
                                  JOptionPane.WARNING_MESSAGE);
                                        
                                        replay();//hope this helps.

                                  }
                              }
                          }
                        }
                           
         public void actionPerformed(ActionEvent e)
        {
       
           
                Random gen= new Random();
                if (e.getSource()==resetcard)
                {
                        init();
                        createBoard();
                }
             
                else if (e.getSource()==pick)
                {
                        pick();
                }
                     
        }
                        
    public static void main (String args[])
        {
              JFrame aFrame= new BingoGame();
              aFrame.setBackground(Color.GREEN);
        }
     
     
}




it just basically creates a replay() method then instead of calling system exit
you call replay(). Hope this helps...btw its lookin good.
Was This Post Helpful? 0
  • +
  • -

#3 mary anne  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 5
  • Joined: 13-March 10

Re: new bingo card

Posted 31 March 2010 - 01:50 AM

To Get.carter():

thanks very much for helping me out,pal....
I'm excited to try this out....
and don't stop helping others in need....

and to those who will put their suggestions here about my recent code problem,thank you!!
:angel:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1