Article View: borland.public.jbuilder.java.swing
Article #124Call Jinternal from another in java
From: tolu45
Date: Tue, 14 Feb 2006 10:58
Date: Tue, 14 Feb 2006 10:58
628 lines
22028 bytes
22028 bytes
Hello,
I have a problem with the application i am developing. I have an main
frame and the others are InternalFrames. In my main frame i have the
menu bar which i use in calling one of the internalframes. After i
click a button on the displayed internalframe, i would like the current
internalframa to hide/close while it will make another Internalframe
visible. I have made t like this for control reasons.
Here is my main frame class:
/*
* Billing.java
*
* Created on 13. februar 2006, 14:33
*/
package systemInterface;
import billingsystem.Rooms;
import java.awt.*;
/**
*
* @author noah
*/
public class Billing extends javax.swing.JFrame {
/** Creates new form Billing */
public Billing() {
initComponents();
int inset = 0;
Dimension screenSize =
Toolkit.getDefaultToolkit().getScreenSize();
setBounds(inset, inset, screenSize.width, screenSize.height -
30);
/* addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
*/
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
private void initComponents() {
jDesktopPane1 = new javax.swing.JDesktopPane();
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
Restaurant = new javax.swing.JMenu();
jMenuItem1 = new javax.swing.JMenuItem();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jMenu1.setText("Menu");
jMenuBar1.add(jMenu1);
Restaurant.setText("Restaurant");
jMenuItem1.setText("Billing");
jMenuItem1.addActionListener(new
java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt)
{
jMenuItem1ActionPerformed(evt);
}
});
Restaurant.add(jMenuItem1);
jMenuBar1.add(Restaurant);
setJMenuBar(jMenuBar1);
org.jdesktop.layout.GroupLayout layout = new
org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jDesktopPane1,
org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 1031, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jDesktopPane1,
org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 496, Short.MAX_VALUE)
);
pack();
}// </editor-fold>
private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent
evt) {
// TODO add your handling code here:
RoomInterface roomForm = new RoomInterface();
roomForm.setVisible(true);
jDesktopPane1.add(roomForm);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Billing().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JMenu Restaurant;
private javax.swing.JDesktopPane jDesktopPane1;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JMenuItem jMenuItem1;
// End of variables declaration
}
here is my first internalframe class:
/*
* PurchaseInterface.java
*
* Created on 13. februar 2006, 10:24
*/
package systemInterface;
import java.awt.*;
import java.awt.GridLayout;
import java.awt.event.ActionListener;
import systemInterface.RoomInterface;
import java.awt.Button;
import java.awt.event.ActionEvent;
/**
*
* @author noah
*/
public class PurchaseInterface extends javax.swing.JInternalFrame
implements ActionListener {
/** Creates new form PurchaseInterface */
public PurchaseInterface() {
initComponents();
int inset = 0;
Dimension screenSize =
Toolkit.getDefaultToolkit().getScreenSize();
setBounds(inset, inset, screenSize.width, screenSize.height - 30);
init();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
private void initComponents() {
jpQuantity = new javax.swing.JPanel();
jBtn1 = new javax.swing.JButton();
jBtn2 = new javax.swing.JButton();
jBtn3 = new javax.swing.JButton();
jBtn4 = new javax.swing.JButton();
jBtn5 = new javax.swing.JButton();
jBtn6 = new javax.swing.JButton();
jBtn7 = new javax.swing.JButton();
jBtn8 = new javax.swing.JButton();
jBtn9 = new javax.swing.JButton();
jBtn10 = new javax.swing.JButton();
jBtnOK = new javax.swing.JButton();
jBtnClear = new javax.swing.JButton();
jTxtQuantity = new javax.swing.JTextField();
jpProdPanel = new javax.swing.JPanel();
jButton1 = new javax.swing.JButton();
jPanel1 = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane();
jList1 = new javax.swing.JList();
jBtnTotal = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
jBtn1.setText("1");
jBtn2.setText("2");
jBtn3.setText("3");
jBtn4.setText("4");
jBtn5.setText("5");
jBtn6.setText("6");
jBtn7.setText("7");
jBtn8.setText("8");
jBtn9.setText("9");
jBtn10.setText("0");
jBtnOK.setText("ok");
jBtnClear.setText("Clear");
org.jdesktop.layout.GroupLayout jpQuantityLayout = new
org.jdesktop.layout.GroupLayout(jpQuantity);
jpQuantity.setLayout(jpQuantityLayout);
jpQuantityLayout.setHorizontalGroup(
jpQuantityLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING,
jpQuantityLayout.createSequentialGroup()
.add(34, 34, 34)
.add(jpQuantityLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(org.jdesktop.layout.GroupLayout.LEADING,
jTxtQuantity, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 247,
Short.MAX_VALUE)
.add(jpQuantityLayout.createSequentialGroup()
.add(jpQuantityLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(jBtnOK,
org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 78, Short.MAX_VALUE)
.add(org.jdesktop.layout.GroupLayout.LEADING, jBtn7,
org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 78, Short.MAX_VALUE)
.add(org.jdesktop.layout.GroupLayout.LEADING, jBtn4,
org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 78, Short.MAX_VALUE)
.add(jBtn1,
org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 78, Short.MAX_VALUE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jpQuantityLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING,
false)
.add(org.jdesktop.layout.GroupLayout.LEADING, jBtn10, 0, 0,
Short.MAX_VALUE)
.add(org.jdesktop.layout.GroupLayout.LEADING, jBtn8,
org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(org.jdesktop.layout.GroupLayout.LEADING, jBtn5,
org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(org.jdesktop.layout.GroupLayout.LEADING, jBtn2,
org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 76, Short.MAX_VALUE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jpQuantityLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jBtnClear,
org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 81, Short.MAX_VALUE)
.add(jpQuantityLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING,
false)
.add(org.jdesktop.layout.GroupLayout.TRAILING, jBtn6,
org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(jBtn3,
org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 72, Short.MAX_VALUE)
.add(org.jdesktop.layout.GroupLayout.TRAILING, jBtn9,
org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 81, Short.MAX_VALUE)))))
.addContainerGap())
);
jpQuantityLayout.setVerticalGroup(
jpQuantityLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jpQuantityLayout.createSequentialGroup()
.add(43, 43, 43)
.add(jTxtQuantity,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 48,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(75, 75, 75)
.add(jpQuantityLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jBtn2,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 53,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jBtn3,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 51,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jBtn1,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 53,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(6, 6, 6)
.add(jpQuantityLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jBtn5,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 55,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jBtn4,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 50,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jBtn6,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 55,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED,
org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(jpQuantityLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jBtn8,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 50,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jBtn7,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 49,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jBtn9,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 49,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(jpQuantityLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jpQuantityLayout.createSequentialGroup()
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jBtn10,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 52,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(jpQuantityLayout.createSequentialGroup()
.add(45, 45, 45)
.add(jpQuantityLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jBtnClear,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 48,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jBtnOK,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 50,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))
.add(63, 63, 63))
);
jButton1.setText("jButton1");
org.jdesktop.layout.GroupLayout jpProdPanelLayout = new
org.jdesktop.layout.GroupLayout(jpProdPanel);
jpProdPanel.setLayout(jpProdPanelLayout);
jpProdPanelLayout.setHorizontalGroup(
jpProdPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jpProdPanelLayout.createSequentialGroup()
.add(21, 21, 21)
.add(jButton1)
.addContainerGap(102, Short.MAX_VALUE))
);
jpProdPanelLayout.setVerticalGroup(
jpProdPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jpProdPanelLayout.createSequentialGroup()
.add(66, 66, 66)
.add(jButton1)
.addContainerGap(385, Short.MAX_VALUE))
);
jList1.setModel(new javax.swing.AbstractListModel() {
String[] strings = { "Item 1", "Item 2", "Item 3", "Item
4", "Item 5" };
public int getSize() { return strings.length; }
public Object getElementAt(int i) { return strings[i]; }
});
jScrollPane1.setViewportView(jList1);
jBtnTotal.setText("Total");
org.jdesktop.layout.GroupLayout jPanel1Layout = new
org.jdesktop.layout.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1Layout.createSequentialGroup()
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1Layout.createSequentialGroup()
.add(83, 83, 83)
.add(jBtnTotal,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 120,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.add(jScrollPane1,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 266,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.add(jScrollPane1,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 337,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jBtnTotal,
org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 31, Short.MAX_VALUE)
.addContainerGap())
);
org.jdesktop.layout.GroupLayout layout = new
org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING,
layout.createSequentialGroup()
.addContainerGap(235, Short.MAX_VALUE)
.add(jpProdPanel,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jpQuantity,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jPanel1,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(29, 29, 29))
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap(102, Short.MAX_VALUE)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jpQuantity,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 438,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(layout.createSequentialGroup()
.add(28, 28, 28)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(jPanel1,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jpProdPanel,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))
.addContainerGap())
);
pack();
}// </editor-fold>
/**
* @param args the command line arguments
*/
// Variables declaration - do not modify
private javax.swing.JButton jBtn1;
private javax.swing.JButton jBtn10;
private javax.swing.JButton jBtn2;
private javax.swing.JButton jBtn3;
private javax.swing.JButton jBtn4;
private javax.swing.JButton jBtn5;
private javax.swing.JButton jBtn6;
private javax.swing.JButton jBtn7;
private javax.swing.JButton jBtn8;
private javax.swing.JButton jBtn9;
private javax.swing.JButton jBtnClear;
private javax.swing.JButton jBtnOK;
private javax.swing.JButton jBtnTotal;
private javax.swing.JButton jButton1;
private javax.swing.JList jList1;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextField jTxtQuantity;
private javax.swing.JPanel jpProdPanel;
private javax.swing.JPanel jpQuantity;
// End of variables declaration
}
the second internal frame i want to call is like this:
/*
* Rooms.java
*
* Created on 13. februar 2006, 11:44
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package billingsystem;
import java.awt.*;
import java.awt.GridLayout;
import java.awt.event.ActionListener;
import systemInterface.RoomInterface;
import java.awt.Button;
import java.awt.event.ActionEvent;
import javax.swing.JFrame;
import systemInterface.PurchaseInterface;
import javax.swing.JInternalFrame;
/**
*
* @author noah
*/
public class Rooms extends javax.swing.JInternalFrame implements
ActionListener {
int roomNum =0;
Button[] roomButton = new Button[5];
Container content = getContentPane();
PurchaseInterface newPurchase = new PurchaseInterface();
Rooms room = new Rooms();
/** Creates a new instance of Rooms */
public Rooms() {
init();
int inset = 0;
Dimension screenSize =
Toolkit.getDefaultToolkit().getScreenSize();
setBounds(inset, inset, screenSize.width, screenSize.height - 30);
}
public void setRoomNumber(int rmNumber){
roomNum= rmNumber;
}
public int getRoomNumber(){
return this.roomNum;
}
// Attributes
String slogan = "Java Online";
Button[] toolBar = new Button[5];
public void init()
{
// 1. Toolbar Panel
Panel p = new Panel();
p.setLayout(new GridLayout(0,4));
p.setBackground(Color.lightGray);
// 2. Create the toolBar Buttons
String[] captions =
{ "Red", "Blue", "Green", "Yellow", "Black" };
for (int i = 0; i < toolBar.length; i++)
{
toolBar[i] = new Button(captions[i]);
toolBar[i].addActionListener(this);
p.add(toolBar[i]);
}
// 3. Add the Panel to the top of the applet
//setLayout(new BorderLayout());
content.add(p, "North");
}
public void actionPerformed(ActionEvent ae)
// Here we call the form that is related to purchase using query
based on the room selected
{
// 1. Retrieve source of click
Object obj = ae.getSource();
// 2. Match it with toolBar Button
int clicked;
for (clicked = 0; clicked < toolBar.length; clicked++)
{
if (obj == toolBar[clicked])
break;
}
PurchaseInterface newPurchase = new PurchaseInterface();
Rooms room = new Rooms();
// 3. Take action based upon Button pressed
switch (clicked)
{
case 0: newPurchase.setVisible(true); room.setEnabled(false);
break;//content.setBackground(Color.red);
case 1: content.setBackground(Color.blue); break;
case 2: content.setBackground(Color.green); break;
case 3: content.setBackground(Color.yellow); break;
case 4: content.setBackground(Color.black); break;
}
//repaint();
}
}
Technical Details
Message-ID:
<1139914699.263963.313820@z14g2000cwz.googlegroups.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!postnews.google.com!z14g2000cwz.googlegroups.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 111d45,7975bb084ed9c256,start X-Google-Attributes: gid111d45,public X-Google-Language: ENGLISH,ASCII-7-bit Path: arc1-ca.pugleaf.net!g2news1.google.com!postnews.google.com!z14g2000cwz.googlegroups.com!not-for-mail From: tolu45@gmail.com Newsgroups: borland.public.jbuilder.java.swing Subject: Call Jinternal from another in java Date: 14 Feb 2006 02:58:19 -0800 Organization: http://groups.google.com Lines: 629 Message-ID: <1139914699.263963.313820@z14g2000cwz.googlegroups.com> NNTP-Posting-Host: 193.88.144.166 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1139914710 5540 127.0.0.1 (14 Feb 2006 10:58:30 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 14 Feb 2006 10:58:30 +0000 (UTC) User-Agent: G2/0.2 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322),gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: z14g2000cwz.googlegroups.com; posting-host=193.88.144.166; posting-account=3QZUHg0AAACb_7bRn8rvC3AUKeuFIU1F