새소식

Java

[Java] JOptionPane

  • -

[Java] JOptionPane



import java.awt.*;
import java.awt.event.*;

import javax.swing.*;
//외부클래스
public class JOptionPaneTest extends JFrame {
Container con;
//외부클래스 생성자 구현
public JOptionPaneTest(){
  setTitle("JOptionPane 실습");
  setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  con = getContentPane();
 
  setBounds(500, 400, 500, 300);
  con.add(new myPanel(),BorderLayout.NORTH);
     setVisible(true);
}
//내부클래스 구현
 class myPanel extends JPanel{
 JButton inputbtn = new JButton("Input Name");
 JButton confirmbtn = new JButton("confirm");
 JButton messagebtn = new JButton("message");
 JTextField tf = new JTextField(10);
 //내부클래스의 생성자 구현
 public myPanel(){
  setBackground(Color.LIGHT_GRAY);
  add(inputbtn);
     add(confirmbtn);
     add(messagebtn);
     add(tf);
     //이벤트 연결 및 이벤트 핸들러 처리를 동시에
     inputbtn.addActionListener(new ActionListener() {
  @Override
  public void actionPerformed(ActionEvent e) {
  String name = JOptionPane.showInputDialog("이름을 입력하세요");
   tf.setText(name);
   
   
  }
 });
     confirmbtn.addActionListener(new ActionListener() {
  
  @Override
  public void actionPerformed(ActionEvent e) {
     int result = JOptionPane.showConfirmDialog(null, "계속하겠습니까?",
       "confirm 다이얼로그창",JOptionPane.YES_NO_OPTION);
     if(result == JOptionPane.YES_OPTION)
      tf.setText("Yes");
     else
      tf.setText("No");
  }
  });
     messagebtn.addActionListener(new ActionListener() {
  
  @Override
  public void actionPerformed(ActionEvent e) {
  JOptionPane.showMessageDialog(null, "message 다이얼로그 태스트","Message",JOptionPane.ERROR_MESSAGE);
  tf.setText("메세지 보여줌");
   
  }
 });
 }
 }

public static void main(String args[]){
 new JOptionPaneTest();
}

 
 }
 

'Java' 카테고리의 다른 글

[Java] 메모장 만들기(메뉴)  (0) 2012.11.03
[Java] 벡터클래스 테스트  (0) 2012.11.03
[Java] 금액을 화폐단위로 나누기  (0) 2012.11.03
[Java] JTable응용  (0) 2012.10.25
[Java] Jtable 만들기  (0) 2012.10.25
Contents

포스팅 주소를 복사했습니다

이 글이 도움이 되었다면 공감 부탁드립니다.