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

📄 loginpane.java

📁 基于Ajax的WebOS————PhoneShow案例
💻 JAVA
字号:
package com.cownew.phoneshow;

import nextapp.echo2.app.Button;
import nextapp.echo2.app.Extent;
import nextapp.echo2.app.Grid;
import nextapp.echo2.app.Label;
import nextapp.echo2.app.PasswordField;
import nextapp.echo2.app.Row;
import nextapp.echo2.app.SplitPane;
import nextapp.echo2.app.TextField;
import nextapp.echo2.app.WindowPane;
import nextapp.echo2.app.event.ActionEvent;
import nextapp.echo2.app.event.ActionListener;

import com.cownew.phoneshow.basedata.user.IUserDAO;
import com.cownew.phoneshow.basedata.user.UserInfo;
import com.cownew.phoneshow.framework.common.PISException;
import com.cownew.phoneshow.framework.common.Resources;
import com.cownew.phoneshow.framework.common.ServiceLocator;

class LoginPane extends WindowPane
{
	private static final Extent PX_300 = new Extent(300, Extent.PX);

	private TextField userIdField;

	private PasswordField pwdField;

	public LoginPane()
	{
		super();
		SplitPane splitPane = new SplitPane(
				SplitPane.ORIENTATION_VERTICAL_BOTTOM_TOP, new Extent(32));
		add(splitPane);

		Row controlRow = new Row();
		controlRow.setStyleName("ControlPane");
		splitPane.add(controlRow);

		Button btnLogin = new Button("登录", Resources.ICON_24_YES);
		btnLogin.setStyleName("ControlPane.Button");
		btnLogin.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e)
			{
				processLogin();
			}
		});
		controlRow.add(btnLogin);

		Button btnReg = new Button("注册", Resources.ICON_24_YES);
		btnReg.setStyleName("ControlPane.Button");
		btnReg.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e)
			{
				showRegPane();
			}
		});
		controlRow.add(btnReg);

		Grid layoutGrid = new Grid();
		layoutGrid.setStyleName("LoginScreen.LayoutGrid");
		splitPane.add(layoutGrid);

		Label labelUserId = new Label("用户名:");
		labelUserId.setStyleName("LoginScreen.Prompt");
		layoutGrid.add(labelUserId);

		userIdField = new TextField();
		userIdField.setWidth(PX_300);
		userIdField.setStyleName("Default");
		userIdField.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e)
			{
				processLogin();
			}
		});
		layoutGrid.add(userIdField);

		Label labelPwd = new Label("密码:");
		labelPwd.setStyleName("LoginScreen.Prompt");
		layoutGrid.add(labelPwd);

		pwdField = new PasswordField();
		pwdField.setWidth(PX_300);
		pwdField.setStyleName("Default");
		pwdField.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e)
			{
				processLogin();
			}
		});
		layoutGrid.add(pwdField);

		MainApp.getActive().setFocusedComponent(userIdField);
	}

	//处理登录
	private void processLogin()
	{
		String userId = userIdField.getText();
		String pwd = pwdField.getText();
		boolean isCorrect = false;
		try
		{
			//判断用户名、密码是否正确
			IUserDAO dao = (IUserDAO) ServiceLocator.getService(IUserDAO.class);
			isCorrect = (dao.isCorrect(userId, pwd));
		} catch (PISException e)
		{
			//因为IUserDAO可能会抛出PISException异常,所以要捕获此异常
			MainApp.showInfo(e.getMessage());
			return;
		}
		if (!isCorrect)
		{
			MainApp.showInfo("用户名或者密码错误!");
		} else
		{
			//如果验证正确则设定当前登录用户的Id,并显示主界面
			IUserDAO dao = (IUserDAO) ServiceLocator.getService(IUserDAO.class);
			UserInfo userInfo = dao.loadByUserId(userId);
			MainApp.setActiveUserId(userInfo.getUserId());
			MainApp.showScreen(new MainScreen());

		}

	}

	//显示注册界面
	private void showRegPane()
	{
		//创建注册界面
		RegisterPane registerPane = new RegisterPane();
		//设定界面大小
		registerPane.setWidth(new Extent(500));
		registerPane.setHeight(new Extent(200));
		//显示界面
		MainApp.addComponent(registerPane);
	}

}

⌨️ 快捷键说明

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