king431
发贴: 13
积分: 0
|
于 2005-09-06 18:32
import java.awt.*; import java.awt.event.*;
public class Dialog extends Frame implements ActionListener { Button btnExit; Button btnYes; Button btnNo; Dialog dlgConfirm; public Dialog() { btnExit=new Button("Eixt"); btnExit.addActionListener(this); add(btnExit); setLayout(new FlowLayout()); dlgConfirm=new Dialog(); dlgConfirm.setResizable(false); btnYes=new Button("Y"); btnYes.addActionListener(this); btnNo=new Button("N"); btnNo.addActionListener(this); dlgConfirm.add(btnYes); dlgConfirm.add(btnNo); dlgConfirm.setTitle("SY?"); dlgConfirm.setSize(200,100); dlgConfirm.setLayout(new FlowLayout()); addWindowListener(new WinCloser()); setTitle("Using a Dialog"); setBounds(100,100,300,300); setVisible(true); } public void actionPerformed(ActionEvent ae) { if(ae.getActionCommand().equals("Exit")) dlgConfirm.show(); if(ae.getActionCommand().equals("Y")) System.exit(0); if(ae.getActionCommand().equals("N")) dlgConfirm.setVisible(false); } public static void main(String[] args) { Dialog td=new Dialog(); } } class WinCloser extends WindowAdapter { public void WindowClosing(WindowEvent e) { System.exit(0); } }
|