Article View: comp.lang.java.programmer
Article #269simple applet (code included) won't redraw properly
From: Geoff_Ingram
Date: Mon, 01 Dec 1997 00:00
Date: Mon, 01 Dec 1997 00:00
105 lines
3499 bytes
3499 bytes
I had a problem with redrawing the screen in an applet. I have reproduced
the problem using a simple applet that consists of a Choice list
containing "A", "B", "C". When you select from the list, a grid is drawn
below it, containing the letter you selected, replacing any previous grid
that existed. JDK 1.1 AWT is used.
I cant get the grid to display properly from my code when I select from
the Choice list. Under Netscape 4.0.4 with JDK 1.1 update it displays
properly if I press Reload button on browser. Under appletviewer it
displays properly only if I resize the screen. Under IE4 plus SDK 2.0
update it never displays properly.
I have tried placing calls to validate() and paintAll() in the code.
The behaviour still isnt what I expect.
I have seen countless postings to do with similar problems over the last
few months. Is there a definitive answer?
All code for applet is contained below.
regards Geoff Ingram
=========
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class Draw extends java.applet.Applet
{
public void init()
{
System.out.println("init Draw");
DrawPanel panel = new DrawPanel();
add(panel);
}
}
class DrawPanel extends Panel implements ItemListener
{
private Choice mychoice = new Choice();
private GridBagLayout gridbag = new GridBagLayout();
private GridBagConstraints constr = new GridBagConstraints();
private Panel pnl_grid;
public DrawPanel()
{
setLayout(gridbag);
mychoice.addItem("A");
mychoice.addItem("B");
mychoice.addItem("C");
mychoice.addItemListener(this);
constr.gridwidth = GridBagConstraints.REMAINDER; // end row
gridbag.setConstraints(mychoice,constr);
add(mychoice);
} // DrawPanel
public void itemStateChanged(ItemEvent evt)
{
if (evt.getStateChange() == ItemEvent.DESELECTED)
{
return;
}
displayGrid(mychoice.getSelectedItem());
}
public void displayGrid(String s)
{
int dim=1;
if (s.equals("A"))
dim=5;
else if (s.equals("B"))
dim=4;
else if (s.equals("C"))
dim=3;
GridLayout grid = new GridLayout(dim,dim);
if (pnl_grid != null) // remove from last time
remove(pnl_grid);
pnl_grid = new Panel();
pnl_grid.setLayout(grid);
for (int row=0;row<dim;row++)
for (int col=0;col<dim;col++)
{
pnl_grid.add(new Label(s));
}
gridbag.setConstraints(pnl_grid,constr);
add(pnl_grid);
// paintAll(getGraphics());
}
} // DrawPanel
-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet
Technical Details
Message-ID:
<880983591.6943@dejanews.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10a146,7336280b6ba26964,start X-Google-Attributes: gid10a146,public X-Google-Thread: 100145,7336280b6ba26964,start X-Google-Attributes: gid100145,public X-Google-Thread: ff01d,7336280b6ba26964,start X-Google-Attributes: gidff01d,public From: Geoff_Ingram@ml.com Subject: simple applet (code included) won't redraw properly Date: 1997/12/01 Message-ID: <880983591.6943@dejanews.com> X-Deja-AN: 294195554 X-Http-User-Agent: Mozilla/4.04 [en] (WinNT; I) X-Originating-IP-Addr: 193.130.38.81 (lonsf24317.mle.co.uk) Organization: Deja News Posting Service X-Authenticated-Sender: Geoff_Ingram@ml.com X-Article-Creation-Date: Mon Dec 01 13:39:51 1997 GMT Newsgroups: comp.lang.java.programmer,microsoft.public.java.visualj++,borland.public.jbuilder.applet-issues