IT_Programming/Java

JDialog Example

JJun ™ 2008. 8. 20. 08:50

 

 

 

 

 

  

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;
class mainFrame extends JFrame
{
public mainFrame(){
this.setSize(300,200);

this.setVisible(true);
new parentDLG();
}
public static void main(String[] ar){
new mainFrame();
}
}
class parentDLG implements MenuListener{
Container con;
mainFrame frame;
JDialog dlg = new JDialog(frame, true);
JMenu menu = new JMenu("메뉴");
JEditorPane edPane = new JEditorPane();
JScrollPane jsp = new JScrollPane(edPane);
public parentDLG(){
dlg.getContentPane().add(jsp);
JMenuBar jmb = new JMenuBar();
jmb.add(menu);
dlg.setJMenuBar(jmb);
menu.addMenuListener(this);
edPane.setContentType("text/html");
edPane.setText("hi");
dlg.setSize(200,200);
dlg.setVisible(true);
dlg.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
}
public void menuCanceled(MenuEvent e){}
public void menuDeselected(MenuEvent e){}
public void menuSelected(MenuEvent e){

if(e.getSource() == menu){

new subDLG(this.dlg);

}
}
}

class subDLG
{

JDialog ddd;
JDialog subdlg = new JDialog(ddd, true);

//// 소유자가 parentDLG다이얼로그이어야하고, parentDLG 다이얼로그 앞쪽에 보여져야함..

public subDLG(JDialog dlg) {

ddd=dlg;


subdlg.getContentPane().add(new JButton("aaa"));
subdlg.setSize(100,100);
subdlg.setVisible(true);
subdlg.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
}
};