java - How to add internal frame to menu -


i have gui has 3 menus:read files, add, finish. under add menu specifically, have 3 menu items called add owner, add residential property , add commercial property. when clicking of these menu items have internal frame come not want internal frame same menu items. trying add few more text fields commercial , residential property compared owner. not qant internal frame same unique each menu item , having trouble. here 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 , residential property want add 2 more text fields account number , price before submit button.

i not qant internal frame same unique each menu item , having trouble.

custompanel panel1 = new custompanel(); ... custompanel panel2 = new custompanel(); ... custompanel panel3 = new custompanel(); 

then can't use same panel.

you need 3 different panels. need:

  1. "ownerpanel"
  2. "residentialpanel"
  3. "commercialpanel"

don't try internal frames use same panel if data different each panel.

//custompanel panel1 = new custompanel(); ownerpanel panel1 = new ownerpanel(); ... //custompanel panel2 = new custompanel(); residentialpanel panel2 = new residentialpanel(); ... //custompanel panel3 = new custompanel(); commercialpanel panel3 = new commercialpanel(); 

Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -