Help with getContentPane()

Discussion in 'Java' started by RCS, Sep 7, 2003.

  1. RCS

    RCS Guest

    I am trying to write a GUI that has buttons similiar to that of a
    phone and a message board above showing messages. I am receiving an
    error shown below:



    C:\Program Files\j2sdk_nb\j2sdk1.4.2\bin>javac JButtons4.java
    JButtons4.java:29: cannot resolve symbol
    symbol : method getContentPane ()
    location: class JButtons4
    Container content3 = getContentPane();
    ^
    1 error

    C:\Program Files\j2sdk_nb\j2sdk1.4.2\bin>







    Here is my code: if someone can comment on the problem and anything
    else on my code that would be great. I am a beginner so any comments
    would be great:

    import java.applet.Applet;
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;


    public class JButtons4 extends Frame{

    private JButton phonekeys[];
    private String KEYS[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9",
    "*", "0", "+"};
    private int counter = 0;
    private String numbers[];
    private int i;
    private JLabel label;
    private JPanel content;
    private JPanel content3;

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


    public void init()
    {

    JPanel content = new JPanel();
    JPanel content2 = new JPanel();
    Container content3 = getContentPane();

    label = new JLabel();

    phonekeys = new JButton[ KEYS.length ];

    content2.setLayout( new GridLayout(4, 3) );

    ButtonHandler handler = new ButtonHandler();

    for( int i = 0 ; i < 12 ; i++ )
    {
    phonekeys = new JButton( KEYS );
    content2.add( phonekeys );
    phonekeys.addActionListener( handler );
    }

    content3.add(content2, BorderLayout.SOUTH);
    content3.add(content, BorderLayout.NORTH);

    pack();
    setVisible(true);

    }

    private class ButtonHandler implements ActionListener
    {
    public void actionPerformed( ActionEvent e )
    {
    for( i = 0; i < phonekeys.length; i++ )
    {
    if( e.getSource() == phonekeys )
    {
    label.setText( KEYS );
    content.add(label);
    break;
    }
    }
    }

    }

    }
    RCS, Sep 7, 2003
    #1
    1. Advertising

  2. RCS

    E.C. Bäck Guest

    RCS" <> wrote in message
    news:...
    > I am trying to write a GUI that has buttons similiar to that of a
    > phone and a message board above showing messages. I am receiving an
    > error shown below:
    >
    >
    >
    > C:\Program Files\j2sdk_nb\j2sdk1.4.2\bin>javac JButtons4.java
    > JButtons4.java:29: cannot resolve symbol
    > symbol : method getContentPane ()
    > location: class JButtons4
    > Container content3 = getContentPane();
    > ^
    > 1 error


    The AWT Frame class does not have a getContentPane() method. The Swing
    JFrame does...
    --
    Thanks,
    Elliott C. Bäck

    Sophomore, Computer Science
    Cornell University
    E.C. Bäck, Sep 7, 2003
    #2
    1. Advertising

  3. RCS

    Bjorn Abelli Guest

    "RCS" wrote...

    > I am receiving an
    > error shown below:


    > JButtons4.java:29: cannot resolve symbol
    > symbol : method getContentPane ()


    [snip]

    > Here is my code:


    [snip]

    > public class JButtons4 extends Frame{

    ---------------------------------^

    java.awt.Frame doesn't have any "content pane", such as the
    javax.swing.JFrame has.

    Here you probably just made a typo, missing the "J" in "JFrame"?

    // Bjorn A
    Bjorn Abelli, Sep 7, 2003
    #3
  4. RCS

    RCS Guest

    "Bjorn Abelli" <> wrote in message news:<bjfn3o$ik84c$-berlin.de>...
    > "RCS" wrote...
    >
    > > I am receiving an
    > > error shown below:

    >
    > > JButtons4.java:29: cannot resolve symbol
    > > symbol : method getContentPane ()

    >
    > [snip]
    >
    > > Here is my code:

    >
    > [snip]
    >
    > > public class JButtons4 extends Frame{

    > ---------------------------------^
    >
    > java.awt.Frame doesn't have any "content pane", such as the
    > javax.swing.JFrame has.
    >
    > Here you probably just made a typo, missing the "J" in "JFrame"?
    >
    > // Bjorn A

    Thanks Bjorn A and Elliott C. Bäck
    RCS, Sep 8, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?dHJlbGxvdzQyMg==?=

    HELP! HELP! HELP! Opening Web Application Project Error

    =?Utf-8?B?dHJlbGxvdzQyMg==?=, Feb 20, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    766
    =?Utf-8?B?dHJlbGxvdzQyMg==?=
    Feb 20, 2004
  2. Harvey
    Replies:
    0
    Views:
    698
    Harvey
    Jul 16, 2004
  3. Harvey
    Replies:
    1
    Views:
    842
    Daniel
    Jul 16, 2004
  4. Gil
    Replies:
    9
    Views:
    1,686
  5. DaveForgotHisEngineering

    getContentPane problem

    DaveForgotHisEngineering, Mar 4, 2008, in forum: Java
    Replies:
    3
    Views:
    7,327
    Roedy Green
    Mar 5, 2008
Loading...

Share This Page