newjdialog.java

来自「实习时做的人事系统」· Java 代码 · 共 159 行

JAVA
159
字号
package com.personnel;import java.awt.BorderLayout;import java.awt.FlowLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JTextField;import javax.swing.SwingUtilities;import org.jdesktop.application.Application;public class NewJDialog extends javax.swing.JDialog {	private static final long serialVersionUID = 1L;	private JTextField[] text = null;	private JButton yesButton;	private JButton cancelButton;	private JPanel buttonPane;	private JPanel contentPanel;	private int result = 0;	private JPanel root;	int column = 0;	/**	 * Auto-generated main method to display this JDialog	 */	public static void main(String[] args) {		SwingUtilities.invokeLater(new Runnable() {			public void run() {				JFrame frame = new JFrame();				NewJDialog inst = new NewJDialog(frame);				inst.setVisible(true);			}		});	}	public NewJDialog(JFrame frame) {		super(frame);		this.initGUI();		setLocation(frame.getX(), frame.getY());	}	public NewJDialog(JFrame frame, boolean mode, String[] columnNames) {		super(frame, mode);		setLocation(frame.getX(), frame.getY());		this.initGUI();		String[] columnN = columnNames;		for (int i = 0; i < columnNames.length; i++) {			if (columnNames[i].equals("ID")) {				columnN = this.resizeColumn(columnNames, i);			}		}		this.column = columnN.length;		this.text = new JTextField[this.column];		for (int i = this.column; i > 0; i--) {			JLabel label = new JLabel(columnN[i - 1]);			this.contentPanel.add(label);			this.text[i - 1] = new JTextField(30);			this.contentPanel.add(this.text[i - 1]);		}		this.validate();	}	public String[] resizeColumn(String[] columnName, int index) {		int size = columnName.length - 1;		String[] n = new String[size];		for (int i = 0; i < columnName.length; i++) {			if (i != index) {				n[size - 1] = columnName[i];				size--;			}		}		return n;	}	public int getResult() {		return this.result;	}	public String[] getTextFields() {		String[] val = new String[this.column];		for (int i = this.column; i > 0; i--) {			val[i - 1] = this.text[i - 1].getText().trim();		}		return val;	}	private void initGUI() {		try {			{				this.addWindowListener(new WindowAdapter() {					@Override					public void windowClosing(WindowEvent evt) {						NewJDialog.this.result = 1;					}				});			}			this.contentPanel = new JPanel();			FlowLayout contentPaneLayout = new FlowLayout();			contentPaneLayout.setHgap(1);			contentPaneLayout.setVgap(1);			contentPaneLayout.setAlignment(FlowLayout.LEFT);			this.contentPanel.setLayout(contentPaneLayout);			{				this.root = new JPanel();				BorderLayout rootLayout = new BorderLayout();				this.root.setLayout(rootLayout);				this.getContentPane().add(this.root, BorderLayout.CENTER);				this.root.setPreferredSize(new java.awt.Dimension(220, 688));				{					this.buttonPane = new JPanel();					this.root.add(this.buttonPane, BorderLayout.SOUTH);					{						this.yesButton = new JButton();						this.buttonPane.add(this.yesButton);						this.yesButton.setName("yesButton");						this.yesButton.addActionListener(new ActionListener() {							public void actionPerformed(ActionEvent evt) {								NewJDialog.this.result = 0;								NewJDialog.this.setVisible(false);							}						});					}					{						this.cancelButton = new JButton();						this.buttonPane.add(this.cancelButton);						this.cancelButton.setName("cancelButton");						this.cancelButton								.addActionListener(new ActionListener() {									public void actionPerformed(ActionEvent evt) {										NewJDialog.this.result = 1;										NewJDialog.this.setVisible(false);									}								});					}				}				{					this.root.add(this.contentPanel, BorderLayout.CENTER);				}			}			this.setSize(206, 750);			Application.getInstance().getContext().getResourceMap(					this.getClass()).injectComponents(this.getContentPane());		} catch (Exception e) {			e.printStackTrace();		}	}}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?