dialog类java_AWT Dialog类

介绍

对话框控件是一个用于采取某种形式的用户输入的标题和边框的顶层窗口。

类的声明

以下是声明为java.awt.Dialog类:

publicclassDialogextendsWindow

字段域

以下java.awt.image类的字段:

static Dialog.ModalityType DEFAULT_MODALITY_TYPE -- 默认模态对话框的模态类型.

类的构造函数

S.N.

构造函数&说明

1

Dialog(Dialog owner)

Constructs an initially invisible, modeless Dialog with the specified owner Dialog and an empty title.

2

Dialog(Dialog owner, String title)

Constructs an initially invisible, modeless Dialog with the specified owner Dialog and title.

3

Dialog(Dialog owner, String title, boolean modal)

Constructs an initially invisible Dialog with the specified owner Dialog, title, and modality.

4

Dialog(Dialog owner, String title, boolean modal, GraphicsConfiguration gc)

Constructs an initially invisible Dialog with the specified owner Dialog, title, modality and GraphicsConfiguration.

5

Dialog(Frame owner)

Constructs an initially invisible, modeless Dialog with the specified owner Frame and an empty title.

6

Dialog(Frame owner, boolean modal)

Constructs an initially invisible Dialog with the specified owner Frame and modality and an empty title.

7

Dialog(Frame owner, String title)

Constructs an initially invisible, modeless Dialog with the specified owner Frame and title.

8

Dialog(Frame owner, String title, boolean modal)

Constructs an initially invisible Dialog with the specified owner Frame, title and modality.

9

Dialog(Frame owner, String title, boolean modal, GraphicsConfiguration gc)

Constructs an initially invisible Dialog with the specified owner Frame, title, modality, and GraphicsConfiguration.

10

Dialog(Window owner)

Constructs an initially invisible, modeless Dialog with the specified owner Window and an empty title.

11

Dialog(Window owner, Dialog.ModalityType modalityType)

Constructs an initially invisible Dialog with the specified owner Window and modality and an empty title.

12

Dialog(Window owner, String title)

Constructs an initially invisible, modeless Dialog with the specified owner Window and title.

13

Dialog(Window owner, String title, Dialog.ModalityType modalityType)

Constructs an initially invisible Dialog with the specified owner Window, title and modality.

14

Dialog(Window owner, String title, Dialog.ModalityType modalityType, GraphicsConfiguration gc)

Constructs an initially invisible Dialog with the specified owner Window, title, modality and GraphicsConfiguration

类方法

S.N.

方法&说明

1

void addNotify()

Makes this Dialog displayable by connecting it to a native screen resource.

2

AccessibleContext getAccessibleContext()

Gets the AccessibleContext associated with this Dialog.

3

Dialog.ModalityType getModalityType()

Returns the modality type of this dialog.

4

String getTitle()

Gets the title of the dialog.

5

void hide()

Deprecated. As of JDK version 1.5, replaced by setVisible(boolean).

6

boolean isModal()

Indicates whether the dialog is modal.

7

boolean isResizable()

Indicates whether this dialog is resizable by the user.

8

boolean isUndecorated()

Indicates whether this dialog is undecorated.

9

protected String paramString()

Returns a string representing the state of this dialog.

10

void setModal(boolean modal)

Specifies whether this dialog should be modal.

11

void setModalityType(Dialog.ModalityType type)

Sets the modality type for this dialog.

12

void setResizable(boolean resizable)

Sets whether this dialog is resizable by the user.

13

void setTitle(String title)

Sets the title of the Dialog.

14

void setUndecorated(boolean undecorated)

Disables or enables decorations for this dialog.

15

void setVisible(boolean b)

Shows or hides this Dialog depending on the value of parameter b.

16

void show()

Deprecated. As of JDK version 1.5, replaced by setVisible(boolean).

17

void toBack()

If this Window is visible, sends this Window to the back and may cause it to lose focus or activation if it is the focused or active Window.

继承的方法

这个类继承的方法从以下类:

java.awt.Window

java.awt.Component

java.lang.Object

Choice 实例

选择使用任何编辑器创建以下java程序 D:/ > AWT > com > yiibai > gui >

AwtControlDemo

packagecom.yiibai.gui;importjava.awt.*;importjava.awt.event.*;publicclassAwtControlDemo{privateFramemainFrame;privateLabelheaderLabel;privateLabelstatusLabel;privatePanelcontrolPanel;publicAwtControlDemo(){prepareGUI();}publicstaticvoidmain(String[]args){AwtControlDemoawtControlDemo=newAwtControlDemo();awtControlDemo.showDialogDemo();}privatevoidprepareGUI(){mainFrame=newFrame("Java AWT Examples");mainFrame.setSize(400,400);mainFrame.setLayout(newGridLayout(3,1));mainFrame.addWindowListener(newWindowAdapter(){publicvoidwindowClosing(WindowEventwindowEvent){System.exit(0);}});headerLabel=newLabel();headerLabel.setAlignment(Label.CENTER);statusLabel=newLabel();statusLabel.setAlignment(Label.CENTER);statusLabel.setSize(350,100);controlPanel=newPanel();controlPanel.setLayout(newFlowLayout());mainFrame.add(headerLabel);mainFrame.add(controlPanel);mainFrame.add(statusLabel);mainFrame.setVisible(true);}privatevoidshowDialogDemo(){headerLabel.setText("Control in action: Dialog");ButtonshowAboutDialogButton=newButton("Show About Dialog");showAboutDialogButton.addActionListener(newActionListener(){@OverridepublicvoidactionPerformed(ActionEvente){AboutDialogaboutDialog=newAboutDialog(mainFrame);aboutDialog.setVisible(true);}});controlPanel.add(showAboutDialogButton);mainFrame.setVisible(true);}classAboutDialogextendsDialog{publicAboutDialog(Frameparent){super(parent,true);setBackground(Color.gray);setLayout(newBorderLayout());Panelpanel=newPanel();panel.add(newButton("Close"));add("South",panel);setSize(200,200);addWindowListener(newWindowAdapter(){publicvoidwindowClosing(WindowEventwindowEvent){dispose();}});}publicbooleanaction(Eventevt,Objectarg){if(arg.equals("Close")){dispose();returntrue;}returnfalse;}publicvoidpaint(Graphicsg){g.setColor(Color.white);g.drawString("TutorialsPoint.Com",25,70);g.drawString("Version 1.0",60,90);}}}

编译程序,使用命令提示符。到 D:/ > AWT然后键入以下命令。

D:AWT>javac comyiibaiguiAwtControlDemo.java

如果没有错误出现,这意味着编译成功。使用下面的命令来运行程序。

D:AWT>java com.yiibai.gui.AwtControlDemo

验证下面的输出

acdf0c6e1d317fe3f4a211b725e3084a.png

¥ 我要打赏

纠错/补充

收藏

加QQ群啦,易百教程官方技术学习群

注意:建议每个人选自己的技术方向加群,同一个QQ最多限加 3 个群。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值