Results 1 to 10 of 10
Like Tree4Likes
  • 1 Post By Tolls
  • 1 Post By kneitzel
  • 1 Post By kneitzel
  • 1 Post By kneitzel

Thread: ContentPane and JFrame

  1. #1
    tedy_pro is offline Member
    Join Date
    Jun 2014
    Posts
    11
    Rep Power
    0

    Default ContentPane and JFrame

    Hi all. I'm beginner . What's the problem here? please help me ....

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

    public class ContentPaneEx extends JFrame
    {
    ContentPaneEx()
    {
    setTitle("ContentPane and JFrame");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Container contentPane = getContentPane();
    contentPane.setBackground(Color.ORANGE);
    contentPane.setLayout(new FlowLayout());
    contentPane.add(new JButton("OK"));
    contentPane.add(new JButton("cancel"));
    contentPane.add(new JButton("ignore"));

    setSize(300, 150);
    setVisible(true);


    }
    public static void main(String[] args) {
    new ContentPaneEx();
    }
    }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: ContentPane and JFrame

    You are the one that needs to tell us what the problem is...
    We can then provide a solution.
    tedy_pro likes this.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    kneitzel is offline Senior Member
    Join Date
    Feb 2014
    Posts
    447
    Rep Power
    1

    Default Re: ContentPane and JFrame

    The only problems that I see:
    - You do not tell us where you see a problem. (So what error do you get? What happens and what should happen?)
    - You didn't put the Code in [CODE] ... [/CODE] tags

    Konrad
    tedy_pro likes this.

  4. #4
    tedy_pro is offline Member
    Join Date
    Jun 2014
    Posts
    11
    Rep Power
    0

    Default Re: ContentPane and JFrame

    Thank you all.
    error is here. how to solve this error
    Error: ContentPaneEx class can not be found, the default method. Define the following format: The default method.
    public static void main (String [] args)

  5. #5
    kneitzel is offline Senior Member
    Join Date
    Feb 2014
    Posts
    447
    Rep Power
    1

    Default Re: ContentPane and JFrame

    Can you explain exactly what you did?

    I did the following:
    - Created a file ContentPaneEx.java with your code
    - Called javac ContentPaneEx.java
    - Called java ContenPaneEx

    I got no error and everything worked fine. (I was in the same directory as the files of course!)

    With kind regards,

    Konrad
    tedy_pro likes this.

  6. #6
    tedy_pro is offline Member
    Join Date
    Jun 2014
    Posts
    11
    Rep Power
    0

    Default Re: ContentPane and JFrame

    thank you very much Konrad

    i will following your manual.

    Best regards.

    Tedy :-)

  7. #7
    tedy_pro is offline Member
    Join Date
    Jun 2014
    Posts
    11
    Rep Power
    0

    Default Re: ContentPane and JFrame

    hi all
    i'm seeing the example in the book bring out the draft result.

    ContentPane and JFrame-.jpg

    please see the picture

  8. #8
    kneitzel is offline Senior Member
    Join Date
    Feb 2014
    Posts
    447
    Rep Power
    1

    Default Re: ContentPane and JFrame

    Hi,

    could you provide us with a full picture of your IDE so we can see more details?

    Your code is correct, compiles and can be executed. So it must be something with our IDE.
    There is a warning with your Classname. If you hover your mouse over the warning, you might see some text that could help you. Maybe your placed the code inside a folder structure which represents a package. In such a case you need to declare the package in your file, too.
    So you could place the files in a directory "test", put a "package test;" on top of your file and then you must be in the parent directory and compile with
    javac test/ContentPaneEx.java
    and start with
    java test.ContentPaneEx

    But all this is guessing only. There isn't enough data to be more precise.

    With kind regards,

    Konrad
    tedy_pro likes this.

  9. #9
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,365
    Rep Power
    6

    Default Re: ContentPane and JFrame

    The warning is probably just a "not serializable" type of deal, but there is clearly one or more errors mentioned in the 'problems' widget as it is marked with a red cross. I'm more curious what's in there.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  10. #10
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,033
    Rep Power
    6

    Default Re: ContentPane and JFrame

    Why are you extending JFrame when all you really need to do is create an instance of JFrame and work with that? A couple time savers are, 1) the JFrame constructor takes a title as an argument and 2) the JFrame.add() method is a helper method which adds the components to the contentPane for you. So you don't need to grab the contentPane to do this.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Replies: 2
    Last Post: 10-05-2013, 07:28 PM
  2. Adding Scaled BufferedImage to ContentPane
    By switch in forum AWT / Swing
    Replies: 12
    Last Post: 01-26-2012, 02:46 AM
  3. exception: contentPane cannot be set to null.
    By Chaosje in forum New To Java
    Replies: 5
    Last Post: 05-04-2011, 07:53 PM
  4. contentpane
    By marodia in forum AWT / Swing
    Replies: 7
    Last Post: 08-27-2009, 08:30 AM
  5. Rootpane,ContentPane,LayeredPane
    By makpandian in forum AWT / Swing
    Replies: 2
    Last Post: 01-31-2009, 12:22 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
  •