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

📄 shelllogin.java

📁 JAVA编写的单击的PIZZA店销售系统
💻 JAVA
字号:
package GUI;

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.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import com.swtdesigner.SWTResourceManager;
import java.sql.*;
import org.eclipse.jface.dialogs.*;

public class ShellLogin extends Shell {

	private Text password;
	private Text username;
	Display display = Display.getDefault();
	/**
	 * Create the shell
	 * @param display
	 * @param style
	 */
	public ShellLogin(Display display, int style) {
		super(display, style);
		createContents();
	}
	/**
	 * Create contents of the window
	 */
	protected void createContents() {
		
		
		this.setSize(500, 375);
		this.setText("登录");
		
		
		final Label label = new Label(this, SWT.NONE);
		label.setFont(SWTResourceManager.getFont("", 24, SWT.BOLD));
		label.setText("请先登录系统");
		label.setBounds(154, 53, 221, 42);

		final Label label_1 = new Label(this, SWT.NONE);
		label_1.setFont(SWTResourceManager.getFont("", 14, SWT.BOLD));
		label_1.setText("用户名");
		label_1.setBounds(95, 122, 61, 25);

		final Label label_2 = new Label(this, SWT.NONE);
		label_2.setFont(SWTResourceManager.getFont("", 14, SWT.BOLD));
		label_2.setText("密码");
		label_2.setBounds(94, 197, 62, 25);

		username = new Text(this, SWT.BORDER);
		username.setBounds(178, 118, 150, 32);

		password = new Text(this, SWT.BORDER | SWT.PASSWORD);
		password.setBounds(178, 193, 150, 32);

		final Button button = new Button(this, SWT.NONE);
		button.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				idCheck(username.getText(), password.getText());
			}
		});
		button.setText("确定");
		button.setBounds(139, 285, 61, 22);

		final Button button_1 = new Button(this, SWT.NONE);
		button_1.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				System.exit(0);
			}
		});
		button_1.setText("取消");
		button_1.setBounds(258, 285, 61, 22);
		//
	}
	
	private void idCheck(String user, String password){
		try 
		{ 
			Class.forName("org.gjt.mm.mysql.Driver"); 
			Connection con=DriverManager.getConnection("jdbc:mysql://localhost/Pizza?user=root&password=198652");
			String sql = "SELECT password FROM user where name = ?";
			PreparedStatement pstate = con.prepareStatement(sql);
			pstate.setString(1,user);
			ResultSet resultSet = pstate.executeQuery();
			while (resultSet.next()) {
        		String pass = resultSet.getString("password");
        		if (pass.equals(password)){
        			this.close();
    				PizzaStore ps = new PizzaStore(display, SWT.SHELL_TRIM);
    		    	ps.open();
    		    //	con.close();
    		    	ps.layout();	 
    		    	while (!ps.isDisposed()) {
    					if (!display.readAndDispatch())
    						display.sleep();
    		    	}
        		}
			}
			MessageDialog.openError(this, "警告","用户名或者密码错误,请重新输入");
		}	
		catch(SQLException e){ 
			System.out.println("Error! Error Code:#1. Can't make connection to Mysql Server. "+e.getMessage()); 
		} 
		 
		catch (java.lang.ClassNotFoundException e){ 
			System.out.println("Error! Error Code #2. Can't Load jdbc Driver. "+e.getMessage()); 
		} 
		
		
	/*	//temp check function. not connect with the db
		if(user.equals("杨洋")){
			if(password.equals("1")){
				this.close();
				PizzaStore ps = new PizzaStore(display, SWT.SHELL_TRIM);
		    	ps.open();
		    	ps.layout();	    	
		    	while (!ps.isDisposed()) {
					if (!display.readAndDispatch())
						display.sleep();
				}
				
			}
			else{	
				MessageDialog.openError(this, "警告","用户名或者密码错误,请重新输入");
			}
				
		}
		else if(user.equals("陆欣")){
			if(password.equals("1")){
				this.close();
				
			}
			else{	
				MessageDialog.openError(this, "警告","用户名或者密码错误,请重新输入");
			}				
		}
		else{
			MessageDialog.openError(this, "警告","用户名或者密码错误,请重新输入");
		}*/
			
	}

	


	protected void checkSubclass() {
		// Disable the check that prevents subclassing of SWT components
	}

}

⌨️ 快捷键说明

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