首 页文章中心下载中心繁體中文
设为首页
加入收藏
联系我们
您当前的位置:开源盛世-源代码下载网 -> 文章中心 -> 其他编程 -> Java技术 -> 文章内容 退出登录 用户管理
栏目导航
· VC# 技术 · Delphi技术
· Java技术 · 通用算法
· 编程相关
热门文章
· Tab Control控件使用...
· 学生档案管理系统
· [图文] 排列组合公式
· UTF-8与GB2312之间的...
· DirectShow下载安装...
· Virtual PC 在PAE模...
· Windows2000终端服务...
· MapInfo上的GIS系统...
· Mapbasic参考手册索...
· MapX应用开发中文讲...
相关文章
看看对话框
作者:佚名  来源:vscodes.com整理  发布时间:2005-12-16 13:00:11  发布人:Polaris

减小字体 增大字体

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);

}

}


End of《看看对话框》

[] [返回上一页] [打 印] [收 藏]
上一篇文章:读写远程文件并显示
下一篇文章:限制访问页面
 
∷相关“看看对话框”文章评论∷
(评论内容只代表网友观点,与本站立场无关!) [更多评论...]
关于本站 - 网站帮助 - 广告合作 - 下载声明 - 友情连接 - 网站地图 网站目录 鄂ICP备06007162
开源盛世 版权所有Copyright © 2003-2005 VSCodes.Com. All Rights Reserved.