aspose file tools
The moose likes Applets and the fly likes how to displaying different panels on action event Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Applets
Reply Bookmark "how to displaying different panels on action event" Watch "how to displaying different panels on action event" New topic
Author

how to displaying different panels on action event

jos xavier
Greenhorn

Joined: Feb 02, 2001
Posts: 14
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

Joined: Mar 12, 2001
Posts: 12
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

Joined: Feb 02, 2001
Posts: 14
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

Joined: Oct 18, 2000
Posts: 4120

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


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
jos xavier
Greenhorn

Joined: Feb 02, 2001
Posts: 14
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

 
 
subject: how to displaying different panels on action event
 
Threads others viewed
grouping labels and buttons in a JPanel with other JPanels
JtabbedPane. How do i know on witch tab i am
Swing/JButton/JPanel
How do I find out if a change has been made on a panel
urgent ! swing design pattern
developer file tools