📄 modeldialogframe.java
字号:
package modeldialog;import java.awt.*;import java.awt.event.*;import javax.swing.*;/** * <p>Title: Model Dialog Demo</p> * <p>Description: This is a Model Dialog demo</p> * <p>Copyright: Copyright (c) 2002</p> * <p>Company: d6-125</p> * @author Liujun * @version 1.0 */public class ModelDialogFrame extends JFrame { JPanel contentPane; JButton jButton1 = new JButton(); JButton jButton2 = new JButton(); GridBagLayout gridBagLayout1 = new GridBagLayout(); //Construct the frame public ModelDialogFrame() { enableEvents(AWTEvent.WINDOW_EVENT_MASK); try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } //Component initialization private void jbInit() throws Exception { //setIconImage(Toolkit.getDefaultToolkit().createImage(ModelDialogFrame.class.getResource("[Your Icon]"))); contentPane = (JPanel) this.getContentPane(); jButton1.setText("以非模式方式调用"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jButton1_actionPerformed(e); } }); contentPane.setLayout(gridBagLayout1); this.setSize(new Dimension(400, 91)); this.setTitle("Model Dialog Frame Demo"); jButton2.setText("以模式方式调用"); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jButton2_actionPerformed(e); } }); contentPane.add(jButton1, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 269, 0)); contentPane.add(jButton2, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 281, -1)); } //Overridden so we can exit when window is closed protected void processWindowEvent(WindowEvent e) { super.processWindowEvent(e); if (e.getID() == WindowEvent.WINDOW_CLOSING) { System.exit(0); } } void jButton1_actionPerformed(ActionEvent e) { (new MyDialog(this,"非模态对话框",false)).show(); } void jButton2_actionPerformed(ActionEvent e) { (new MyDialog(this,"模态对话框",true)).show(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -