Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Repaint and Applet

 
Pragnesh Shah
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic