📄 demodialogframe.java
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package swing;import java.awt.Dimension;import java.awt.Toolkit;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.JDialog;import javax.swing.JFrame;import javax.swing.JLabel;/** * * @author zhaolin */public class DemoDialogFrame extends JDialog{ public DemoDialogFrame(){ this(null); } public DemoDialogFrame(JFrame owner){ super(owner); this.setModal(true); JLabel label = new JLabel("in Dialog"); this.getContentPane().add(label); JButton button = new JButton("exit"); button.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { setVisible(false); } }); this.getContentPane().add(button,"South"); } public static void main(String[] args) { final JFrame f = new JFrame(); final DemoDialogFrame dialog = new DemoDialogFrame(f); dialog.setSize(400,360); JButton button = new JButton("打开对话框"); button.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { int frameX = f.getX(); int frameY = f.getY(); int frameWidth = f.getWidth(); int frameHeight = f.getHeight(); int x = (frameWidth-dialog.getWidth())/2+frameX; int y = (frameHeight-dialog.getHeight())/2+frameY; dialog.setLocation(x,y); dialog.setVisible(true); } }); f.getContentPane().add(button); f.setSize(500,480); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); int x = (int)(screenSize.getWidth()-f.getWidth())/2; int y = (int)(screenSize.getHeight()-f.getHeight())/2; f.setLocation(x,y); f.setVisible(true); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -