/* import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Main extends JFrame {
JLabel imgLabel = new JLabel();
public Main() {
setTitle("menu만들기 예제");
createmenu();
getContentPane().add(imgLabel,BorderLayout.CENTER);
setSize(1000,1000);
setVisible(true);
}
private void createmenu() {
JMenuBar mb = new JMenuBar();
JMenuItem [] menuItem = new JMenuItem[4];
String[] itemTitle = {"load","hide","reshow","exit"};
JMenu screenMenu = new JMenu("screen");
MenuActionListener listner = new MenuActionListener();
for(int i=0;i<menuItem.length;i++) {
menuItem[i] = new JMenuItem(itemTitle[i]);
menuItem[i].addActionListener(listner);
screenMenu.add(menuItem[i]);
}
mb.add(screenMenu);
setJMenuBar(mb);
}
class MenuActionListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
String cmd = e.getActionCommand();
switch (cmd) {
case "load":
if(imgLabel.getIcon() != null)
return;
imgLabel.setIcon(new ImageIcon("free-icon-flower-697433.png"));
break;
case "hide":
imgLabel.setVisible(false);
break;
case "reshow":
imgLabel.setVisible(true);
break;
case "exit":
System.exit(0);
break;
}
}
}
public static void main(String[] args) {
new Main();
}
}*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class MyDialog extends JDialog{
private JTextField tf = new JTextField(10);
private JButton okButton = new JButton("ok");
public MyDialog(JFrame frame, String title){
super(frame,title);
setLayout(new FlowLayout());
add(tf);
add(okButton);
setSize(200,200);
okButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
setVisible(false);
}
});
}
}
class Main extends JFrame{
private MyDialog dialog;
public Main() {
super("dialogex 에제 프레임");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton btn = new JButton("show Dialog");
dialog = new MyDialog(this, "test dialog");
btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dialog.setVisible(true);
}
});
getContentPane().add(btn);
setSize(250,250);
setVisible(true);
}
public static void main(String[] args) {
new Main();
}
}