private Container con;
private JLabel lb = new JLabel(" ID : ",JLabel.RIGHT); // 아이디 라벨
private JTextField tf = new JTextField(10); //텍스트 필드
private JDialog dlg = new JDialog(this,"확인"); // 확인 다이얼로그
private Container dlgcon;
private JLabel dlglb = new JLabel(" 사용할 수 있는 ID 입니다.",JLabel.CENTER); // 다이얼로그 라벨
private BorderLayout dlgbl = new BorderLayout(); // 다이얼로그 레이아웃 매니저
public Exam08_sub(){
super("Exam08");
this.init();
this.start();
this.setSize(300,200);
this.setVisible(true);
}
public void init(){
con = this.getContentPane();
con.setLayout(new FlowLayout());
con.add(lb);
con.add(tf);
dlgcon = dlg.getContentPane(); // 다이얼로그 컨테이너 얻어옴
dlgcon.setLayout(dlgbl); // 다이얼로그 레이아웃 지정
dlglb.setBorder(new BevelBorder(BevelBorder.RAISED)); // 다이얼로그 보더 지정
dlgcon.add("Center",dlglb); //콘테이너에, 라벨 추가
dlg.setSize(200, 150); // 다이얼로그 사이즈 지정
Toolkit tk = Toolkit.getDefaultToolkit(); // 정 중앙에 라벨 뜨도록 설정
Dimension di = tk.getScreenSize();
Dimension di1 = this.getSize();
dlg.setLocation((int)(di.getWidth() / 2 - di1.getWidth()),(int)(di.getHeight() / 2 - di1.getHeight() /2));
}
public void start(){
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // 프레임 종료
tf.addActionListener(this);
dlg.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); // 다이얼로그 하이드
}
public void actionPerformed(ActionEvent e){
if(e.getSource() == tf){ // 텍스트필드에서 엔터 칠 경우 다이얼로그 뷰
dlg.setVisible(true);
}
그 외에 , 메뉴 바 등, 프레임과 동일한 기능 다이얼로그서 사용 가능
'JAVA > Swing' 카테고리의 다른 글
JOption Pane (0) | 2013.02.26 |
---|---|
스크롤 패인 , 콤보박스, 리스트 (0) | 2013.02.26 |
BOX 로 버튼 정렬 (0) | 2013.02.26 |
JButton 과 Border 그리고 메뉴 바 (0) | 2013.02.26 |
JFrame 과, IConImage (0) | 2013.02.26 |