Results 1 to 7 of 7
  1. #1
    Join Date
    Jun 2010
    Posts
    29
    Rep Power
    0

    Default [SOLVED]Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException

    Hy i am getting this error!
    at TicTacToe.<init>(TicTacToe.java:59)
    at Starting$1.actionPerformed(Starting.java:77)
    at javax.swing.AbstractButton.fireActionPerformed(Abs tractButton.java:1995)
    at javax.swing.AbstractButton$Handler.actionPerformed (AbstractButton.java:2318)
    at javax.swing.DefaultButtonModel.fireActionPerformed (DefaultButtonModel.java:387)
    at javax.swing.DefaultButtonModel.setPressed(DefaultB uttonModel.java:242)
    at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(BasicButtonListener.java:236)
    at java.awt.Component.processMouseEvent(Component.jav a:6263)
    at javax.swing.JComponent.processMouseEvent(JComponen t.java:3267)
    at java.awt.Component.processEvent(Component.java:602 8)
    at java.awt.Container.processEvent(Container.java:204 1)
    at java.awt.Component.dispatchEventImpl(Component.jav a:4630)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2099)
    at java.awt.Component.dispatchEvent(Component.java:44 60)
    at java.awt.LightweightDispatcher.retargetMouseEvent( Container.java:4574)
    at java.awt.LightweightDispatcher.processMouseEvent(C ontainer.java:4238)
    at java.awt.LightweightDispatcher.dispatchEvent(Conta iner.java:4168)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2085)
    at java.awt.Window.dispatchEventImpl(Window.java:2478 )
    at java.awt.Component.dispatchEvent(Component.java:44 60)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 599)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:269)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:184)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:174)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:169)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:161)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:122)
    Last edited by Cluster Storm; 06-07-2010 at 05:45 PM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Your error is that you're trying to use a null object on line 59 of your TicTacToe class. Since it's Sunday and I left my crystal ball at work, I can't magically see and inspect your code. You're going to either have to figure this out for yourself (usually inspecting the objects on that line will show you the error), or post your code, because without your code we have absolutely no idea what's null.

  3. #3
    Join Date
    Jun 2010
    Posts
    29
    Rep Power
    0

    Default

    Here is the code . . . TicTacToe is the other class i am creating the object of that . . .

    Java Code:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.UIManager.*;
    
    public class Starting {
    		
    		static final JFrame frame = new JFrame( "Tic Tac Toe Game" ); 
    		private Container container;
    		private JLabel backgroundImageJLabel, promptTextJLabel;
    		private JRadioButton twoPlayerJRadioButton, computerJRadioButton;
    		private ButtonGroup radioGroup;
    		private JButton okButton;	
    				
    		public Starting( )
    		{	
    						
    			frame.setSize( 500, 290 );
    			frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    			frame.setLocationRelativeTo( null );
    			frame.setResizable( false );
    			frame.setVisible( true );		
    			
    			container = frame.getContentPane();
    			
    			backgroundImageJLabel = new JLabel();
    			backgroundImageJLabel.setIcon( new ImageIcon( "backgroundImage.jpg" ) );
    			
    			promptTextJLabel = new JLabel( "Select the Gameplay which you want" );
    			promptTextJLabel.setBounds( 60, 70, 260, 30 );
    			promptTextJLabel.setFont( new Font( "Calibri", Font.BOLD, 15 ) );
    			
    			twoPlayerJRadioButton = new JRadioButton( "Two Players", true );
    			twoPlayerJRadioButton.setBounds( 60, 90, 100, 30 );
    			
    			computerJRadioButton = new JRadioButton( "Play With Computer", false );
    			computerJRadioButton.setBounds( 200, 90, 150, 30 );
    			
    			okButton = new JButton( "Ok" );
    			okButton.setFont( new Font( "Calibri", Font.BOLD, 13 ) );
    			okButton.setBounds( 350, 160, 100, 30 );
    			
    			// create logical relationship between JRadioButtons
    			radioGroup = new ButtonGroup();
    			radioGroup.add( twoPlayerJRadioButton );
    			radioGroup.add( computerJRadioButton );
    			
    			container.add( okButton );
    			container.add( computerJRadioButton );
    			container.add( twoPlayerJRadioButton );
    			container.add( promptTextJLabel );
    			container.add( backgroundImageJLabel );
    			
    					
    			
    			okButton.addActionListener( 
    				
    				new ActionListener()
    				{
    					public void actionPerformed( ActionEvent e )
    					{
    						//if( twoPlayerJRadioButton.isSelected() )
    						//{	
    							new TicTacToe( frame );
    							frame.setVisible( false );
    						//}	
    						//else if( computerJRadioButton.isSelected() )	
    						//		System.out.println();
    						//else							
    						//	JOptionPane.showMessageDialog( null, "You hav'nt selected Gameplay. Please select the Gameplay!",
    						//										 "Error Message", JOptionPane.ERROR_MESSAGE );
    							
    					} // end method
    					
    				} // end ActionListener
    				
    			); // end okButton.addActionListener
    		
    		/*	twoPlayerJRadioButton.addItemListener(
    				
    				new ItemListener()
    				{
    					public void itemStateChanged( ItemEvent event )
    					{
    						
    					} // end method
    					
    				} // end ItemListener
    			
    			); // end twoPlayerJRadioButton.addItemListener
    			
    			computerJRadioButton.addItemListener(
    				
    				new ItemListener()
    				{
    					public void itemStateChanged( ItemEvent event )
    					{
    						
    					} // end method
    					
    				} // end ItemListener
    			
    			); // end computerJRadioButton.addItemListener
    			*/
    		} // end constructor	
    	
    	public static void main (String[] args) {
    		
    		new Starting();
    		
    		
    	} // end main
    	
    } // end class Starting
    Moderator Edit: Code tags added
    Last edited by Fubarable; 06-06-2010 at 08:48 PM. Reason: Moderator Edit: Code tags added

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Cluster Storm View Post
    Here is the code . . . TicTacToe is the other class i am creating the object of that . . .
    But it appears by the error message that the problem lies in the TicTacToe class, so you may wish to post that. Oh, I added code tags to your post and I ask that you please use code tags with your next post.

    To do this, highlight your pasted code (please be sure that it is already formatted when you paste it into the forum; the code tags don't magically format unformatted code) and then press the code button, and your code will have tags.

    Another way to do this is to manually place the tags into your code by placing the tag [cod&#101;] above your pasted code and the tag [/cod&#101;] below your pasted code like so:

    Java Code:
    [cod&#101;]
      // your code goes here
      // notice how the top and bottom tags are different
    [/cod&#101;]
    Much luck!

  5. #5
    Join Date
    Jun 2010
    Posts
    29
    Rep Power
    0

    Default

    Code of TicToaToe class
    Java Code:
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    import java.io.File;
    import java.util.Arrays;
    import java.awt.Desktop;
    
    
    
    
    public class TicTacToe extends Panel {
    	
    	final JFrame frameChild, frameParent;
    	JFrame frameCopyChild, boardMaking;
    	JMenuBar menubar;
    	JMenu menuFile, menuBoard, menuHelp;
    	JMenuItem itemNewGame, itemExit, itemChoseColor, itemStrategy, itemAbout;
    	JTextField player;	
    	ImageIcon iconCross, iconCheck;
    	JPanel panelButton, panelStatus;
    	JLabel labelStatusBar ;
    	char whoseTurn = 'x';
    	JButton buttons[] = new JButton[10];
    	char cell[] = new char[10];
    	int check[] = new int[10];
    	static File pdf;
    	Image img;
    		
    	public TicTacToe( JFrame parent ){
    		
    		frameChild     = new JFrame( "Tic Tac Toe" ); 
    		menubar        = new JMenuBar();
    		menuFile       = new JMenu( "Game" );
    		menuBoard      = new JMenu( "Board" );
    		menuHelp       = new JMenu( "Help" );
    		itemNewGame    = new JMenuItem( "New Game" );
    		itemExit       = new JMenuItem( "Exit" );
    		itemChoseColor = new JMenuItem( "Chose Colour" );
    		itemStrategy   = new JMenuItem( "Strategy Guide" );
    		itemAbout      = new JMenuItem( "About" );
    		panelButton    = new JPanel( null );
    		panelStatus    = new JPanel();
    		labelStatusBar = new JLabel( start.textPlayer_X.getText() );
    		iconCross      = new ImageIcon( "Cross.jpg" );
    	  	iconCheck      = new ImageIcon( "Check.jpg" );
    	  	buttons[1]     = new JButton();
    	  	buttons[2]     = new JButton();
    	  	buttons[3]     = new JButton();
    	  	buttons[4]     = new JButton();
    	  	buttons[5]     = new JButton();
    	  	buttons[6]     = new JButton();
    	  	buttons[7]     = new JButton();
    	  	buttons[8]     = new JButton();
    	  	buttons[9]     = new JButton();		
    		
    		frameChild.setVisible( true );
    		frameChild.setSize( 650,600 );
    		frameChild.setResizable( false );
    		frameChild.setLocationRelativeTo(null);
    		frameChild.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    				
    		frameParent = parent;
    		frameCopyChild = frameChild;
    		
    		frameChild.setJMenuBar( menubar );				
    		
    		menubar.add( menuFile );		
    		menuFile.add( itemNewGame );		
    		menuFile.add( itemExit );
    		
    			
    		menubar.add( menuBoard  );    	
    		menuBoard.add( itemChoseColor );				
    			
    		menubar.add( menuHelp );		
    		menuHelp.add( itemStrategy );		
    		menuHelp.add( itemAbout );
          	
          	frameChild.add( labelStatusBar, BorderLayout.SOUTH );
          	
          	panelButton.setBackground( Color.gray );
    	  	
    	  	buttons[1].setBounds( 128,85,128,128 );
    	  	buttons[2].setBounds( 256,85,128,128 );
    	  	buttons[3].setBounds( 384,85,128,128 );
    	  	buttons[4].setBounds( 128,213,128,128 );
    	  	buttons[5].setBounds( 256,213,128,128 );
    	  	buttons[6].setBounds( 384,213,128,128 );
    	  	buttons[7].setBounds( 128,341,128,128 );
    	  	buttons[8].setBounds( 256,341,128,128 );
    	  	buttons[9].setBounds( 384,341,128,128);
    	  		  		  	
    	  	panelButton.add( buttons[1] );
    	  	panelButton.add( buttons[2] );
    	  	panelButton.add( buttons[3] );
    	  	panelButton.add( buttons[4] );
    	  	panelButton.add( buttons[5] );
    	  	panelButton.add( buttons[6] );
    	  	panelButton.add( buttons[7] );
    	  	panelButton.add( buttons[8] );
    	  	panelButton.add( buttons[9] );
    	  		  	
    	  		  	
    	  	frameChild.add( panelButton );
    	    
    	    for ( int i = 0 ; i < 9 ; i++ )
    	    	cell[i] = '0';
    	    
    	    class openFile implements ActionListener{
    	    	public void actionPerformed ( ActionEvent e )
    	    	{
    	    		//pdf = new menuFile( "07.pdf" );
    	    		//Desktop desk = new Desktop();
    	    		//Desktop.open( pdf );
    	    		// Desktop.getDesktop().open(new menuFile( "07.pdf" ));
    	    		 try                                      //try statement
            {
    
    	    		Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + "Tic Tac Toe itemStrategy.pdf");   //open the menuFile chart.pdf
            }
            catch(Exception exp )
            {
            	System.out.println("Error" + exp );
            }
    
    	    		
    	    	}
    	    }
    	     
    	    itemStrategy.addActionListener( new openFile() ); 
    	       		
    //---------------------------------------------------------------------------------------		    		
    		class exitaction implements ActionListener{
    			public void actionPerformed	( ActionEvent e ){
    			System.exit(0);	
    				
    			}
    		}
    		
    		itemExit.addActionListener( new exitaction() );
    		
    //---------------------------------------------------------------------------------------		
    		class colour implements ActionListener{
    			public void actionPerformed ( ActionEvent e ){
    			
    		//	Container container = panelButton.getContentPane();
    			Color color = JColorChooser.showDialog(panelButton, "dfsd", panelButton.getBackground());
    				
    				if( color != null)
    					panelButton.setBackground( color );
    					//ontainer.setBackground(color);
    			
    			}
    		}
    		
    		itemChoseColor.addActionListener( new colour() );
    //---------------------------------------------------------------------------------------		
    		class New_Game implements ActionListener{
    			public void actionPerformed ( ActionEvent e ){
    				
    				frameParent.setVisible(true);
    				frameCopyChild.dispose();
    				frameCopyChild = null;
    			}
    		}
    		
    		itemNewGame.addActionListener( new New_Game() );
    //---------------------------------------------------------------------------------------		
    	   
    	  	class but implements ActionListener{
    	  		  			  		
    	  		public void actionPerformed ( ActionEvent e ){
    	  			  	
    	  			  						
    	  			  		
    	  		if( buttons[1] == e.getSource() ){
    						  			
    	  				if( check[1] == 0 ){
    	  				
    		  				buttons[1].setIcon( ( ( whoseTurn == 'x' ) ? iconCross : iconCheck ) );
    		  				//buttons[1].setEnabled( false );
    		  				cell[1] = whoseTurn;//Character.toString( whoseTurn );		  				
    		  				
    		  				if ( labelStatusBar.getText().equals(  start.textPlayer_X.getText() ) )
    		  					labelStatusBar.setText( start.textPlayer_O.getText() );
    		  				else
    		  					labelStatusBar.setText( start.textPlayer_X.getText() );
    		  				
    		  				if ( isWon() ) {
    	                    labelStatusBar.setText( whoseTurn + " won! The game is over");
    		                whoseTurn = ' '; // Game is over
    		                }
    		 				else if (isFull()) {
    		                labelStatusBar.setText("Draw! The game is over");
    		                whoseTurn = ' '; // Game is over
    		                }
    		  				
    		  				whoseTurn =  ( whoseTurn == 'x' )  ? 'o': 'x';	  			  						  				
    		  					
    		  					
    						
    						check[1]++;	  				
    	  				
    	  				}
    	  		}				
    	  		
    			if ( buttons[2] == e.getSource() ){				
    					if ( check[2] == 0 ){
    									
    						buttons[2].setIcon( ( ( whoseTurn == 'x' ) ? iconCross: iconCheck ) );
    		  				//buttons[2].setEnabled( false );
    		  				
    		  				cell[2] = whoseTurn;//Character.toString( whoseTurn );
    		  				if ( labelStatusBar.getText().equals(  start.textPlayer_X.getText() ) )
    		  					labelStatusBar.setText( start.textPlayer_O.getText() );
    		  				else
    		  					labelStatusBar.setText( start.textPlayer_X.getText() );
    		  				
    		  				if ( isWon() ) {
    	                    labelStatusBar.setText( whoseTurn + " won! The game is over");
    		                whoseTurn = ' '; // Game is over
    		                }
    		 				else if (isFull()) {
    		                labelStatusBar.setText("Draw! The game is over");
    		                whoseTurn = ' '; // Game is over
    		                }
    		  	
    		  						  				
    		  				whoseTurn =  ( whoseTurn == 'x' ) ? 'o': 'x';
    		  				
    		  		
    		  				
    		  				check[2]++;
    	  					
    					} // end inner if		  					
    	  		} // end else if
    			if( buttons[3] == e.getSource() ){
    					if ( check[3] == 0 ){
    						buttons[3].setIcon( ( ( whoseTurn == 'x' ) ? iconCross: iconCheck ) );
    		  				//buttons[3].setEnabled( false );
    		  				
    		  				cell[3] = whoseTurn;//Character.toString( whoseTurn );
    		  				
    		  				if ( labelStatusBar.getText().equals(  start.textPlayer_X.getText() ) )
    		  					labelStatusBar.setText( start.textPlayer_O.getText() );
    		  				else
    		  					labelStatusBar.setText( start.textPlayer_X.getText() );
    		  				
    		  				if ( isWon() ) {
    	                    labelStatusBar.setText( whoseTurn + " won! The game is over");
    		                whoseTurn = ' '; // Game is over
    		                }
    		 				else if (isFull()) {
    		                labelStatusBar.setText("Draw! The game is over");
    		                whoseTurn = ' '; // Game is over
    		                }
    		  				
    		  				whoseTurn =  ( whoseTurn == 'x' )  ? 'o': 'x';
    		  				
    						check[3]++;
    					}
    			} // end else if
    			 if ( buttons[4] == e.getSource() ){
    					if( check[4]== 0 ){
    					
    					buttons[4].setIcon( ( ( whoseTurn == 'x' ) ? iconCross: iconCheck ) );
    	  				//buttons[4].setEnabled( false );
    	  				
    	  				cell[4] = whoseTurn;//Character.toString( whoseTurn );
    	  				
    					if ( labelStatusBar.getText().equals(  start.textPlayer_X.getText() ) )
    		  					labelStatusBar.setText( start.textPlayer_O.getText() );
    		  				else
    		  					labelStatusBar.setText( start.textPlayer_X.getText() );
    		  				
    		  				if ( isWon() ) {
    	                    labelStatusBar.setText( whoseTurn + " won! The game is over");
    		                whoseTurn = ' '; // Game is over
    		                }
    		 				else if (isFull()) {
    		                labelStatusBar.setText("Draw! The game is over");
    		                whoseTurn = ' '; // Game is over
    		                }  			
    	  				
    	  				whoseTurn = ( whoseTurn == 'x' )  ? 'o': 'x';
    	  				
    	  									
    					check[4]++;
    					}
    			} // end else if
    			if( buttons[5] == e.getSource() ){
    					
    					if ( check[5] == 0 ){
    					
    					buttons[5].setIcon( ( ( whoseTurn == 'x' ) ? iconCross: iconCheck ) );
    	  				//buttons[5].setEnabled( false );
    	  				
    	  				cell[5] = whoseTurn;//Character.toString( whoseTurn );
    	  				
    	  				if ( labelStatusBar.getText().equals(  start.textPlayer_X.getText() ) )
    		  					labelStatusBar.setText( start.textPlayer_O.getText() );
    		  				else
    		  					labelStatusBar.setText( start.textPlayer_X.getText() );
    		  				
    		  				if ( isWon() ) {
    	                    labelStatusBar.setText( whoseTurn + " won! The game is over");
    		                whoseTurn = ' '; // Game is over
    		                }
    		 				else if (isFull()) {
    		                labelStatusBar.setText("Draw! The game is over");
    		                whoseTurn = ' '; // Game is over
    		                }
    	  				
    	  				whoseTurn =  ( whoseTurn == 'x' )  ? 'o': 'x';
    	  				
    	  	
    	  				check[5]++;
    	  				
    					}
    			} // end else if				
    			if ( buttons[6] == e.getSource() ){
    					if( check[6] == 0 ){
    					
    					buttons[6].setIcon( ( ( whoseTurn == 'x' ) ? iconCross: iconCheck ) );
    	  				//buttons[6].setEnabled( false );
    	  				
    	  				cell[6] = whoseTurn; //Character.toString( whoseTurn );
    	  				  				
    	  			if ( labelStatusBar.getText().equals(  start.textPlayer_X.getText() ) )
    		  					labelStatusBar.setText( start.textPlayer_O.getText() );
    		  				else
    		  					labelStatusBar.setText( start.textPlayer_X.getText() );
    		  				
    		  				if ( isWon() ) {
    	                    labelStatusBar.setText( whoseTurn + " won! The game is over");
    		                whoseTurn = ' '; // Game is over
    		                }
    		 				else if (isFull()) {
    		                labelStatusBar.setText("Draw! The game is over");
    		                whoseTurn = ' '; // Game is over
    		                } 				
    	  				
    	  				whoseTurn =  ( whoseTurn == 'x' )  ? 'o': 'x';
    	  				
    
    					
    					check[6]++;
    					}
    			} // end else if
    			if( buttons[7] == e.getSource() ){
    					
    					if( check[7] == 0 ){
    					buttons[7].setIcon( ( ( whoseTurn == 'x' ) ? iconCross: iconCheck ) );
    	  				//buttons[7].setEnabled( false );
    	  				
    	  				cell[7] = whoseTurn;//Character.toString( whoseTurn );
    	  				
    	  			if ( labelStatusBar.getText().equals(  start.textPlayer_X.getText() ) )
    		  					labelStatusBar.setText( start.textPlayer_O.getText() );
    		  				else
    		  					labelStatusBar.setText( start.textPlayer_X.getText() );
    		  				
    		  				if ( isWon() ) {
    	                    labelStatusBar.setText( whoseTurn + " won! The game is over");
    		                whoseTurn = ' '; // Game is over
    		                }
    		 				else if (isFull()) {
    		                labelStatusBar.setText("Draw! The game is over");
    		                whoseTurn = ' '; // Game is over
    		                }
    	  				
    	  				whoseTurn =  ( whoseTurn == 'x' ) ? 'o': 'x';
    
    	  				check[7]++;
    					}
    			} // end else if
    			if ( buttons[8] == e.getSource() ){
    				if( check[8] == 0 ){
    					buttons[8].setIcon( ( ( whoseTurn == 'x' ) ? iconCross: iconCheck ) );
    	  			//	buttons[8].setEnabled( false );
    	  			
    	  				cell[8] = whoseTurn;//Character.toString( whoseTurn );
    	  				
    	  		if ( labelStatusBar.getText().equals(  start.textPlayer_X.getText() ) )
    		  					labelStatusBar.setText( start.textPlayer_O.getText() );
    		  				else
    		  					labelStatusBar.setText( start.textPlayer_X.getText() );
    		  				
    		  				if ( isWon() ) {
    	                    labelStatusBar.setText( whoseTurn + " won! The game is over");
    		                whoseTurn = ' '; // Game is over
    		                }
    		 				else if (isFull()) {
    		                labelStatusBar.setText("Draw! The game is over");
    		                whoseTurn = ' '; // Game is over
    		                }
    	  				  					  			
    	  				whoseTurn =  ( whoseTurn == 'x' )  ? 'o': 'x';
    	  				
    
    	  				check[8]++;
    				}
    			} // end else if
    			if ( buttons[9] == e.getSource() )
    			{		if( check[9] == 0 ){
    					buttons[9].setIcon( ( ( whoseTurn == 'x' ) ? iconCross: iconCheck ) );
    	  				//buttons[9].setEnabled( false );
    	  				
    	  				cell[9] = whoseTurn;// Character.toString( whoseTurn );
    	  				if ( labelStatusBar.getText().equals(  start.textPlayer_X.getText() ) )
    		  					labelStatusBar.setText( start.textPlayer_O.getText() );
    		  				else
    		  					labelStatusBar.setText( start.textPlayer_X.getText() );
    		  				
    		  				if ( isWon() ) {
    	                    labelStatusBar.setText( whoseTurn + " won! The game is over");
    		                whoseTurn = ' '; // Game is over
    		                }
    		 				else if (isFull()) {
    		                labelStatusBar.setText("Draw! The game is over");
    		                whoseTurn = ' '; // Game is over
    		                }
    	  		
    	  				  				
    	  				whoseTurn = ( whoseTurn == 'x' )  ? 'o': 'x';
    	  				
    
    					check[9]++;
    					}
    			} // end else if
    			
    			// Check game status
    			
    			
    						
    			
    			for( char character : cell )
    				System.out.println( character + "Khuch ha sath" );           
    			
    			
    		//for (int i = 0; i < 3; i++){
    		
          	//	for (int j = 0; j < 3; j++)
           	//		System.out.printf("%s", cell[i][j] );
    		//
    	//	System.out.println();
    	//	}		
    									
                            
                
                
                	
    		
    	  		} // end actionPerformed Method
    	  		
    	  		
    	  		
    	  	} // end class but
    	  	
    	  	buttons[1].addActionListener( new but() );
    	  	buttons[2].addActionListener( new but() );
    	  	buttons[3].addActionListener( new but() );
    	  	buttons[4].addActionListener( new but() );
    	  	buttons[5].addActionListener( new but() );
    	  	buttons[6].addActionListener( new but() );
    	  	buttons[7].addActionListener( new but() );
    	  	buttons[8].addActionListener( new but() );
    	  	buttons[9].addActionListener( new but() );
    	  	
    	  
    	  
       	 
    	} // end constructor
    
    public boolean isFull() {
    	
       // String empty = "null" ;
        System.out.print( "Cell se pehle " );
        
        for (int i = 1; i < 9; i++)
          //for (int j = 0; j < 3; j++)
             if ( cell[i] == '0' )  
           		 return false;
             
            		
    	return true;
        
    }
    
    public boolean isWon( ) {
        
        //String next = Character.toString(token) ;
        //System.out.printf( "\n\n%s Ye convert ho gaya ha\n", token );
        //try{
        
        //if( cell[0][0].equalsIgnoreCase( whoseTurn )){
        
        //	System.out.println( "Ye chal gaya ha " );
        	
        	//for (int i = 0; i < 3; i++)
          	  //		b[i].setEnabled( false );
        	
        //	return true;
        //}
       // catch( Exception e )
        //{
        //	System.out.println( e.getMessage() );
        //}   
              
          if ( cell[1] == whoseTurn && cell[2] == whoseTurn && cell[3] == whoseTurn ) {
            System.out.println( "\n\nFirst Condition Execute\n" );
                buttons[4].setEnabled( false );
    			buttons[5].setEnabled( false );
              	buttons[6].setEnabled( false );
    			buttons[7].setEnabled( false );
              	buttons[8].setEnabled( false );
    			buttons[9].setEnabled( false );
            return true;
          }
          if ( cell[4] == whoseTurn && cell[5] == whoseTurn && cell[6] == whoseTurn ) {
            System.out.println( "\n\nSecond Condition Execute\n" );
                buttons[1].setEnabled( false );
    			buttons[2].setEnabled( false );
              	buttons[3].setEnabled( false );
    			buttons[7].setEnabled( false );
              	buttons[8].setEnabled( false );
    			buttons[9].setEnabled( false );
            return true;
          }
          if ( cell[7] == whoseTurn && cell[8] == whoseTurn && cell[9] == whoseTurn ) {
            System.out.println( "\n\nThird Condition Execute\n" );
                buttons[1].setEnabled( false );
    			buttons[2].setEnabled( false );
              	buttons[3].setEnabled( false );
    			buttons[4].setEnabled( false );
              	buttons[5].setEnabled( false );
    			buttons[6].setEnabled( false );
            return true;
            
          }
    
       
          
          if ( cell[1] == whoseTurn && cell[4] == whoseTurn && cell[7] == whoseTurn ) {  
            System.out.println( "\n\nfourth Condition Execute\n" );
            
                buttons[2].setEnabled( false );
    			buttons[3].setEnabled( false );
              	buttons[5].setEnabled( false );
    			buttons[6].setEnabled( false );
              	buttons[8].setEnabled( false );
    			buttons[9].setEnabled( false );
            return true;
          }
          
          if ( cell[2] == whoseTurn && cell[5] == whoseTurn && cell[8] == whoseTurn ) {  
            System.out.println( "\n\nfifth Condition Execute\n" );
                buttons[1].setEnabled( false );
    			buttons[3].setEnabled( false );
              	buttons[4].setEnabled( false );
    			buttons[6].setEnabled( false );
              	buttons[7].setEnabled( false );
    			buttons[9].setEnabled( false );
            
            return true;
          }
          if ( cell[3] == whoseTurn && cell[6] == whoseTurn && cell[9] == whoseTurn ) {  
            System.out.println( "\n\nsixth Condition Execute\n" );
    	        buttons[1].setEnabled( false );
    			buttons[2].setEnabled( false );
              	buttons[4].setEnabled( false );
    			buttons[5].setEnabled( false );
              	buttons[7].setEnabled( false );
    			buttons[8].setEnabled( false );
    	    
    	    return true;
          }
    
       	  if ( cell[1] == whoseTurn && cell[5] == whoseTurn && cell[9] == whoseTurn ) {   
            System.out.println( "\n\nseventh Condition Execute\n" );
              	buttons[2].setEnabled( false );
    			buttons[3].setEnabled( false );
              	buttons[4].setEnabled( false );
    			buttons[6].setEnabled( false );
              	buttons[7].setEnabled( false );
    			buttons[8].setEnabled( false );						        	
            return true;
          }
    
          if ( cell[3] == whoseTurn && cell[5] == whoseTurn && cell[7] == whoseTurn ){
          System.out.println( "\n\neight Condition Execute\n" );
                buttons[1].setEnabled( false );
    			buttons[2].setEnabled( false );
              	buttons[4].setEnabled( false );
    			buttons[6].setEnabled( false );
              	buttons[8].setEnabled( false );
    			buttons[9].setEnabled( false );
           return true;
          }
    	  
    	  System.out.println( "\n\nReturn kerne se pehle\n" );
          return false;
        } // end method isWon
    	 
    
    		
    }

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Wow. Big class. So what is "start"?

  7. #7
    Join Date
    Jun 2010
    Posts
    29
    Rep Power
    0

    Default

    I got my point of error . . . Thanks for just saying start . . .
    Basically start is my previous class, starting is modified form . . . I am changing the look and feel . . .

    Thanks You !!!
    To Be HapPy Always . . . ;)

Similar Threads

  1. Replies: 3
    Last Post: 04-30-2010, 07:44 PM
  2. Replies: 5
    Last Post: 08-26-2009, 11:37 AM
  3. Replies: 6
    Last Post: 08-03-2009, 08:58 PM
  4. Replies: 12
    Last Post: 10-05-2008, 06:52 AM
  5. Replies: 3
    Last Post: 01-29-2008, 01:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •