This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Applets and the fly likes Repaint and Applet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "Repaint and Applet" Watch "Repaint and Applet" New topic
Author

Repaint and Applet

Pragnesh Shah
Greenhorn

Joined: Dec 05, 2000
Posts: 3
i am dynamically generate control(checkbox and ch.group) and feel in panel with gridlayout.
Code is like. if flag=0 then remove all component from panel(removeAll()) and add control dynamically.The problame is that if i minimize or max. then the effect.(Proper set in layout).I also use repain and paint.
The code is here
import java.awt.*;
import java.applet.Applet;
import java.awt.event.*;
public class Display extends Applet implements ActionListener,ContainerListener
{
Panel p1,p2,p3,p4;
Button b1,b2;
TextArea t1;
String s;
CheckboxGroup cbg;
static int i;

int flag;
public void init()
{
s=new String("Y");
p1=new Panel();
p2=new Panel();
p3=new Panel();

setLayout(new BorderLayout());
p1.setLayout(new FlowLayout());
p2.setLayout(new GridLayout(1,2));
p3.addContainerListener(this);
add(p1,BorderLayout.SOUTH);
add(p2,BorderLayout.NORTH);
b1=new Button("Next");
b2=new Button("Previous");
p1.add(b1);
p1.add(b2);
t1=new TextArea(50,20);
p2.add(t1);

b1.addActionListener(this);
b2.addActionListener(this);
}
public void f(String s)
{

if(s.equals("Y"))
{
System.out.println("in Y");


p3.setLayout(new GridLayout(3,2));
p3.add(add(new Checkbox("Cone", null, true)));
//p3.add(new TextArea(5,2));
p3.add(new Button("C"));
p3.add(add(new Checkbox("Ctwo")));
//p3.add(new TextArea(5,2));
p3.add(new Button("C"));
p3.add(add(new Checkbox("Cthree")));
//p3.add(new TextArea(5,2));
p3.add(new Button("C"));

p2.add(p3);
p2.add(p4);
//p3.repaint();
}
else
{
System.out.println("in N");

p3.repaint();

cbg = new CheckboxGroup();
p3.setLayout(new GridLayout(3,3));
p3.add(add(add(new Checkbox("Rone", cbg, true))));
p3.add(new TextArea(5,2));
p3.add(add(add(new Checkbox("Rone", cbg, true))));
p3.add(new TextArea(5,2));
p3.add(add(add(new Checkbox("Rone", cbg, true))));
p3.add(new TextArea(5,2));
p2.add(p3);
//p3.repaint();
}
}
public void actionPerformed(ActionEvent ae)
{
String s1=ae.getActionCommand();
if(s1.equals("Next"))
{
if(i>2)
{
s=new String("Y");
p3.removeAll();
f(s);
p3.repaint();
//System.out.println(i + s);


}
else
{
s=new String("N");
p3.removeAll();
f(s);
p3.repaint();
//System.out.println(i + s);
s=null;
}
i=i+1;
String s=getAppletInfo();
System.out.println(s);
}
}


public void paint(Graphics g)
{
//s=new String("N");//f(s);
p3.repaint();

}
public void update(Graphics g)
{
paint(g);
}

}

Tanveer Rameez
Ranch Hand

Joined: Dec 11, 2000
Posts: 158
hi
I am not sure, but you can write invalidate() in the method f()
after
System.out.println("in Y");
or after
System.out.println("in N);
and then
validate();
before calling paint() at the end of method f()

Writing invalidate() invalidates the previuos layout() and validate() would cause the new layout to be enforced
hope that helps
bye
Tanveer


Author of JPhotoBrush Pro (www.jphotobrushpro.com)
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Repaint and Applet
 
Similar Threads
Layout Problems
Layout problem
removeAll()
Display image in a BorderLayout
Layouts