Results 1 to 11 of 11
  1. #1
    Grish is offline Member
    Join Date
    Jun 2011
    Posts
    4
    Rep Power
    0

    Default First day of Swing

    Hello everyone!
    It's my first day of learing swing and i'm kinda lost already

    i'm doing everything by the book, using NetBeans

    and it's just not working =(

    Can anyone help?


    import java.awt.*;
    import java.util.*;
    import java.text.*;
    import javax.swing.*;

    public class SS {

    Swing ()
    Error "Invalid method declaration; return type required"

    {
    JFrame mySS = new JFrame();
    mySS.setText("Pes app"); Error "Cannot find symbol; symbol method setText (java.lang.String, location : variable.mySS of type javax.swing.JFrame)
    mySS.setSize (300,300);
    mySS.show(); This Line is striked out
    }




    public static void main(String[] args) {

    new SS ();
    }
    }
    Last edited by Grish; 06-01-2011 at 02:51 PM.

  2. #2
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    5

    Cool

    Quote Originally Posted by Grish View Post
    and it's just not working =(
    Means what? Provide proper details.

    Goldest
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

  3. #3
    Grish is offline Member
    Join Date
    Jun 2011
    Posts
    4
    Rep Power
    0

    Default

    Ok

    So I'm just tring to bring up a simple window with title.
    on line Swing () it's telling me "Invalid method declaration"

    on line mySS.setText("Pes app"); there is an error "Cannot find symbol"
    and mySS.show(); is just striked out.



    I'm so sorry for this type of question, but I'm just starting to learn.

  4. #4
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    5

    Cool

    Quote Originally Posted by Grish View Post
    on line Swing () it's telling me "Invalid method declaration"
    Read : Defining Methods

    Quote Originally Posted by Grish View Post
    on line mySS.setText("Pes app"); there is an error "Cannot find symbol"
    Because there is no method called setText for JFrame

    Quote Originally Posted by Grish View Post
    and mySS.show(); is just striked out.
    They are deprecated methods. For more details : What "Deprecated" Means

    Hope that helps,

    Goldest
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

  5. #5
    Grish is offline Member
    Join Date
    Jun 2011
    Posts
    4
    Rep Power
    0

    Default

    Thank you so much!

    Huh...I guess my book is pretty outdated? Everything runs well for the author
    Can I ask the last question, just to make sure, so what would I use instead of setText for title of the simple frame?


    UPD: I got it! THANK YOU SO MUCH!
    yay, i was going crazy there :D
    Last edited by Grish; 06-01-2011 at 03:17 PM.

  6. #6
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    5

    Cool

    Quote Originally Posted by Grish View Post
    so what would I use instead of setText for title of the simple frame?
    See: setTitle

    Goldest
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

  7. #7
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,227
    Rep Power
    6

  8. #8
    Grish is offline Member
    Join Date
    Jun 2011
    Posts
    4
    Rep Power
    0

    Default

    Thanks guys.

    I was really thrown off by this textbook, which I should ditch I guess :) It's extremely outdated

  9. #9
    loopsnhoops is offline Member
    Join Date
    Feb 2011
    Posts
    83
    Rep Power
    0

    Default

    Sorry for late response but another way to create a JFrame is to make it a parent class which is done by: public class classname extends JFrame.
    then you can add or set properties without have to specify the JFrame each time so you would do this like: super(title)


    Java Code:
    public class whatever extends JFrame{
    
    public whatever(){
    
    super("MY FIRST WINDOW);
    setSize(400,400);
    setVisible(true);
    
    }
    
    }

  10. #10
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    5

    Cool

    Quote Originally Posted by Grish View Post
    I was really thrown off by this textbook, which I should ditch I guess :) It's extremely outdated
    Let the others know which book is this, so that they can avoid it if its not suitable for proper learning.

    Goldest
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

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

    Default

    Quote Originally Posted by loopsnhoops View Post
    Sorry for late response but another way to create a JFrame is to make it a parent class which is done by: public class classname extends JFrame.
    then you can add or set properties without have to specify the JFrame each time ...
    ... which is a gross misuse of inheritance. Always favor composition over inheritance. Classes are extended for the purpose of enhancing or modifying behavior, not to save typing a variable reference name.

    db

Similar Threads

  1. About Swing
    By satimis in forum New To Java
    Replies: 2
    Last Post: 05-01-2010, 05:37 PM
  2. swing.jar
    By krrishnak in forum AWT / Swing
    Replies: 2
    Last Post: 04-05-2009, 05:29 AM
  3. What is next to Swing
    By javaplus in forum AWT / Swing
    Replies: 1
    Last Post: 01-13-2008, 10:16 PM
  4. AWT or Swing
    By bugger in forum AWT / Swing
    Replies: 4
    Last Post: 11-22-2007, 09:44 AM
  5. map javax.swing.text.Element to javax.swing.text.View
    By elizabeth in forum New To Java
    Replies: 1
    Last Post: 07-30-2007, 07:02 PM

Posting Permissions

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