Thread View: comp.lang.java.programmer
1 messages
1 total messages
Started by Geoff_Ingram
Mon, 01 Dec 1997 00:00
simple applet (code included) won't redraw properly
Author: 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
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads