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