i have a GUI that has 3 menus:Read Files, Add, Finish. under the Add menu specifically, i have 3 menu items called add owner, add residential property and add commercial property. when clicking any of these menu items i have an internal frame come up but i do not want the internal frame to be the same for all menu items. i am trying to add a few more text fields for commercial and residential property compared to owner. so i do not qant the internal frame to be the same but unique for each menu item and that is where i am having trouble. here is the code
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
public class PropertyGUITest
{
public static void main(String[] args)
{
PropertyGUI obj = new PropertyGUI();
obj.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
obj.setSize(400,300);
obj.setVisible(true);
obj.setLocation(100,50);
}
}
class PropertyGUI extends JFrame
{
private int countFrames = 0;
public PropertyGUI()
{
super("Property GUI");
JMenuBar bar = new JMenuBar();
setJMenuBar(bar);
JMenu readMenu = new JMenu("Read Files");
bar.add(readMenu);
JMenu addMenu = new JMenu("Add");
bar.add(addMenu);
JMenuItem newFrame1=new JMenuItem("Add Owner");
addMenu.add(newFrame1);
JMenuItem newFrame2=new JMenuItem("Add Residential Property");
addMenu.add(newFrame2);
JMenuItem newFrame3=new JMenuItem("Add Commercial Property");
addMenu.add(newFrame3);
JMenu finishMenu = new JMenu("Finish");
bar.add(finishMenu);
JDesktopPane theDesktop = new JDesktopPane();
add(theDesktop);
JMenuItem writeItem = new JMenuItem("Write Owners");
finishMenu.add(writeItem);
JMenuItem readpItem = new JMenuItem("Read Properties");
readMenu.add(readpItem);
JMenuItem readoItem = new JMenuItem("Read Owners");
readMenu.add(readoItem);
JMenuItem exitItem = new JMenuItem("Exit");
exitItem.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
//System.exit(0);
dispose();
}
}
);
finishMenu.add(exitItem);
newFrame1.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
countFrames++;
JInternalFrame jf = new JInternalFrame("Add Owner",true,true,true,true);
theDesktop.add(jf);
jf.setVisible(true);
jf.pack();
jf.setSize(300,200);
jf.setLocation(countFrames*10,countFrames*20);
CustomPanel panel1 = new CustomPanel();
jf.add(panel1);
}
}
);
newFrame2.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
countFrames++;
JInternalFrame jf = new JInternalFrame("Add Residential Property",true,true,true,true);
theDesktop.add(jf);
jf.setVisible(true);
jf.pack();
jf.setSize(300,200);
jf.setLocation(countFrames*10,countFrames*20);
CustomPanel panel2 = new CustomPanel();
jf.add(panel2);
}
}
);
newFrame3.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
countFrames++;
JInternalFrame jf = new JInternalFrame("Add Commercial Property",true,true,true,true);
theDesktop.add(jf);
jf.setVisible(true);
jf.pack();
jf.setSize(300,200);
jf.setLocation(countFrames*10,countFrames*20);
CustomPanel panel3 = new CustomPanel();
jf.add(panel3);
}
}
);
}
class CustomPanel extends JPanel
{
JTextField tf1;
JTextField tf2;
JTextField tf3;
JTextField tf4;
JTextField tf5;
JLabel label1;
JLabel label2;
JLabel label3;
JLabel label4;
JLabel label5;
JLabel label6;
JButton button1;
public CustomPanel()
{
setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.weightx = 1;
gbc.anchor = GridBagConstraints.WEST;
gbc.insets = new Insets(2, 2, 2, 2);
add(new JLabel("Name"), gbc);
gbc.gridy++;
add(new JLabel("Street"), gbc);
gbc.gridy++;
add(new JLabel("City"), gbc);
gbc.gridy++;
add(new JLabel("State"), gbc);
gbc.gridy++;
add(new JLabel("Zip"), gbc);
gbc.gridy++;
add(new JLabel("Submit when done"), gbc);
JTextField[] fields = new JTextField[5];
gbc.gridx = 1;
gbc.gridy = 0;
gbc.weightx = 1;
gbc.fill = GridBagConstraints.HORIZONTAL;
add((fields[0] = new JTextField(10)), gbc);
gbc.gridy++;
add((fields[1] = new JTextField(10)), gbc);
gbc.gridy++;
add((fields[2] = new JTextField(10)), gbc);
gbc.gridy++;
add((fields[3] = new JTextField(10)), gbc);
gbc.gridy++;
add((fields[4] = new JTextField(10)), gbc);
gbc.gridy++;
JButton btn = new JButton("Submit");
add(btn, gbc);
}
}
}
for commercial and residential property i just want to add two more text fields for account number and price before the submit button.