Results 1 to 5 of 5
  1. #1
    HausOf is offline Member
    Join Date
    Jan 2013
    Posts
    2
    Rep Power
    0

    Default [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; 01-31-2013 at 03:20 PM.

  2. #2
    zael is offline Member
    Join Date
    Jan 2013
    Location
    Berlin
    Posts
    4
    Rep Power
    0

    Default 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

  3. #3
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,742
    Rep Power
    19

    Default 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 **

  4. #4
    HausOf is offline Member
    Join Date
    Jan 2013
    Posts
    2
    Rep Power
    0

    Default Re: Eclipse - Start: Applet not initialized - Help?

    Quote Originally Posted by zael View Post
    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
    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.

    Quote Originally Posted by Tolls View Post
    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.
    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 re-reading all the code I found it! One small error can mess the whole thing up..
    Last edited by HausOf; 01-31-2013 at 03:18 PM.

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default 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);
    
     }
     }
    THREAD CLOSED
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Start: Applet not initialized
    By Djblacklantern in forum Java Applets
    Replies: 2
    Last Post: 11-15-2012, 08:24 AM
  2. Replies: 1
    Last Post: 01-18-2011, 06:27 PM
  3. Applet won't start
    By David2010 in forum New To Java
    Replies: 5
    Last Post: 07-14-2009, 05:32 AM
  4. [SOLVED] &quot;start: applet not initialized&quot;
    By DenniGa in forum Java Applets
    Replies: 3
    Last Post: 02-24-2009, 02:10 AM
  5. run on eclipse not in web start
    By hanizainol in forum New To Java
    Replies: 0
    Last Post: 06-11-2008, 03:31 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
  •