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

📄 addagentdialog.java

📁 一套基于JAVA开发的完整版航空订票系统,代码简洁,适合JAVA初学者研究
💻 JAVA
字号:
package com.tarena.abs.server;

import javax.swing.*;
import com.tarena.abs.dao.*;
import com.tarena.abs.model.*;
import java.awt.*;
import java.awt.event.*;

/**
 * 添加代理商对话框。
 * @author tangliang
 *
 */
public class AddAgentDialog extends JDialog implements ActionListener{
	private static final long serialVersionUID = 1239004139549714749L;
	JLabel label0,label1,label2;
	JButton ok,cancel;
	JTextField name,email;
	public AddAgentDialog(JFrame frame){
		super(frame,"添加代理商");
		label0=new JLabel("请输入代理商信息:");
		label1=new JLabel("        用户名:");
		label2=new JLabel("        E_mail:");
		ok=new JButton("添加");
		cancel=new JButton("取消");
		name=new JTextField(15);
		email=new JTextField(15);
		init();
		eventHandle();
	}
	private void init(){
		JPanel p1=new JPanel();
		p1.add(label0);
		this.add(p1,BorderLayout.NORTH);
		JPanel p2=new JPanel();
		p2.setLayout(new GridLayout(2,2,10,20));
		p2.add(label1);
		p2.add(name);
		p2.add(label2);
		p2.add(email);
		this.add(p2,BorderLayout.CENTER);
		JPanel p3=new JPanel();
		p3.add(ok);
		p3.add(cancel);
		this.add(p3,BorderLayout.SOUTH);
	}
	private void eventHandle(){
		ok.addActionListener(this);
		cancel.addActionListener(this);
	}
	public void showMe(){
		this.setSize(300,200);
		this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
		this.setVisible(true);
	}
	public void actionPerformed(ActionEvent e) {
		String comm=e.getActionCommand();
		if(comm.equals("添加")){
			if(name.getText().equals("")||email.getText().equals("")){
				JOptionPane.showMessageDialog(this,"姓名或email不能为空!");
				return;
			}
			AgentDAO dao=ServerMainClass.agentDao;
			boolean success=dao.addAgent(new Agent(name.getText(),"8888",email.getText()));
			if(success){	
				JOptionPane.showMessageDialog(this,"祝贺,代理商添加成功!");
				this.dispose();
			}else{
				JOptionPane.showMessageDialog(this,"代理商添加不成功,可能已存在同名的代理商!");
				name.setText("");
				email.setText("");
			}
		}else if(comm.equals("取消")){
			this.dispose();
		}
	}
}

⌨️ 快捷键说明

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