• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 380
  • Last Modified:

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?
0
SEstudent
Asked:
SEstudent
  • 6
  • 4
  • 3
  • +1
1 Solution
 
girionisCommented:
 Are you talking with interfaces with regards to Java terminology or interfaces as in "user interface"?
0
 
SEstudentAuthor Commented:

I mean user interface..
0
 
girionisCommented:
 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
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
yasser_helmyCommented:
Use the CardLayout layout manager in the panel.. when the button is pressed, how the right card..
0
 
yasser_helmyCommented:
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(managerPanel, "manager");
cl.addLayoutComponent(employeePanel, "Employee");
//add the layout to the master panel
masterPanel.setLayout(cl);

//when the button is pressed
cl.show(masterPanel, "manager");
0
 
SEstudentAuthor Commented:

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?
0
 
girionisCommented:
 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.
0
 
SEstudentAuthor Commented:

can you help me please with the code that will load the class to me?
0
 
SEstudentAuthor Commented:

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("Manager");
    btnManager.addActionListener(new Frame1_btnManager_actionAdapter(this));
    contentPane.setLayout(xYLayout1);
    this.setSize(new Dimension(400, 300));
    this.setTitle("Frame Title");
    btnEmployee.setText("Employee");
    btnEmployee.addActionListener(new Frame1_btnEmployee_actionAdapter(this));
    lblPosition.setText("Choose Your Position");
    contentPane.add(btnManager, new XYConstraints(146, 102, 112, -1));
    contentPane.add(btnEmployee,   new XYConstraints(147, 156, 113, 24));
    contentPane.add(lblPosition,   new XYConstraints(25, 30, 115, 26));
    mngr = new ManagerUI(this, true);
    empl = new EmployeeUI(this, true);
  }
  //Overridden so we can exit when window is closed
  protected void processWindowEvent(WindowEvent e) {
    super.processWindowEvent(e);
    if (e.getID() == WindowEvent.WINDOW_CLOSING) {
      System.exit(0);
    }
  }

  void btnManager_actionPerformed(ActionEvent e) {
    mngr.setName("Manager");
    mngr.show();

  }

  void btnEmployee_actionPerformed(ActionEvent e) {
    empl.setName("Employee");
    empl.show();
  }
}

class Frame1_btnManager_actionAdapter implements java.awt.event.ActionListener {
  Frame1 adaptee;

  Frame1_btnManager_actionAdapter(Frame1 adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
    adaptee.btnManager_actionPerformed(e);
  }
}

class Frame1_btnEmployee_actionAdapter implements java.awt.event.ActionListener {
  Frame1 adaptee;

  Frame1_btnEmployee_actionAdapter(Frame1 adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
    adaptee.btnEmployee_actionPerformed(e);
  }
}

===================================

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.WINDOW_EVENT_MASK);

    try {
      jbInit();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }
  public ManagerUI(){
   this(null,false);
 }

  private void jbInit() throws Exception {
    lblCompNum.setText("Choose a Complaint");
    xYLayout1.setWidth(450);
    xYLayout1.setHeight(643);
    jPanel1.setLayout(xYLayout1);
    lblTech.setText("Choose a Technician");
    btnComplaints.setText("Show Complaints");
    txtComplaints.setText("");
    txtMDetail.setText("");
    lblSelect.setText("Select a complaint to");
    btnChange.setText("Change Status");
    btnShowDetail.setText("Show Details");
    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,  new XYConstraints(163, 139, 134, 28));
    jPanel1.add(jScrollPane2, new XYConstraints(23, 418, 405, 153));
    jScrollPane2.getViewport().add(txtMDetail, null);
    jScrollPane1.getViewport().add(txtComplaints, null);
    jPanel1.add(lblSelect,  new XYConstraints(22, 350, 105, 22));
    jPanel1.add(btnShowDetail,    new XYConstraints(297, 376, -1, 26));
    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..
0
 
girionisCommented:
 Try to add the jpanel to the dialog itself. Try this:

  this.getContentPane().add(jpanel);
0
 
yasser_helmyCommented:
You have 2 problems:
1- The ManagerUI dialog doesnt have a size.. the default is 0x0.. then only the title bar appears and you have to resize the dialog..
2- you have not added jpanel1 to the dialog.. so when the dialog opens the jpanel1 is created but not added to the dialog..
i think you re using jbuilder.. drag the jpanel1 into the dialog area..  in the jbinit() method you should find these lines..
contentPane = (JPanel) this.getContentPane();
contentPane.add(jPanel1);
0
 
SEstudentAuthor Commented:

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,,
0
 
SEstudentAuthor Commented:

now it works..thanks alot :)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 4
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now