import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/*class Nmain extends JDialog {
private JTextField tf = new JTextField(12);
private JButton ob = new JButton("Next");
public Nmain(JFrame frame, String title) {
super(frame, title, true);
ob.setForeground(Color.blue);
setLayout(new FlowLayout());
add(tf);
add(ob);
setSize(200, 100);
ob.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setVisible(false);
}
});
}
public String getInput() {
if (tf.getText().length() == 0)
return null;
else
return tf.getText();
}
}
public class Main extends JFrame {
private Nmain dialog;
public Main() {
super("Main 예제 프레임");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton bn = new JButton("다이얼로그 보이기");
dialog = new Nmain(this, "TSMD"); // 모달 디이얼로그
bn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dialog.setVisible(true);
String text = dialog.getInput();
if (text == null)
return;
JButton btn = (JButton) e.getSource();
btn.setText(text);
}
});
getContentPane().add(bn);
setSize(250,200);//MY NAME IS 직지,직지직지직지.
setVisible(true);
}*/
public class Main extends JFrame {
public Main() {
setTitle("옵션 팬 예제");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c = getContentPane();
setSize(500, 200);
c.add(new MyPanel(), BorderLayout.NORTH);
setVisible(true);
}
class MyPanel extends Panel {
private JButton ibt = new JButton("이름");
private JTextField tf = new JTextField(10);
private JButton cimb = new JButton("확인");
private JButton mess = new JButton("나가기");
public MyPanel() {
setBackground(Color.lightGray);
add(ibt);
add(tf);
add(cimb);
add(mess);
ibt.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
String name = JOptionPane.showInputDialog("What's your name??");
if (name != null)
tf.setText(name);
}
});
cimb.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
int result = JOptionPane.showConfirmDialog(null, "계속시겠습니다.", "OK!!", JOptionPane.YES_NO_OPTION);
if (result == JOptionPane.CLOSED_OPTION)
tf.setText("JUST CLOSED WITHOUT SELECTION!!!");
else if (result == JOptionPane.CLOSED_OPTION)
tf.setText("Y");
else
tf.setText("N");
}
});
mess.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
JOptionPane.showMessageDialog(null, "나가쉬겠습니다.", "MMS", JOptionPane.ERROR_MESSAGE);
}
});
}
}public static void main(String[] args) {
new Main();
}
}



