Results 1 to 5 of 5
 01312013, 02:45 PM #1Member
 Join Date
 Jan 2013
 Posts
 2
 Rep Power
 0
[SOLVED]Eclipse  Start: Applet not initialized  Help?
I'm new to programming with Java and using eclipse.
I have recently started to work with a Tic Tac Toe game in Java via Eclipse, however, when I attempt to run the code in an applet via the Eclipse programme, a white window loads up with the message: "Start: Applet not initialized" located in the bottom left of the screen.
Since I'm new to using both Eclipse and Java, I'm having trouble troubleshooting what the problem is, and I was wondering if someone could possibly point me in the right direction of the error?
Thanks in advance for your time.
Error has been fixed.Last edited by HausOf; 01312013 at 04:20 PM.
 01312013, 03:08 PM #2Member
 Join Date
 Jan 2013
 Location
 Berlin
 Posts
 4
 Rep Power
 0
Re: Eclipse  Start: Applet not initialized  Help?
Hi HausOf,
I would to suggest to implement first very small code samples. The first thing i saw was that you tried to assign a label to a button.
JButton wins;
wins = new JLabel("Won: " +gamesWon);
So please look more to the compiler erros in your IDE, or if it is to complex for you at the beginning, start with the basics.
Best
 01312013, 03:09 PM #3Moderator
 Join Date
 Apr 2009
 Posts
 12,370
 Rep Power
 21
Re: Eclipse  Start: Applet not initialized  Help?
Please use [code] tags[/code] not [quote] tags [/quote] when posting code.
That's far too much code for most people here to go through...
How are you executing this in Eclipse?
If you are running this as a Java application then it will fail as it is a Java applet.Please do not ask for code as refusal often offends.
** This space for rent **
 01312013, 03:16 PM #4Member
 Join Date
 Jan 2013
 Posts
 2
 Rep Power
 0
Re: Eclipse  Start: Applet not initialized  Help?
Ah, thank you. I didn't spot that. I've fixed that error and have looked back through the code for any other little errors similar to that, but to no avail. The applet is still loading as a blank window.
My apologies  I have now surrounded the code with the respective tags. I'm also running it as an applet, rather than an application.
EDIT: I've managed to fix it. I missed out a space in one of the functions, after rereading all the code I found it! One small error can mess the whole thing up..Last edited by HausOf; 01312013 at 04:18 PM.
 01312013, 05:16 PM #5
Re: Eclipse  Start: Applet not initialized  Help?
Don't remove content and make the thread useless. That's against the spirit of a forum.
I'm posting the code you removed.
db
Code:
Java Code:import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.applet.Applet; public class TicTacToe extends JApplet implements ActionListener { JButton squares[]; JButton newGameButton; JLabel score; JLabel wins; JLabel loses; JLabel ties; int emptySquaresLeft=9; int gamesWon=0; int gamesLost=0; int gamesTied=0; public static void main(String[] args){ //.. Create and initialize the applet JApplet theApplet = new TicTacToe(); theApplet.init(); //Needed if overridden in applet theApplet.start(); //Needed if overridden in applet //.. Create a window (JFrame) and make applet the content pane JFrame window = new JFrame ("Tic Tac Toe Applet and Application"); window.setContentPane(theApplet); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLO SE); //Arrange the components window.setSize(300,300); window.setVisible(true); //Make the window visible } // ====================== Applet Constructor public TicTacToe() { add(new JLabel("This is both an Applet and Application")); } /** * init mrthod is the applets constructor */ public void init(){ //Get the applet's content pane  //all window components go there Container appletContent = this.getContentPane(); resize(300,300); //Set the pplet's layout manager, font and background color. appletContent.setLayout(new BorderLayout()); appletContent.setBackground(Color.CYAN); //Create the button new Game and register it //with the action listener newGameButton=new JButton("New Game"); newGameButton.addActionListener(this); wins = new JLabel("Won: " +gamesWon); loses=new JLabel("Lost: " +gamesLost); ties=new JLabel("Tied: "+gamesTied); JPanel topPanel = newJPanel(); topPanel.setLayout(new GridLayout()); topPanel.add(wins); topPanel.add(newGameButton); newGameButton.setHorizontalAlignment(JButton.CENTE R); newGameButton.setSize (3,3); topPanel.add(loses); appletContent.add(topPanel, "North"); JPanel centerPanel=new JPanel(); centerPanel.setLayout(new GridLayout(3,3)); //FIX CODE appletContent.add(centerPanel, "Center"); score=new JLabel("Your Turn!"); appletContent.add(score, "South"); // Create an array to hold references to 9 buttons squares=new JButton[9]; //Instantiate the buttons, store the references // to them in the array, register them with the //listeners, paint them in orange and add to panel for(int i=0; i<9; i++){ squares[i]=new JButton(); //INSERT CODE HERE!! squares[i].setBackground(Color.ORANGE); centerPanel.add(squares[i]); // Create the frame and set its content pane JFrame frame = new JFrame("TicTacToe"); } } /** * This method will process all action events * @param Action Event object */ public void actionPerformed(ActionEvent e){ JButton theButton = (JButton) e.getSource(); //Is this a New Game Button? if (theButton ==newGameButton){ for(int i=0; i<9; i++){ squares[i].setEnabled(true); squares[i].setText(""); squares[i].setBackground(Color.ORANGE); } emptySquaresLeft=9; score.setText("Your Turn!"); newGameButton.setEnabled(false); return; // EXIT THE METHOD HERE } String winner = ""; //Is this one of the squares? for(int i=0; i<9; i++){ if (theButton == squares[i]){ squares[i].setText("X"); //squares[i].setEnabled(false); squares[i].setEnabled(true); winner = lookForWinner; if(!"".equals(winner)){ endTheGame(); }else { computerMove(); winner = lookForWinner(); if (!"".equals(winner)){ endTheGame(); } } break; } } //END LOOP if (winner.equals("X")){ score.setText("You Won!"); gamesWon++; wins.setText(" Won: " +gamesWon); }else if (winner.equals("O")){ score.setText("You Lost!"); gamesLost++; loses.setText(" Lost: "+gamesLost); }else if (winner.equals("T")){ gamesTied++; score.setText("It's a tie!"); } } //END ACTIONPERFORMED /** * This methid is called after every move to see * if we have a winner. * It checks every row, column and diagonal to find out * three squares with the same label (other than blank) * @return "X", "O", "T" for tie or "" for no winner */ String lookForWinner(){ String theWinner = ""; emptySquaresLeft; if (emptySquaresLeft==0){ return "T"; //It's a tie } //Check the row 1  array elements 0,1,2 if(!squares[0].getText().equals("") && squares[0].getText().equals(squares[1].getText()) && squares[0].getText().equals(squares[2].getText()) ) { theWinner = squares[0].getText(); highlightWinner(0,1,2); //Check the row 2  array elements 3,4,5 }else if(!squares[3].getText().equals("") && squares[3].getText().equals(squares[4].getText()) && squares[3].getText().equals(squares[5].getText()) ) { theWinner = squares[3].getText(); highlightWinner(3,4,5); //Check the row 3  array elements 6,7,8 }else if(!squares[6].getText().equals("") && squares[6].getText().equals(squares[7].getText()) && squares[6].getText().equals(squares[8].getText()) ) { theWinner = squares[6].getText(); highlightWinner(6,7,8); //Check the column 1  0,3,6 }else if(!squares[0].getText().equals("") && squares[0].getText().equals(squares[3].getText()) && squares[0].getText().equals(squares[6].getText()) ) { theWinner = squares[0].getText(); highlightWinner(0,3,6); // Check the column 2  array elements 1,4,7 }else if(!squares[1].getText().equals("") && squares[1].getText().equals(squares[4].getText()) && squares[1].getText().equals(squares[7].getText()) ) { theWinner = squares[1].getText(); highlightWinner(1,4,7); // Check the column 3  2,5,8 }else if(!squares[2].getText().equals("") && squares[2].getText().equals(squares[5].getText()) && squares[2].getText().equals(squares[8].getText()) ) { theWinner = squares[2].getText(); highlightWinner(2,5,8); //Check the first diagonal  array elements 0,4,8 }else if(!squares[0].getText().equals("") && squares[0].getText().equals(squares[4].getText()) && squares[0].getText().equals(squares[8].getText()) ) { theWinner = squares[0].getText(); highlightWinner(0,4,8); //Check the second diagonal  array elements 2,4,6 }else if(!squares[2].getText().equals("") && squares[2].getText().equals(squares[4].getText()) && squares[2].getText().equals(squares[6].getText()) ) { theWinner = squares[2].getText(); highlightWinner(2,4,6); } return theWinner; } /** * This method applies a set of rules to find * the best computer's move. If a good move * can't be found, it picks a random square. */ void computerMove() { int selectedSquare; //Computer first tries to find an empty //square next to the two squares with "O" to win selectedSquare = findEmptySquare("O"); //If can't find two "O", at least try to stop the //Opponent from making 3 in a row by placing //"O" next to 2 "X". if (selectedSquare == 1){ selectedSquare = findEmptySquare("X"); } //if the selectedSquare if still 1, at least //try to occupy the central square //FIX THIS!! if ( (selectedSquare == 0)&&(squares[4].getText().equals(""))){ selectedSquare=4; } //No luck with the central either... //just get a random square if (selectedSquare == 1){ selectedSquare = getRandomSquare(); } squares[selectedSquare].setText("O"); squares[selectedSquare].setEnabled(true); } /** *This method checks every row, column and diagonal *to see if there are two squares with the same label *and an empty square *@param give X  for the user, and O for the computer *@return the number of the empty square to use. *or the negative 1 coule not find 2 square *with the same label */ int findEmptySquare(String player){ int weight[] = new int[9]; for (int i=0; i<9; i++){ if (squares[i].getText().equals("O")) weight[i] = 1; else if (squares[i].getText().equals("X")) weight[i] = 1; else weight[i] = 0; } int twoWeights = player.equals("O") ? 2 : 2; //See if row 1 has the same 2 squares and a blank if (weight[0] + weight[1] + weight[2] == twoWeights){ if (weight[0] == 0) return 0; else if (weight[1] == 0) return 1; else return 2; } //See if row 2 has the same 2 squares and a blank if (weight[3] + weight[4] + weight[5] == twoWeights){ if (weight[3] == 0) return 3; else if (weight[4] == 0) return 4; else return 5; } //See if row 3 has the same 2 squares and a blank if (weight[6] + weight[7] + weight[8] == twoWeights){ if (weight[6] == 0) return 6; else if (weight[7] == 0) return 7; else return 8; } //See of column 2 has the same 2 squares and a blank if (weight[0] + weight[3] + weight[6] == twoWeights){ if (weight[0] == 0) return 0; else if (weight[3] == 0) return 3; else return 6; } //See if column 2 has the same 2 squares and a blank if (weight[1] + weight[4] + weight[7] == twoWeights){ if (weight[1] == 0) return 2; else if (weight[4] == 0) return 4; else return 7; } //See if column 3 has the same 2 squares and a blank if (weight[2] + weight[5] + weight[8] == twoWeights){ if (weight[2] == 0) return 2; else if (weight[5] == 0) return 5; else return 8; } //See if diagonal 1 has the same 2 squares and a blank if (weight[0] + weight[4] + weight[8] == twoWeights){ if (weight[0] == 0) return 0; else if (weight[4] == 0) return 4; else return 8; } //See if diagonal 2 has the same 2 squares and a blank if (weight[2] + weight[4] + weight[6] == twoWeights){ if (weight[2] == 0) return 2; else if (weight[4] == 0) return 4; else return 6; } //Do not have the same two neightbours return 1; } //End of findEmptySpace /** *This method selects any empty square *@return a randomly selected square number */ int getRandomSquare(){ boolean gotEmptySquare = false; int selectedSquare = 1; do { selectedSquare = (int) (Math.random()*9); if(squares[selectedSquare].getText().equals("")){ gotEmptySquare = true; //LOOPING ENDS HERE! } }while(!gotEmptySquare); return selectedSquare; } //END RANDOM SQUARE SELECTION /** *This method highlights the winning line *@param first square to highlight *@param second square to highlight *@param third square to highlight */ void highlightWinner(int win1, int win2, int win3){ squares[win1].setBackground(Color.CYAN); squares[win2].setBackground(Color.CYAN); squares[win3].setBackground(Color.CYAN); } /** *Disables squares and enable New Game Button */ void endTheGame(){ for (int i=0; i<9; i++){ squares[i].setEnabled(false); } //Enable New Game Button // newGameButton.setEnabled(true); } }
If you're forever cleaning cobwebs, it's time to get rid of the spiders.
Similar Threads

Start: Applet not initialized
By Djblacklantern in forum Java AppletsReplies: 2Last Post: 11152012, 09:24 AM 
Start Swing GUI program by Java Web Start with IE in Eclipse debug mode
By albertkao in forum EclipseReplies: 1Last Post: 01182011, 07:27 PM 
Applet won't start
By David2010 in forum New To JavaReplies: 5Last Post: 07142009, 05:32 AM 
[SOLVED] "start: applet not initialized"
By DenniGa in forum Java AppletsReplies: 3Last Post: 02242009, 03:10 AM 
run on eclipse not in web start
By hanizainol in forum New To JavaReplies: 0Last Post: 06112008, 03:31 AM
Bookmarks