• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to displaying different panels on action event

 
jos xavier
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
My problem is that I am creating an applet which should be able to change panels. E.g. i have an add, delete, edit and view buttons. Each button should change the panel. I am using border layout and I want to change the panels for each button...
Can anyone tell me how to do it...
 
Matthew Gaunt
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you mean change that each button changes a certain region of the border layout (ie-North South East West Center).
It is a little difficult to understand what section of the panel is supposed to change when you press the buttons. And where are the buttons positioned?
Best Regards
Matt
 
jos xavier
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Matt for your reply...
My applet is as follows :
import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class Cust extends Applet implements ActionListener{
Label Msg= new Label("");
TextField tf = new TextField("hi",10);
Panel PanMain,pNorth,pCenter;
BorderLayout blMain;
Button bAdd,bEdit,bDel,bView,EditChk,AddChk;

public void init() {
PanMain = new Panel();
blMain = new BorderLayout();
PanMain.setLayout(blMain);
String PanMainCol= "#17518b";
add(PanMain);
pNorth = new Panel();
PanMain.add(pNorth,blMain.NORTH);
pNorth.setBackground(new Color("#fccffc".hashCode()));
bAdd = new Button("ADD");
bEdit = new Button("EDIT");
bDel = new Button("DELETE");
bView = new Button("VIEW");
pNorth.add(bAdd);
pNorth.add(bEdit);
pNorth.add(bDel);
pNorth.add(bView);
pNorth.add(tf);
bAdd.addActionListener(this);
bEdit.addActionListener(this);
bDel.addActionListener(this);
bView.addActionListener(this);
tf.addActionListener(this);
addPanel("789789789");
}

public void actionPerformed (ActionEvent ae) {
if (ae.getSource()==bAdd) {
tf.setText("Adding Records");
pCenter.removeAll();
addPanel("567567567");
pCenter.validate();
}

if (ae.getSource()==bEdit) {
tf.setText("Editing Records");
pCenter.removeAll();
addPanel("123123123");
pCenter.validate();
}
}

public void addPanel(String ColorVal) {
pCenter= new Panel();
PanMain.add(pCenter,blMain.SOUTH);
pCenter.setBackground(new Color(ColorVal.hashCode()));
pCenter.add(new Button(ColorVal));
}
}
Originally posted by Matthew Gaunt:
Do you mean change that each button changes a certain region of the border layout (ie-North South East West Center).
It is a little difficult to understand what section of the panel is supposed to change when you press the buttons. And where are the buttons positioned?
Best Regards
Matt

[This message has been edited by Stephanie Grasson (edited March 13, 2001).]
[This message has been edited by Stephanie Grasson (edited March 13, 2001).]
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jos,

Another perfect example for using CardLayout...
Look here for another post mentioning this... ( http://www.javaranch.com/ubb/Forum2/HTML/000907.html )
If you need any further help with CardLayout, just ask...
HTH,
-Nate
 
jos xavier
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much fro your reply.....
I have got it working..
thanks once again
jos xavier

Originally posted by Nathan Pruett:
jos,

Another perfect example for using CardLayout...
Look here for another post mentioning this... ( http://www.javaranch.com/ubb/Forum2/HTML/000907.html )
If you need any further help with CardLayout, just ask...
HTH,
-Nate

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic