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

📄 addpeople.java

📁 这是我做的一个收发邮件的软件
💻 JAVA
字号:
package source;

import java.awt.Dimension;
import java.awt.Toolkit;

import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import com.swtdesigner.SWTResourceManager;

public class AddPeople {

	private Combo combo;
	private Text text_7;
	private Text text_6;
	private Text text_4;
	protected Shell shell;
	private Display display;

	/**
	 * Launch the application
	 * @param args
	 */
	public AddPeople(Shell parent,Display display) {
		this.shell=shell;
		this.display=display;
		try {
			open();
		} catch (Exception e) {
			
		}
	}

	/**
	 * Open the window
	 */
	public void open() {
		createContents();
		shell.open();
		shell.layout();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
	}

	/**
	 * Create contents of the window
	 */
	protected void createContents() {
		shell = new Shell();
		shell.setSize(407, 300);
		shell.setText("添加联系人信息");
		int width,height;
        width=407;
        height=300;
        shell.setSize(width, height);
        shell.setCapture(true);
        shell.setLayout(null);
        Toolkit kit=Toolkit.getDefaultToolkit();
        Dimension screenSize=kit.getScreenSize();
        shell.setBounds((screenSize.width-width)/2, (screenSize.height-height)/2, width,height);

		final Button button = new Button(shell, SWT.NONE);
		button.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent arg0) {
			}
		});


		text_4 = new Text(shell, SWT.BORDER);
		text_4.setBounds(151, 32, 165, 20);

		text_6 = new Text(shell, SWT.BORDER);
		text_6.setBounds(151, 128, 165, 20);

		text_7 = new Text(shell, SWT.BORDER);
		text_7.setBounds(151, 179, 165, 20);

		combo = new Combo(shell, SWT.READ_ONLY);
		combo.setBounds(151, 77, 49, 20);
		
		combo.add("男");
		combo.add("女");
		combo.select(0);

		final Label label = new Label(shell, SWT.NONE);
		label.setFont(SWTResourceManager.getFont("楷体_GB2312", 12, SWT.BOLD));
		label.setText("  姓 名");
		label.setBounds(21, 31, 71, 25);

		final Label label_1 = new Label(shell, SWT.NONE);
		label_1.setFont(SWTResourceManager.getFont("楷体_GB2312", 12, SWT.BOLD));
		label_1.setText("性 别");
		label_1.setBounds(36, 76, 71, 21);

		final Label label_2 = new Label(shell, SWT.NONE);
		label_2.setFont(SWTResourceManager.getFont("楷体_GB2312", 12, SWT.BOLD));
		label_2.setText("Email地址");
		label_2.setBounds(36, 127, 80, 25);

		final Label label_3 = new Label(shell, SWT.NONE);
		label_3.setFont(SWTResourceManager.getFont("楷体_GB2312", 12, SWT.BOLD));
		label_3.setText("电话号码");
		label_3.setBounds(35, 178, 81, 26);
		button.setText("确定");
        button.addSelectionListener(new SelectionAdapter() {
        	public void widgetSelected(SelectionEvent arg2) {
        	    if(text_4.getText().trim()==""||text_4.getText().trim()==""||text_6.getText().trim()==""||text_7.getText().trim()=="")
        	    {
        	    	MessageDialog.openInformation(null, null, "请将信息添加完整!");
        	    }
        	    else
        	    {
        	    	String name;
        	    	boolean sex;
        	    	String phone;
        	    	String email;
        	    	name=text_4.getText().trim();
        	    	phone=text_7.getText().trim();
        	    	email=text_6.getText().trim();
        	    	if(combo.getSelectionIndex()==0)
        	    	{
        	    		sex=true;
        	    	}
        	    	else
        	    	{
        	    		sex=false;
        	    	}
        	    	DataBase db=new DataBase();
        	    	db.connectToDB();
        	    	String sql="";
        	    	sql="insert into people(name,phone,email,sex) values('"+name+"','"+phone+"','"+email+"',"+sex+")";
        	    	db.executeInsert(sql);
        	    	db.close();
        	    	MessageDialog.openInformation(null, null, "添加信息成功!");
        	    	shell.close();        	    	
        	    }
        	}
        });
		button.setBounds(150, 225, 80, 25);

	}

}

⌨️ 快捷键说明

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