Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie --- How to call an internalFrame after clicking a button?

Status
Not open for further replies.

huiyanx2

Technical User
Nov 1, 2002
11
HK
Hi all,

Do you know how to call new internalFrame after clicking a Jbutton in other internal Frame? As I use MDI, I don't know how to add that new internalFrame to my destop manager ?
Also, Should I use 'AddInternalFrameListener' instead of addActonListener in internalFrame? If yes, what is the method should I use to replace 'actionPerformed'?

Following is part of my coding:

public class lw_SearchPO extends JInternalFrame implements InternalFrameListener, ActionListener{

JButton jButton1 = new JButton();

private void jbInit() throws Exception {
jButton1.setText("Search");
jButton1.addActionListener(new
java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton1_actionPerformed(e);
}
});

void jButton1_actionPerformed(ActionEvent e) {
MainFrame_Pur MainFrame_Pur = new MainFrame_Pur();
lw_updatePO lw_updatePO = new lw_updatePO();
lw_updatePO.addInternalFrameListener(this);

// Can't access desktop even desktop is declared public!
MainFrame_Pur.desktop.add(lw_updatePO);
lw_updatePO.show();
lw_updatePO.pack();
lw_updatePO.setVisible(true);
}

}

Thanks!

Joyce

 
Hi huiyanx2:

You are doing it right, but you need to receive a pointer to the Main class to access its desktop. In the constructor:

public lw_SearchPO(<MainFrame_Pur class name (type)> parent)

Then declare the parent public and access its desktop.

If the desktop is public, your class must be able to reach it.

For the actionListener issue, it depends on why do you want to add an InternalFrameListener. If you want the main application to be notified of the button event, the actionlistener added to the button should notify the Event Manager of the application, so it will be enough.

Hope it helps. Pedro Andrés Solorzano
Pontificia Universidad Javeriana
Bogotá, Colombia, SurAmérica.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top