Results 1 to 6 of 6

Thread: Need help with errors in simple code.

  1. #1

    Thread Starter
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336

    Need help with errors in simple code.

    Hey guys I am new to Java programming and I making a simple program to test out a java applett. I keep getting errors that say

    "C:\...\Test.java:14: <identifier> expected
    container.add(outputArea);
    ^
    C:\...\Test.java:17: <identifier> expected
    outputArea.setText("dfgdgdfg");"

    with my code, but I cannot figure out why. Can someone look at my code and see if they see anything obvious or not so obvious?

    Thanks!

    PHP Code:
    import java.awt.*;
    import javax.swing.*;



    public class 
    Test extends JApplet {



    JTextArea outputArea = new JTextArea();

    Container container  getContentPane();

    container.add(outputArea);

    outputArea.setText("dfgdgdfg");



    Last edited by Arc; Oct 23rd, 2005 at 06:47 PM.
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


  2. #2
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: Need help with errors in simple code.

    Try putting all that code in a constructor:

    Code:
     import java.awt.*;
    import javax.swing.*;
    
    
    
    public class Test extends JApplet {
    
    
       public Test()
       {
           JTextArea outputArea = new JTextArea();
    
           Container container  = getContentPane();
    
           container.add(outputArea);
    
           outputArea.setText("dfgdgdfg");
       }
    
    }

  3. #3

  4. #4
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    Re: Need help with errors in simple code.

    It's also still vaild to define a main() method. In your case when it terminates the there will still be one thread executing in the jvm. The awt.

  5. #5
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    Re: Need help with errors in simple code.

    Just to add. About applets & constructors. One reason to use init() instead of a constructor is that some methods fail to work inside of an applets constructor like the image loading methods.

  6. #6
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: Need help with errors in simple code.

    Oops, sorry. Was thinking this was a JFrame instead of applet.

Posting Permissions

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



Click Here to Expand Forum to Full Width