some problems when My Base Class is Extended with JDialog.
hello everybody,
I have a problem here. similar problem has been faced by different developers, but mine is little different form them.
pls have a look at the code..
package thepack;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
class MyWindowextends JFrameimplements ActionListener{
JButton btnok, btncancel ;
Container con;
JPanel pansouth;
JMenuBar menubar;
JMenu menu;
JMenuItem menuitem;
MyWindow(){
// TODO Auto-generated constructor stub
con = this.getContentPane();
con.setLayout(new BorderLayout());
menubar =new JMenuBar();
//Build the first menu.
menu =new JMenu("A Menu");
menu.setMnemonic(KeyEvent.VK_A);
menubar.add(menu);
menuitem =new JMenuItem("Add New Employee ",
KeyEvent.VK_E);
menu.add(menuitem);
this.setJMenuBar(menubar);
btnok =new JButton("OK");
btncancel =new JButton("cancel");
pansouth =new JPanel(new FlowLayout());
con.add(pansouth, BorderLayout.SOUTH);
pansouth.add(btnok);
pansouth.add(btncancel);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
btncancel.addActionListener(this);
menuitem.addActionListener(this);
}
publicvoid actionPerformed(ActionEvent arg0){
// TODO Auto-generated method stub
if(arg0.getSource()== btncancel)
{
System.exit(0);
}
elseif (arg0.getSource()== menuitem)
{
NewEmpWin emp =new NewEmpWin(this);
}
}
}
package thepack;
publicclass SampleWinextends JDialog{
Container con;
JButton btnok, btncancel;
JPanel pansouth;
public SampleWin(MyWindow window){
// TODO Auto-generated constructor stub
super(window,true);
System.out.println("we are in main of samp win");
con = this.getContentPane();
con.setLayout(new BorderLayout());
btnok =new JButton("OK");
btncancel =new JButton("cancel");
pansouth =new JPanel(new FlowLayout());
con.add(pansouth, BorderLayout.SOUTH);
pansouth.add(btnok);
pansouth.add(btncancel);
System.out.println("end of we are in main of samp win befor ini");
this.setSize(400,500);
this.setLocation(300, 300);
this.setResizable(false);
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
this.setVisible(true);
System.out.println("end of we are in main of samp win");
}
}
package thepack;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JLabel;
publicclass NewEmpWinextends SampleWinimplements ActionListener{
JLabel lfname ;
public NewEmpWin(MyWindow window){
// TODO Auto-generated constructor stub
super(window);
System.out.println("we are in main of new emp win");
lfname =new JLabel("first name");
con.add(lfname, BorderLayout.CENTER);
btncancel.addActionListener(this);
btnok.addActionListener(this);
System.out.println("end of we are in main of new emp win");
}
publicvoid actionPerformed(ActionEvent e){
// TODO Auto-generated method stub
if(e.getSource()== btnok)
{
lfname.setText("yes");
// some code
}
elseif (e.getSource()== btncancel)
{
lfname.setText("cancel");
this.dispose();
}
}
}
here i have created a sample modal dialog in sampleWin. and it is extended by NewEmpWin.
in NewEmpwin i have added some components.
but i fear that constructor of NewEmpWin is not getting called. so i cannot see the components added in it , but i can see only ok and cancel.
can some one help me.

