Java

本类阅读TOP10

·使用MyEclipse开发Struts框架的Hello World!(录像1)
·hibernate配置笔记
·AOP编程入门--Java篇
·linux下Tomcat 5.0.20 与 Apache 2 安装/集成/配置
·在win2003下整合了整合Tomcat5.5+ apache_2.0.53+ mod_jk_2.0.47.dll
·构建Linux下IDE环境--Eclipse篇
·Jsp 连接 mySQL、Oracle 数据库备忘(Windows平台)
·ASP、JSP、PHP 三种技术比较
·Tomcat5.5.9的安装配置
·AWT GUI 设计笔记(二)

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
看看对话框

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

 

import java.awt.*;

import java.awt.event.*;

 

public class DialogWindow extends Frame implements ActionListener {

    boolean inAnApplet = true; //should be private

    private SimpleDialog dialog;

    private TextArea textArea;

    String newline;

 

    public DialogWindow() {

        textArea = new TextArea(5, 40);

        textArea.setEditable(false);

        add("Center", textArea);

        Button button = new Button("Click to bring up dialog");

        button.addActionListener(this);

       Panel panel = new Panel();

        panel.add(button);

        add("South", panel);

 

        addWindowListener(new WindowAdapter() {

           public void windowClosing(WindowEvent e) {

               if (inAnApplet) {

                   setVisible(false);

                   dispose();

               } else {

                   System.exit(0);

               }

           }

       });

 

        newline = System.getProperty("line.separator");

    }

 

    public void actionPerformed(ActionEvent event) {

       if (dialog == null) {

           dialog = new SimpleDialog(this, "A Simple Dialog");

       }

        dialog.setVisible(true);

    }

 

    public void setText(String text) {

        textArea.append(text + newline);

    }

 

    public static void main(String args[]) {

        DialogWindow window = new DialogWindow();

        window.inAnApplet = false;

 

        window.setTitle("DialogWindow Application");

        window.pack();

        window.setVisible(true);

    }

}

 

class SimpleDialog extends Dialog implements ActionListener {

    TextField field;

    DialogWindow parent;

    Button setButton;

 

    SimpleDialog(Frame dw, String title) {

       super(dw, title, false);

        parent = (DialogWindow) dw;

 

        //Create middle section.

       Panel p1 = new Panel();

       Label label = new Label("Enter random text here:");

        p1.add(label);

       field = new TextField(40);

        field.addActionListener(this);

        p1.add(field);

        add("Center", p1);

 

        //Create bottom row.

       Panel p2 = new Panel();

        p2.setLayout(new FlowLayout(FlowLayout.RIGHT));

        Button b = new Button("Cancel");

        b.addActionListener(this);

        setButton = new Button("Set");

        setButton.addActionListener(this);

        p2.add(b);

        p2.add(setButton);

        add("South", p2);

 

        //Initialize this dialog to its preferred size.

        pack();

    }

 

    public void actionPerformed(ActionEvent event) {

        Object source = event.getSource();

       if ((source == setButton) | (source == field)) {

           parent.setText(field.getText());

       }

        field.selectAll();

        setVisible(false);

    }

}




相关文章

相关软件