demodialogframe.java
来自「java绘图 java awt 经典绘图的例子,对于初学awt模块的人非常有帮助」· Java 代码 · 共 73 行
JAVA
73 行
/* * 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 + =
减小字号Ctrl + -
显示快捷键?