Help with getContentPane()

R

RCS

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;
}
}
}

}

}
 
E

E.C. Bäck

RCS said:
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
 
B

Bjorn Abelli

...
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
 
R

RCS

Bjorn Abelli said:
...
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top