Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

how to displaying different panels on action event

 
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...
 
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).]
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • 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


 
Dinner will be steamed monkey heads with a side of tiny ads.
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic