Ayuda! Excepciones que no sé solucionar
Publicado por Cristina (48 intervenciones) el 14/04/2007 18:15:03
Hola,
OS MUESTRO ESTE CÓDIGO Y A CONTINUACION OS PLANTEO MI PROBLEMA:
public class RectangleDemo extends JApplet{
public void init(){
Container c = getContentPane();
buildUI(c);}
void buildUI(Container c){
c.setLayout(new BoxLayout(c, BoxLayout.Y_AXIS));
RectangleArea rectangleArea = new RectangleArea(this);
c.add(rectangleArea); }
public static void main(String[] args){
JFrame f = new JFrame("RectangleDemo");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
RectangleDemo controller = new RectangleDemo();
controller.buildUI(f.getContentPane());
//f.pack();
f.setSize (500,500);
f.setVisible(true);}
}
QUE AL EJECUTARLO ME DA LAS SIGUIENTES EXCEPCIONES:
Exception in thread "main" java.lang.IllegalArgumentException: adding a window to a container
at java.awt.Container.addImpl(Container.java:616)
at java.awt.Container.add(Container.java:307)
at RectangleDemo.buildUI(RectangleDemo.java:15)
at RectangleDemo.main(RectangleDemo.java:22)
ALQUIEN SABRÍA SOLUCIONARLO???????
LA CLASE RectangleArea QUE APARECE EN EL CODIGO ANTERIOR ES:
class RectangleArea extends JFrame{
public RectangleArea(RectangleDemo controller){
Border raisedBevel = BorderFactory.createRaisedBevelBorder();
Border loweredBevel = BorderFactory.createLoweredBevelBorder();
Border compound = BorderFactory.createCompoundBorder(raisedBevel,loweredBevel);
JPanel drawingArea = new JPanel();
drawingArea.setBorder(compound);
repaint(); }// Fin constructor
public void paintComponent(Graphics g){
g.drawRect(30,40,52,52);
g.setColor(Color.yellow);
g.fillRect(31,41,51,51); }}
GRACIAS.
UN SALUDO!!!!!!!!!!!!!
OS MUESTRO ESTE CÓDIGO Y A CONTINUACION OS PLANTEO MI PROBLEMA:
public class RectangleDemo extends JApplet{
public void init(){
Container c = getContentPane();
buildUI(c);}
void buildUI(Container c){
c.setLayout(new BoxLayout(c, BoxLayout.Y_AXIS));
RectangleArea rectangleArea = new RectangleArea(this);
c.add(rectangleArea); }
public static void main(String[] args){
JFrame f = new JFrame("RectangleDemo");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
RectangleDemo controller = new RectangleDemo();
controller.buildUI(f.getContentPane());
//f.pack();
f.setSize (500,500);
f.setVisible(true);}
}
QUE AL EJECUTARLO ME DA LAS SIGUIENTES EXCEPCIONES:
Exception in thread "main" java.lang.IllegalArgumentException: adding a window to a container
at java.awt.Container.addImpl(Container.java:616)
at java.awt.Container.add(Container.java:307)
at RectangleDemo.buildUI(RectangleDemo.java:15)
at RectangleDemo.main(RectangleDemo.java:22)
ALQUIEN SABRÍA SOLUCIONARLO???????
LA CLASE RectangleArea QUE APARECE EN EL CODIGO ANTERIOR ES:
class RectangleArea extends JFrame{
public RectangleArea(RectangleDemo controller){
Border raisedBevel = BorderFactory.createRaisedBevelBorder();
Border loweredBevel = BorderFactory.createLoweredBevelBorder();
Border compound = BorderFactory.createCompoundBorder(raisedBevel,loweredBevel);
JPanel drawingArea = new JPanel();
drawingArea.setBorder(compound);
repaint(); }// Fin constructor
public void paintComponent(Graphics g){
g.drawRect(30,40,52,52);
g.setColor(Color.yellow);
g.fillRect(31,41,51,51); }}
GRACIAS.
UN SALUDO!!!!!!!!!!!!!
Valora esta pregunta


0