Results 1 to 5 of 5
  1. #1
    Raghavsd9 is offline Member
    Join Date
    Apr 2012
    Posts
    1
    Rep Power
    0

    Default i need help with JFrame.

    hey people. i am not new to java. i know quit abit.
    I am using Eclipse Helios for windows java programming.
    I want to make jframe without lables. just with a title saying " new j frame"
    now this is the code:


    import javax.swing.JFrame;
    class ShowAFrame {
    public static void main (String [] args) {
    JFrame myFrame = new JFrame();
    String myTitle = "Blank Frame";
    myFrame.setTitle(myTitle);
    myFrame.setSize(200,200);
    myFrame.setDefaultCloseOperation
    (JFrame.EXIT_ON_CLOSE);
    myFrame.setVisible(true);
    }
    }




    When i compile thhis in eclispe it says, the program canot find the main method?
    and then when i execute it without ddebugging when it shwos errors it says again that "main is not found in public static void min (string[] args);


    thanks lol

  2. #2
    milovan is offline Senior Member
    Join Date
    Jan 2011
    Location
    Belgrade, Serbia
    Posts
    299
    Rep Power
    4

    Default Re: i need help with JFrame.

    Please use code tags and tell me is this sintax error you have made when writing this post or this is exact message from compiler
    "main is not found in public static void min (string[] args);

  3. #3
    Danieldcc is offline Member
    Join Date
    Sep 2010
    Posts
    83
    Rep Power
    0

    Default Re: i need help with JFrame.

    hhhmmmmm....I just compiled your code in eclipse and it run just fine. I got an empty frame

  4. #4
    JavaCoconut is offline Member
    Join Date
    Apr 2012
    Posts
    3
    Rep Power
    0

    Default Re: i need help with JFrame.

    You should make the file extend JFrame and add a constructor to use the methods like setSize(). To make the frame have a title without using a String you need to add a super constructor on the top line of the constructor, like this:
    Java Code:
    import javax.swing.JFrame;
    
    public class ShowAFrame extends JFrame {
    
        public ShowAFrame() {
            super("Blank Frame");
            setSize(200, 200);
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            setVisible(true);
        }
    
        public static void main(String[] args) {
            new ShowAFrame();
        }
    }
    I hope this is what you were trying to accomplish

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: i need help with JFrame.

    Quote Originally Posted by JavaCoconut View Post
    You should make the file extend JFrame...
    Most professional coders I know frown on this saying that you shouldn't extend a class if you don't plan to override one of its behaviors.

    ... and add a constructor to use the methods like setSize().
    And many (particularly Kleopatra/Jeanette -- a principle developer at SwingLabs, developers of the SwingX add-ons) will tell you to avoid calling setSize(...) on any Swing GUI component but rather to let the layout managers and components set their own sizes. If the GUI needs to be a set size, then the getPreferredSize() method should be overridden.

Similar Threads

  1. Replies: 3
    Last Post: 11-27-2011, 05:18 AM
  2. Replies: 5
    Last Post: 06-14-2010, 06:10 PM
  3. Replies: 6
    Last Post: 04-12-2010, 11:33 AM
  4. Passing data from one JFrame to another JFrame
    By tarami in forum New To Java
    Replies: 3
    Last Post: 08-06-2009, 05:44 PM
  5. Replies: 4
    Last Post: 04-22-2009, 11: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
  •