When I try to run the file I get this error, amen't sure how to fix it.
Exception in thread "main" java.lang.IllegalArgumentException: illegal component
position
at java.awt.Container.addImpl(Container.java:1035)
at java.awt.Container.add(Container.java:408)
at EmailWindow.CreateContent(EmailWindow.java:65)
at EmailWindow.<init>(EmailWindow.java:22)
at Lab6a.main(Lab6a.java:10)
Heres my code sorry for lack of comments
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class EmailWindow extends JFrame implements ActionListener
{
//Declaring the Components
Container cpane;
JPanel textPanel;
JPanel labelPanel;
JPanel textFieldPanel;
JPanel buttonPanel;
JPanel buttonPanel2;
ColouredPanel p;
JButton ok,exit;
public EmailWindow()
{
JFrame frame = new JFrame();
this.setTitle("My Frame");
this.setSize(800, 800);
this.setContentPane(CreateContent());
//this.setJMenuBar(CreateMenu());
this.setVisible(true);
}
public Container CreateContent()
{
cpane = new JPanel(new BorderLayout());
textPanel = new JPanel(new BorderLayout());
labelPanel = new JPanel(new GridLayout(2,0));
textFieldPanel = new JPanel(new GridLayout(2,0));
buttonPanel = new JPanel(new FlowLayout());
buttonPanel2 = new JPanel(new GridLayout(1,0));
p = new ColouredPanel(Color.white, "Nothing yet....");
JLabel name = new JLabel("Name: ");
JLabel email = new JLabel("E-mail Address: ");
JTextField namefield = new JTextField(20);
JTextField emailfield = new JTextField(40);
ok = new JButton("OK");
exit = new JButton("EXIT");
ok.addActionListener(this);
exit.addActionListener(this);
labelPanel.add(name);
labelPanel.add(email);
textFieldPanel.add(namefield);
textFieldPanel.add(emailfield);
textPanel.add(labelPanel, BorderLayout.WEST);
textPanel.add(textFieldPanel, BorderLayout.CENTER);
buttonPanel2.add(ok);
buttonPanel2.add(exit);
buttonPanel.add(buttonPanel2, FlowLayout.RIGHT);
cpane.add(textPanel, BorderLayout.NORTH);
cpane.add(buttonPanel, BorderLayout.SOUTH);
return cpane;
}
public void actionPerformed(ActionEvent e)
{
Object objectUsed = e.getSource();
if(objectUsed instanceof JButton)
{
if(e.getSource() == ok)
{
p.changeText("Pressed Ok");
}
else
{
p.changeText("Press Exit");
}
}
}
}
Any help much appericated