Results 1 to 8 of 8
Like Tree1Likes
  • 1 Post By DarrylBurke

Thread: Why does it seem this method isn't being called?

  1. #1
    Appel is offline Member
    Join Date
    May 2012
    Posts
    5
    Rep Power
    0

    Default Why does it seem this method isn't being called?

    So I have a BaseFrame class, and have a few questions:

    here's the BaseFrame Class, I Stuck a out.println in just to see if in fact I was getting there, well it doesn't seem to be:

    import javax.swing.*;
    import static java.lang.System.out;

    public class BaseFrame {
    static public void OpenFrame(){
    out.println("You hit BaseFrame" + "\n");
    JFrame MyFrame = new JFrame("FrameDemo");
    MyFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CL OSE);
    MyFrame.setSize(50, 50);
    MyFrame.setVisible(true);
    }
    }


    In the main, I have:

    BaseFrame Myframe;
    Myframe = new BaseFrame;
    MyFrame.OpenFrame();


    #1) The compiler is telling me it's expecting a [ or ( at the end of 'baseframe = new BaseFrame'. My question is why? Aren't I just making a copy if BaseFrame, which is a copy of JFrame? Why do I need it?

    #2) When I do add it, a () that is, the compiler doesn't balk, but nothing seems to be called in BaseFrame either, any reason?


    #3) The compiler balked on the class header 'static public void OpenFrame(){', it said this needed to be static Why?

    Thanks for the help!

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,864
    Rep Power
    8

    Default Re: Why does it seem this method isn't being called?

    You aren't going to get any output whatsoever until you run your program, and you aren't going to be able to run your program until you can compile it, and you aren't going to be able to compile it until you get rid of your syntax errors.

    Take them one at a time and pay attention to the error message. Look at the line specified by the compiler, and compare your syntax to the syntax in the basic tutorials.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default Re: Why does it seem this method isn't being called?

    Myframe = new BaseFrame(); is correct!
    Creating Objects (The Java™ Tutorials > Learning the Java Language > Classes and Objects)

    MyFrame.OpenFrame();
    If you mean Myframe -> its a static method, so its better to use the static way -> BaseFrame.OpenFrame(); (but then i will ask you, why do you need the object?)
    If not, you have to use the right variable Myframe instead of MyFrame! (but then i will ask you, why the method is static + take a look at code conventions) :D

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

    Default Re: Why does it seem this method isn't being called?

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

  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: Why does it seem this method isn't being called?

    Quote Originally Posted by eRaaaa View Post
    take a look at code conventions
    Already been told that.
    Alright, Now I'm catching on, but stuck on something....

    Some people only want to ask questions, not follow the advice.

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

  6. #6
    Appel is offline Member
    Join Date
    May 2012
    Posts
    5
    Rep Power
    0

    Default Re: Why does it seem this method isn't being called?

    Darryl - do you just sit around waiting to troll? And Yeah your right, I am here to ask questions, and when somebody asks me a question I answer it, not give smartass remarks. If this is not the purpose of this board well then let me know. Not that it's of any concern of yours, but I'm reading about conventions thank you, didn't realize they were rather important in Java, excuse me for being a noob. eRaaaa, put up the helpful answer and suggestion, you should follow that model or just not respond.
    Last edited by Appel; 05-02-2012 at 08:20 PM.

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

    Default Re: Why does it seem this method isn't being called?

    You're here for help. If you ignore advice, that will encourage the helpful to ignore you.

    Your call.

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

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,798
    Rep Power
    19

    Default Re: Why does it seem this method isn't being called?

    Quote Originally Posted by Appel View Post
    #1) The compiler is telling me it's expecting a [ or ( at the end of 'baseframe = new BaseFrame'. My question is why? Aren't I just making a copy if BaseFrame, which is a copy of JFrame? Why do I need it?
    Having read one of your earlier threads you seem to have a confusion about classes and objects.
    BaseFrame is a class.
    baseFrame is a reference to an instance (an object) of BaseFrame.
    That instance is not a "copy of BaseFrame".
    Think of BaseFrame as a blueprint for what a BaseFrame instance looks like and can do.
    Until you call the constructor method using 'new BaseFrame()' you have no BaseFrame objects at all.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 5
    Last Post: 10-22-2010, 01:55 PM
  2. Client freezes when method is called
    By chyrl in forum Advanced Java
    Replies: 9
    Last Post: 07-26-2010, 09:14 PM
  3. Why the paint() method is called two times ?
    By supremo in forum New To Java
    Replies: 4
    Last Post: 06-03-2010, 06:21 PM
  4. Replies: 10
    Last Post: 02-28-2010, 01:52 PM
  5. what made paintComponent() method to be called twice??
    By Y. Progammer in forum New To Java
    Replies: 5
    Last Post: 02-21-2010, 10:19 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
  •