📄 newdialog.java
字号:
package wbmp;import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.text.*;import java.util.*;/** * The new dialog used to set option in the WBMP Editor. * Copyright (c) 2003 * @author Mark Busman * @version 1.0 * * For License and contact information see WBMPEditor.java */public class NewDialog extends JDialog { JPanel Mainpanel = new JPanel(); JPanel jPanel1 = new JPanel(); FlowLayout flowLayout1 = new FlowLayout(); JButton CancelButton = new JButton(); JButton OKButton = new JButton(); JLabel jLabel1 = new JLabel(); JTextField Widthtext = new JTextField(); JLabel jLabel2 = new JLabel(); JTextField Heighttext = new JTextField(); GridLayout gridLayout1 = new GridLayout(); private int width, height; private boolean OKPressed = false; /** Constructor - constructs a new NewDialog object. */ public NewDialog() { try { jbInit(); this.setSize(275, 134); } catch(Exception e) { e.printStackTrace(); } } /** Initializes form components. */ private void jbInit() throws Exception { jPanel1.setLayout(flowLayout1); flowLayout1.setAlignment(FlowLayout.RIGHT); CancelButton.setText("Cancel"); CancelButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { CancelButton_actionPerformed(e); } }); OKButton.setMaximumSize(new Dimension(81, 23)); OKButton.setMinimumSize(new Dimension(81, 23)); OKButton.setPreferredSize(new Dimension(81, 23)); OKButton.setText("Ok"); OKButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { OKButton_actionPerformed(e); } }); jLabel1.setText("Width"); jLabel2.setText("Height"); Mainpanel.setLayout(gridLayout1); Mainpanel.setPreferredSize(new Dimension(275, 64)); gridLayout1.setRows(2); gridLayout1.setColumns(2); this.setResizable(false); this.setModal(true); this.setTitle("Create a new image"); this.getContentPane().add(Mainpanel, BorderLayout.CENTER); Mainpanel.add(jLabel1, null); Mainpanel.add(Widthtext, null); Mainpanel.add(jLabel2, null); Mainpanel.add(Heighttext, null); this.getContentPane().add(jPanel1, BorderLayout.SOUTH); jPanel1.add(OKButton, null); jPanel1.add(CancelButton, null); } /** OKButton listener - if pressed performs assignment and clean up duties. Assigns OKPressed a value of true. @param ActionEvent e */ private void OKButton_actionPerformed(ActionEvent e) { try { width = Integer.parseInt(Widthtext.getText()); height = Integer.parseInt(Heighttext.getText()); if ((width > 0) && (height > 0)) { OKPressed = true; this.setVisible(false); } else { JOptionPane opt = new JOptionPane(); opt.showMessageDialog(this, new String("Width and or Height must be greater than 0"), new String("Warning"), JOptionPane.WARNING_MESSAGE); } } catch (NumberFormatException NumExecption) { JOptionPane opt = new JOptionPane(); opt.showMessageDialog(this, new String("Width or Height must have a value specified"), new String("Warning"), JOptionPane.WARNING_MESSAGE); } } /** CancelButton Listener. Performs clean up and assigns OKpressed a value of false. @param ActionEvent e */ private void CancelButton_actionPerformed(ActionEvent e) { this.setVisible(false); OKPressed = false; } /** Gets the width set by the user. @return int Width */ public int GetWidth() { return width; } /** Gets the height set by the user. @return int Height */ public int GetHeight() { return height; } /** Gets the status set by pressing the OKButton or the CancelButton. @return boolean OkPressed */ public boolean GetButtonPressed() { return OKPressed; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -