Swing学习(二)——Dialog
package com.xyzx.swing; import java.awt.Container; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JLabel; /** * @description 配置对话框 */ public class DialogDemo extends JDialog{ // 序列化 private static final long serialVersionUID = 5646954994264690723L; public DialogDemo(JFrame frame){ // public JDialog(Frame owner, String title, boolean modal) super(frame,"配置",true); Container container = getContentPane();//容器 container.add(new JLabel("这是一个对话框")); setBounds(100,100,200,200); } }
在notePad中调用Dialog。
package com.xyzx.swing; import javax.swing.JFrame; /** * @description 我的记事本主程序 */ public class NotePad { /** * 构造函数 */ public NotePad(){ // 1、 初始化窗体 JFrame notePadFrame = new JFrame("我的记事本"); // 设置边框 notePadFrame.setBounds(200, 200, 300, 500); notePadFrame.setVisible(true); DialogDemo dialogDemo = new DialogDemo(notePadFrame); dialogDemo.setVisible(true); } public static void main(String[] args) { new NotePad(); } }
效果:
下一篇:
java定义数组的三种类型总结