• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

how to displaying different panels on action event

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).]
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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


 
Poop goes in a willow feeder. Wipe with this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic