⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mydialog.java

📁 jfreechart 柱状图 均值图 和值图 实例
💻 JAVA
字号:
package com.text2;

import java.awt.Container;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

import com.query.Employee;
import com.query.QueryData;

public class MyDialog extends JDialog implements Action, MouseListener {
	JTextField employeeid;

	JTextField employeename;

	public MyDialog() {
		super();
		initContrl();
		localCenter();
	}

	public MyDialog(Frame owner) {
		super(owner, "新增人员", true);
		initContrl();
		localCenter();
	}

	private void initContrl() {
		Container cp = this.getContentPane();
		cp.setPreferredSize(new Dimension(300, 200));
		GridBagLayout g = new GridBagLayout();
		cp.setLayout(g);
		Insets insets = new Insets(2, 2, 2, 2);
		Dimension controlsize = new Dimension(70, 27);
		JLabel lb = new JLabel("人员ID:");
		int y = 0;
		cp
				.add(lb, new GridBagConstraints(0, y, 1, 1, 1, 1,
						GridBagConstraints.WEST, GridBagConstraints.NONE,
						insets, 2, 2));
		employeeid = new JTextField();
		employeeid.setPreferredSize(controlsize);
		cp
				.add(employeeid, new GridBagConstraints(1, y, 1, 1, 1, 1,
						GridBagConstraints.WEST, GridBagConstraints.NONE,
						insets, 2, 2));
		y++;
		lb = new JLabel("人员名称:");
		cp
				.add(lb, new GridBagConstraints(0, y, 1, 1, 1, 1,
						GridBagConstraints.WEST, GridBagConstraints.NONE,
						insets, 2, 2));
		employeename = new JTextField();
		employeename.setPreferredSize(controlsize);
		cp
				.add(employeename, new GridBagConstraints(1, y, 1, 1, 1, 1,
						GridBagConstraints.WEST, GridBagConstraints.NONE,
						insets, 2, 2));
		JPanel bottompane = createSavecancelPane();
		y++;
		cp.add(bottompane, new GridBagConstraints(0, y, 2, 1, 1, 1,
				GridBagConstraints.CENTER, GridBagConstraints.NONE, insets, 2,
				2));
	}

	protected JPanel createSavecancelPane() {
		JPanel jpanel = new JPanel();
		JButton jbutton = new JButton("保存");
		//addEnterkeyConfirm(jbutton);
		jbutton.addActionListener(this);
		jbutton.setActionCommand("save");
		jpanel.add(jbutton);
		jbutton = new JButton("取消");
		//addEnterkeyTraver(jbutton);
		jbutton.addActionListener(this);
		jbutton.setActionCommand("cancel");
		jpanel.add(jbutton);
		return jpanel;
	}

	public void localCenter() {
		Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
		Dimension dimension1 = getPreferredSize();
		double d = (dimension.getWidth() - dimension1.getWidth()) / 2D;
		double d1 = (dimension.getHeight() - dimension1.getHeight()) / 2D;
		setLocation((int) d, (int) d1);
	}

	public void actionPerformed(ActionEvent actionevent) {
		if ("save".equals(actionevent.getActionCommand())
				|| "\n".equals(actionevent.getActionCommand())) {
			onSave();
			return;
		}
		if ("cancel".equals(actionevent.getActionCommand()))
			onCancel();
	}
	//保存
	protected void onSave() {
		//人员ID不能为空
		if(employeeid.getText()==null||employeeid.getText().equals("")){
			infoMessage("提示", "人员ID不能为空");
			return ;
		}
		//人员名称不能为空
		if(employeename.getText()==null||employeename.getText().equals("")){
			infoMessage("提示", "人员名称不能为空");
			return ;
		}
		//进行保存
		QueryData qd=new QueryData();
		Employee emp=new Employee();
		emp.setEmployeeid(employeeid.getText());
		emp.setEmployeename(employeename.getText());
		qd.dosave(emp);
		dispose();
	}

	protected void doClose() {
		onCancel();
	}

	protected void onCancel() {
		dispose();
	}

	public Object getValue(String key) {

		return null;
	}

	public void putValue(String key, Object value) {

	}

	public void mouseClicked(MouseEvent e) {

	}

	public void mouseEntered(MouseEvent e) {

	}

	public void mouseExited(MouseEvent e) {

	}

	public void mousePressed(MouseEvent e) {

	}

	public void mouseReleased(MouseEvent e) {

	}
	 protected void infoMessage(String s, String s1) {
		JOptionPane.showMessageDialog(this, s1, s, 1);
	}

	public static void main(String[] args) {
		/*MyDialog dialog = new MyDialog();
		 dialog.pack();
		 dialog.setVisible(true);*/
		MyDialog dialog = new MyDialog(null);
		dialog.pack();
		dialog.setVisible(true);
	}
}

⌨️ 快捷键说明

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