Solved

connecting interfaces

Posted on 2003-11-18
14
368 Views
Last Modified: 2010-03-31

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
Comment
Question by:SEstudent
  • 6
  • 4
  • 3
  • +1
14 Comments
 
LVL 35

Expert Comment

by:girionis
ID: 9769736
 Are you talking with interfaces with regards to Java terminology or interfaces as in "user interface"?
0
 

Author Comment

by:SEstudent
ID: 9769748

I mean user interface..
0
 
LVL 35

Expert Comment

by:girionis
ID: 9769793
 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
 
LVL 3

Expert Comment

by:yasser_helmy
ID: 9770075
Use the CardLayout layout manager in the panel.. when the button is pressed, how the right card..
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9770122
0
 
LVL 3

Expert Comment

by:yasser_helmy
ID: 9770140
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
 

Author Comment

by:SEstudent
ID: 9771688

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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 35

Expert Comment

by:girionis
ID: 9771977
 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
 

Author Comment

by:SEstudent
ID: 9776476

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

Author Comment

by:SEstudent
ID: 9780800

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
 
LVL 35

Expert Comment

by:girionis
ID: 9785245
 Try to add the jpanel to the dialog itself. Try this:

  this.getContentPane().add(jpanel);
0
 
LVL 3

Accepted Solution

by:
yasser_helmy earned 100 total points
ID: 9785779
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
 

Author Comment

by:SEstudent
ID: 9785846

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
 

Author Comment

by:SEstudent
ID: 9786262

now it works..thanks alot :)
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn how to implement Singleton Design Pattern in Java.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now