SEstudent
asked on
connecting interfaces
Hi..
If I want to connect to interfaces with each othre..
so if I click the button (e.g manager)..I will be able to see the manager interface..
How can I do that?
Are you talking with interfaces with regards to Java terminology or interfaces as in "user interface"?
ASKER
I mean user interface..
Just call the class that implements the manager interface when the user clicks on a button. Add an actionListener to the button and then when an ActionEvent if fired use it to check for the button. If it is the button you want then load the class.
Take a look here for more info of how to use buttons and events: http://java.sun.com/docs/books/tutorial/uiswing/components/button.html
Take a look here for more info of how to use buttons and events: http://java.sun.com/docs/books/tutorial/uiswing/components/button.html
Use the CardLayout layout manager in the panel.. when the button is pressed, how the right card..
this is a sample code.. note that it is not tested..
//create the master panel
JPanel masterPanel=new JPanel();
//create the layout manager
CardLayout cl=new CardLayout();
cl.addLayoutComponent(mana gerPanel, "manager");
cl.addLayoutComponent(empl oyeePanel, "Employee");
//add the layout to the master panel
masterPanel.setLayout(cl);
//when the button is pressed
cl.show(masterPanel, "manager");
//create the master panel
JPanel masterPanel=new JPanel();
//create the layout manager
CardLayout cl=new CardLayout();
cl.addLayoutComponent(mana
cl.addLayoutComponent(empl
//add the layout to the master panel
masterPanel.setLayout(cl);
//when the button is pressed
cl.show(masterPanel, "manager");
ASKER
thanks all for your comments..
but what if I have already created two user interfaces in two different classes..
The first is called "ManagerUI" .. and the second class in "EmployeeUI"..
what do I have to add to the actionlistener in order to be able to show the other class UI only?
Add the actionListener to the button. When a button is pressed an action event will be send to the actionPerformed method. You need to check the event and see which button is pressed. If the button is the one for the ManagerUI then load that class otherwise load the other one. Take a look at the link I posted it contains several examples of how you can do it.
ASKER
can you help me please with the code that will load the class to me?
ASKER
now I have these two classes:
package helpdesk;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.borland.jbcl.layout.*;
public class Frame1 extends JFrame {
JPanel contentPane;
JToggleButton btnManager = new JToggleButton();
XYLayout xYLayout1 = new XYLayout();
JButton btnEmployee = new JButton();
JLabel lblPosition = new JLabel();
ManagerUI mngr;
EmployeeUI empl;
//Construct the frame
public Frame1() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
contentPane = (JPanel) this.getContentPane();
btnManager.setText("Manage
btnManager.addActionListen
contentPane.setLayout(xYLa
this.setSize(new Dimension(400, 300));
this.setTitle("Frame Title");
btnEmployee.setText("Emplo
btnEmployee.addActionListe
lblPosition.setText("Choos
contentPane.add(btnManager
contentPane.add(btnEmploye
contentPane.add(lblPositio
mngr = new ManagerUI(this, true);
empl = new EmployeeUI(this, true);
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowE
super.processWindowEvent(e
if (e.getID() == WindowEvent.WINDOW_CLOSING
System.exit(0);
}
}
void btnManager_actionPerformed
mngr.setName("Manager");
mngr.show();
}
void btnEmployee_actionPerforme
empl.setName("Employee");
empl.show();
}
}
class Frame1_btnManager_actionAd
Frame1 adaptee;
Frame1_btnManager_actionAd
this.adaptee = adaptee;
}
public void actionPerformed(ActionEven
adaptee.btnManager_actionP
}
}
class Frame1_btnEmployee_actionA
Frame1 adaptee;
Frame1_btnEmployee_actionA
this.adaptee = adaptee;
}
public void actionPerformed(ActionEven
adaptee.btnEmployee_action
}
}
==========================
package helpdesk;
import javax.swing.*;
import com.borland.jbcl.layout.*;
import java.awt.*;
public class ManagerUI extends JDialog {
JPanel jPanel1 = new JPanel();
XYLayout xYLayout1 = new XYLayout();
JLabel lblCompNum = new JLabel();
JComboBox jComboBox1 = new JComboBox();
JLabel lblTech = new JLabel();
JComboBox jComboBox2 = new JComboBox();
JButton btnComplaints = new JButton();
JScrollPane jScrollPane1 = new JScrollPane();
JTextArea txtComplaints = new JTextArea();
JScrollPane jScrollPane2 = new JScrollPane();
JTextArea txtMDetail = new JTextArea();
JLabel lblSelect = new JLabel();
JButton btnChange = new JButton();
JButton btnShowDetail = new JButton();
public ManagerUI(JFrame frame, boolean modal) {
super(frame, modal);
enableEvents(AWTEvent.WIND
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
public ManagerUI(){
this(null,false);
}
private void jbInit() throws Exception {
lblCompNum.setText("Choose
xYLayout1.setWidth(450);
xYLayout1.setHeight(643);
jPanel1.setLayout(xYLayout
lblTech.setText("Choose a Technician");
btnComplaints.setText("Sho
txtComplaints.setText("");
txtMDetail.setText("");
lblSelect.setText("Select a complaint to");
btnChange.setText("Change Status");
btnShowDetail.setText("Sho
jPanel1.add(lblCompNum, new XYConstraints(100, 36, 103, 20));
jPanel1.add(jComboBox1, new XYConstraints(226, 36, 124, 22));
jPanel1.add(lblTech, new XYConstraints(101, 82, 101, 23));
jPanel1.add(jComboBox2, new XYConstraints(227, 84, 125, 22));
jPanel1.add(jScrollPane1, new XYConstraints(22, 190, 406, 152));
jPanel1.add(btnComplaints,
jPanel1.add(jScrollPane2, new XYConstraints(23, 418, 405, 153));
jScrollPane2.getViewport()
jScrollPane1.getViewport()
jPanel1.add(lblSelect, new XYConstraints(22, 350, 105, 22));
jPanel1.add(btnShowDetail,
jPanel1.add(btnChange, new XYConstraints(94, 377, 106, 24));
}
public void setName(String na){
this.setTitle(na);
}
}
=========================
and when I click on the Manager button from the first class..I could only see the title bar of the manager interface..
could any one help me with this please..
Try to add the jpanel to the dialog itself. Try this:
this.getContentPane().add( jpanel);
this.getContentPane().add(
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks alot..
I create the HelpDeskUI Using application so I have (frame1)..but I create the ManagerUI by openning a class and use the design to drag different components..
I can't find dialog area in here..
waiting for your answers
thanks in advance,,
ASKER
now it works..thanks alot :)