wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes AWT  [StackOverflowException] Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "AWT  [StackOverflowException]" Watch "AWT  [StackOverflowException]" New topic
Author

AWT [StackOverflowException]

Thiru Thangavelu
Ranch Hand

Joined: Aug 29, 2001
Posts: 219
The following code throws StackOverflowException when executing getPreferredSize(). I know, this is an Error Type which is JVM Error. But why I am getting and how to avoid this?
import java.awt.*;
import java.awt.event.*;
public class Test {
public static void main(String args[]) {
Frame f = new Frame("BorderTest");
BorderLayout bl= new BorderLayout();
Panel p = new Panel(bl);
f.setLayout(bl);
p.add(new Label("Hello", Label.CENTER),
BorderLayout.NORTH);
p.add(new TextArea(), BorderLayout.CENTER);
p.add(new TextField(), BorderLayout.SOUTH);
f.add(p, BorderLayout.SOUTH);
f.addWindowListener(
new WindowAdapter() {
public void windowClosing(WindowEvent we) {
System.exit(0);
}
}
);
f.setSize(200,200);
System.out.println(f.getPreferredSize());
f.setVisible(true);
}
}
Thanks
[ Adjusted title so two AWT threads don't appear to be duplicates ]
[ May 30, 2002: Message edited by: Jessica Sant ]

Thanks,<br />Thiru<br />[SCJP,SCWCD,SCBCD]
Steven Wong
Ranch Hand

Joined: Mar 07, 2002
Posts: 295
Hi,
The following will work.


Clement
SCJP2


best regards,<br />Steven<br />SCJP, SCEA
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: AWT [StackOverflowException]