Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Applet won't display.

0 views
Skip to first unread message

Paul.L...@googlemail.com

unread,
Jul 16, 2008, 10:39:20 AM7/16/08
to
Hi,
This is probably very simple, but I can't get this to work. I am
writing an Applet that will display two panels, the first one being a
panel to display graphics, and the other panel displaying the controls
to manipulate the graphics panel.

Derived from JApplet, my init() method has the following:

Container content=getContentPane();

display = new JPanel();
controls = new JPanel();

displayPanel = new DataDisplayPanel( this );
displayPanel.setPreferredSize(new Dimension( 840, 712 ));
displayPanel.setBackground( Color.BLACK );

display.add( displayPanel );

content.add( display );
content.add( controls );

DataDisplayPanel is just derived from JPanel, with MouseListener
interfaces overriden. I have embedded the applet tag in a webpage (the
relevant code is '<applet code="IceDisplayApplet.class" width="1000"
height="1000">
</applet>'). Now I know that init() is called, as I have a call to
initialise data before the above calls to initialise
the gui are called, and the data init process works just fine.
But when I try and display the applet using appletviewer, I get
nothing at all. Can anyone suggest why?

One thing I do think of was that I have written all my class
declarations in one file, and when I run the compiler,
these of course get split into different files, Class1.class,
Class2.class etc. I have combined these classes into
a jar file and added this is an archive tag in the above applet code
snippet but it still doesn't work. What am I doing wrong? Someone on
another forum suggested to another poster that a .pack() call was
missing, but I have run JApplets without this call, and they work just
fine.

Best wishes

Paul

Andrew Thompson

unread,
Jul 16, 2008, 6:30:10 PM7/16/08
to
On Jul 17, 12:39 am, "Paul.Lee.1...@gmail.com" <Paul.Lee.
1...@googlemail.com> wrote:
...
> This is probably very simple, ...

It probably is. So this time I will try
working with a code snippet. If my suggestions
do not fix the stated problem, try posting an
SSCCE.

> ...


> Derived from JApplet, my init() method has the following:
>
>                 Container content=getContentPane();

content.setLayout(new FlowLayout())

>
>                 display = new JPanel();
>                 controls = new JPanel();
>
>                 displayPanel = new DataDisplayPanel( this );
>                 displayPanel.setPreferredSize(new Dimension( 840, 712 ));
>                 displayPanel.setBackground( Color.BLACK );
>
>                 display.add( displayPanel );
>
>                 content.add( display );
>                 content.add( controls );

pack()

...

> ... Someone on


> another forum suggested to another poster that a .pack() call was
> missing, but I have run JApplets without this call, and they work just
> fine.

That would largely be by accident.

--
Andrew Thompson
http://pscode.org/

Paul.L...@googlemail.com

unread,
Jul 17, 2008, 7:53:05 PM7/17/08
to

Thanks, it works!

Roedy Green

unread,
Jul 21, 2008, 4:30:16 PM7/21/08
to
On Wed, 16 Jul 2008 07:39:20 -0700 (PDT), "Paul.L...@gmail.com"
<Paul.L...@googlemail.com> wrote, quoted or indirectly quoted
someone who said :

>content.add( display );
> content.add( controls );

you are missing a content.setLayout. Very rarely is the defaut layout
what you want.
--

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

Roedy Green

unread,
Jul 22, 2008, 10:28:18 AM7/22/08
to
On Wed, 16 Jul 2008 07:39:20 -0700 (PDT), "Paul.L...@gmail.com"
<Paul.L...@googlemail.com> wrote, quoted or indirectly quoted
someone who said :

><applet code="IceDisplayApplet.class"

I suggest always putting your classes in a Jar when you write an
Applet and put them all in a real package.

see http://mindprod.com/jgloss/applet.html

Roedy Green

unread,
Jul 23, 2008, 6:07:36 AM7/23/08
to
On Thu, 17 Jul 2008 16:53:05 -0700 (PDT), "Paul.L...@gmail.com"

<Paul.L...@googlemail.com> wrote, quoted or indirectly quoted
someone who said :

>Thanks, it works!

that was the key to making it work?

0 new messages