See this entire code:-
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class BankSimulator extends JMenuBar implements ActionListener
{
String accountItems[]={"New","Close","Exit"};
String transactionItems[]={"Deposit","Withdraw"};
JPanel p1,p2,p3;
static JDesktopPane desktop;
static JFrame f;
public BankSimulator()
{
JMenu accountMenu=new JMenu("Account");
JMenu transactionMenu=new JMenu("Transaction");
for(int i=0;i<accountItems.length;i++)
{
JMenuItem item=new JMenuItem(accountItems[i]);
item.addActionListener(this);
accountMenu.add(item);
}
for(int i=0;i<transactionItems.length;i++)
{
JMenuItem item=new JMenuItem(transactionItems[i]);
item.addActionListener(this);
transactionMenu.add(item);
}
accountMenu.insertSeparator(2);
BorderLayout bl=new BorderLayout();
FlowLayout fl1=new FlowLayout(FlowLayout.LEFT,10,20);
FlowLayout fl2=new FlowLayout(FlowLayout.CENTER,10,20);
p1=new JPanel();
p1.setLayout(bl);
p2=new JPanel();
p2.setLayout(fl1);
p3=new JPanel();
p3.setLayout(fl2);
desktop=new JDesktopPane();
add(accountMenu);
add(transactionMenu);
}
public void actionPerformed(ActionEvent e1)
{
String str=e1.getActionCommand();
if(str=="New")
{
JInternalFrame f1=new JInternalFrame("New Account",false,true,false,false);
f1.setLocation(360,160);
f1.setSize(300,300);
JLabel l1=new JLabel("Account No.");
JLabel l2=new JLabel("Name:");
JLabel l3=new JLabel("Amount:");
JTextField t1=new JTextField(35);
JTextField t2=new JTextField(25);
JButton b1=new JButton("Save");
JButton b2=new JButton("Cancel");
JButton b3=new JButton("Close");
p2.add(l2);
p2.add(t1);
p2.add(l3);
p2.add(t2); p3.add(b1); p3.add(b2); p3.add(b3);
p1.add(l1,"North");
p1.add(p3,"South");
p1.add(p2,"Center");
f1.add(p1);
desktop.add(f1);
f1.setVisible(true);
}
}
public static void main(String args[])
{
//BankSimulator bs=new BankSimulator();
f=new JFrame();
f.setLayout(new FlowLayout());
f.setJMenuBar(new BankSimulator());
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(desktop);
f.setSize(600,600);
f.setVisible(true);
}
}
Now what I want is when I click to the "New" button in "Account" Menu an internal frame should be opened at center of the frame and should contain the panels p1,p2,p3 in it.
can anybody help?


LinkBack URL
About LinkBacks
Reply With Quote