Results 1 to 3 of 3
  1. #1
    David1234 is offline Member
    Join Date
    Aug 2012
    Posts
    3
    Rep Power
    0

    Default Please help with simple applet.

    Hey guys this is my first post. I am very new to java and have had trouble understanding this program out of a textbook, hopefully you guys can help me understand it.

    package squareint;

    import java.awt.Container;
    import javax.swing.*;

    public class SquareInt extends JApplet
    {


    public void init()
    {
    String output = "";

    JTextArea outputArea = new JTextArea( 10, 20 );

    Container c = getContentPane();

    c.add( outputArea );

    int result;

    for( int x = 1; x <=10; x++)
    {
    result = square( x );
    output += "The square of " + x +
    " is " + result + "\n";
    }

    outputArea.setText( output );
    }

    public int square( int y )
    {
    return y * y;
    }
    }

    The parts that i am stuck on are:
    String output = "" (the textbook hasn't said anything about it)
    Container c = getContentPane() (don't know what a container is, or what getContentPane() means)
    result = square( x ) (where does square come from)
    public int square( int y) (i think this is a method or something i haven't ever created two in one program before what does it mean public int, and what is y?)

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

    Default Re: Please help with simple applet.

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default Re: Please help with simple applet.

    Java Code:
    String output = "";
    This is a declaration with an initialization.
    Java Code:
    Container c = getContentPane();
    A container is a somewhat generic class for holding GUI components, and getContentPage returns the ContentPane (which is a container) for the given object receiving the call.
    (where does square come from)
    it comes from:
    Java Code:
    public int square( int y )
    {
    return y * y;
    }
    public int, and what is y?
    public is the scope, int is the return type, y is a parameter.

    Sounds like before you go any further, you need to learn the essential parts of a java program:
    - primitive types
    - class structure
    - method structure
    - statement structure
    - scope
    - control structures
    etc....

    Time to do some reading!

Similar Threads

  1. Error while running simple applet
    By diamonddragon in forum Java Applets
    Replies: 15
    Last Post: 02-04-2012, 07:10 AM
  2. A (very) simple question about NumberFormat in Applet
    By calnastic in forum New To Java
    Replies: 2
    Last Post: 06-17-2011, 03:34 AM
  3. Simple Applet not reading non *.txt file
    By dynamic3d in forum Java Applets
    Replies: 2
    Last Post: 08-14-2010, 11:45 PM
  4. Super simple table applet
    By danwoods in forum New To Java
    Replies: 4
    Last Post: 10-21-2009, 12:58 PM
  5. I need simple java applet
    By silvia in forum Java Applets
    Replies: 4
    Last Post: 01-27-2008, 07:50 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
  •