📄 loginscreenexample.java
字号:
/* * The contents of this file are subject to the terms of the Common Development * and Distribution License (the License). You may not use this file except in * compliance with the License. * * You can obtain a copy of the License at http://www.netbeans.org/cddl.html * or http://www.netbeans.org/cddl.txt. * * When distributing Covered Code, include this CDDL Header Notice in each file * and include the License file at http://www.netbeans.org/cddl.txt. * If applicable, add the following below the CDDL Header, with the fields * enclosed by brackets [] replaced by your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. */package loginscreenexample;import java.io.IOException;import javax.microedition.io.Connector;import javax.microedition.io.HttpConnection;import javax.microedition.lcdui.Alert;import javax.microedition.lcdui.Command;import javax.microedition.lcdui.CommandListener;import javax.microedition.lcdui.Display;import javax.microedition.lcdui.Displayable;import javax.microedition.midlet.*;import org.netbeans.microedition.lcdui.LoginScreen;import org.netbeans.microedition.lcdui.SplashScreen;import org.netbeans.microedition.lcdui.WaitScreen;import org.netbeans.microedition.util.SimpleCancellableTask;/** * @author devil */public class LoginScreenExample extends MIDlet implements CommandListener { private boolean midletPaused = false; private boolean login = false; //<editor-fold defaultstate="collapsed" desc=" Generated Fields ">//GEN-BEGIN:|fields|0| private Command exitCommand; private SimpleCancellableTask task; private WaitScreen waitScreen; private SplashScreen splashScreen; private LoginScreen loginScreen; private Alert alertFailure; private Alert alertSuccess; //</editor-fold>//GEN-END:|fields|0| /** * The LoginScreenExample constructor. */ public LoginScreenExample() { } //<editor-fold defaultstate="collapsed" desc=" Generated Methods ">//GEN-BEGIN:|methods|0| //</editor-fold>//GEN-END:|methods|0| //<editor-fold defaultstate="collapsed" desc=" Generated Method: initialize ">//GEN-BEGIN:|0-initialize|0|0-preInitialize /** * Initilizes the application. * It is called only once when the MIDlet is started. The method is called before the <code>startMIDlet</code> method. */ private void initialize() {//GEN-END:|0-initialize|0|0-preInitialize // write pre-initialize user code here//GEN-LINE:|0-initialize|1|0-postInitialize // write post-initialize user code here }//GEN-BEGIN:|0-initialize|2| //</editor-fold>//GEN-END:|0-initialize|2| //<editor-fold defaultstate="collapsed" desc=" Generated Method: startMIDlet ">//GEN-BEGIN:|3-startMIDlet|0|3-preAction /** * Performs an action assigned to the Mobile Device - MIDlet Started point. */ public void startMIDlet() {//GEN-END:|3-startMIDlet|0|3-preAction // write pre-action user code here switchDisplayable(null, getSplashScreen());//GEN-LINE:|3-startMIDlet|1|3-postAction // write post-action user code here }//GEN-BEGIN:|3-startMIDlet|2| //</editor-fold>//GEN-END:|3-startMIDlet|2| //<editor-fold defaultstate="collapsed" desc=" Generated Method: resumeMIDlet ">//GEN-BEGIN:|4-resumeMIDlet|0|4-preAction /** * Performs an action assigned to the Mobile Device - MIDlet Resumed point. */ public void resumeMIDlet() {//GEN-END:|4-resumeMIDlet|0|4-preAction // write pre-action user code here//GEN-LINE:|4-resumeMIDlet|1|4-postAction // write post-action user code here }//GEN-BEGIN:|4-resumeMIDlet|2| //</editor-fold>//GEN-END:|4-resumeMIDlet|2| //<editor-fold defaultstate="collapsed" desc=" Generated Method: switchDisplayable ">//GEN-BEGIN:|5-switchDisplayable|0|5-preSwitch /** * Switches a current displayable in a display. The <code>display</code> instance is taken from <code>getDisplay</code> method. This method is used by all actions in the design for switching displayable. * @param alert the Alert which is temporarily set to the display; if <code>null</code>, then <code>nextDisplayable</code> is set immediately * @param nextDisplayable the Displayable to be set */ public void switchDisplayable(Alert alert, Displayable nextDisplayable) {//GEN-END:|5-switchDisplayable|0|5-preSwitch // write pre-switch user code here Display display = getDisplay();//GEN-BEGIN:|5-switchDisplayable|1|5-postSwitch if (alert == null) { display.setCurrent(nextDisplayable); } else { display.setCurrent(alert, nextDisplayable); }//GEN-END:|5-switchDisplayable|1|5-postSwitch // write post-switch user code here }//GEN-BEGIN:|5-switchDisplayable|2| //</editor-fold>//GEN-END:|5-switchDisplayable|2| //<editor-fold defaultstate="collapsed" desc=" Generated Getter: task ">//GEN-BEGIN:|18-getter|0|18-preInit /** * Returns an initiliazed instance of task component. * @return the initialized component instance */ public SimpleCancellableTask getTask() { if (task == null) {//GEN-END:|18-getter|0|18-preInit // write pre-init user code here task = new SimpleCancellableTask();//GEN-BEGIN:|18-getter|1|18-execute task.setExecutable(new org.netbeans.microedition.util.Executable() { public void execute() throws Exception {//GEN-END:|18-getter|1|18-execute login(); }//GEN-BEGIN:|18-getter|2|18-postInit });//GEN-END:|18-getter|2|18-postInit // write post-init user code here }//GEN-BEGIN:|18-getter|3| return task; } //</editor-fold>//GEN-END:|18-getter|3| //<editor-fold defaultstate="collapsed" desc=" Generated Method: commandAction for Displayables ">//GEN-BEGIN:|7-commandAction|0|7-preCommandAction /** * Called by a system to indicated that a command has been invoked on a particular displayable. * @param command the Command that was invoked * @param displayable the Displayable where the command was invoked */ public void commandAction(Command command, Displayable displayable) {//GEN-END:|7-commandAction|0|7-preCommandAction // write pre-action user code here if (displayable == loginScreen) {//GEN-BEGIN:|7-commandAction|1|31-preAction if (command == LoginScreen.LOGIN_COMMAND) {//GEN-END:|7-commandAction|1|31-preAction // write pre-action user code here switchDisplayable(null, getWaitScreen());//GEN-LINE:|7-commandAction|2|31-postAction // write post-action user code here } else if (command == exitCommand) {//GEN-LINE:|7-commandAction|3|34-preAction // write pre-action user code here exitMIDlet();//GEN-LINE:|7-commandAction|4|34-postAction // write post-action user code here }//GEN-BEGIN:|7-commandAction|5|27-preAction } else if (displayable == splashScreen) { if (command == SplashScreen.DISMISS_COMMAND) {//GEN-END:|7-commandAction|5|27-preAction // write pre-action user code here switchDisplayable(null, getLoginScreen());//GEN-LINE:|7-commandAction|6|27-postAction // write post-action user code here }//GEN-BEGIN:|7-commandAction|7|17-preAction } else if (displayable == waitScreen) { if (command == WaitScreen.FAILURE_COMMAND) {//GEN-END:|7-commandAction|7|17-preAction // write pre-action user code here switchDisplayable(getAlertFailure(), getLoginScreen());//GEN-LINE:|7-commandAction|8|17-postAction } else if (command == WaitScreen.SUCCESS_COMMAND) {//GEN-LINE:|7-commandAction|9|16-preAction // write pre-action user code here switchDisplayable(getAlertSuccess(), getLoginScreen());//GEN-LINE:|7-commandAction|10|16-postAction }//GEN-BEGIN:|7-commandAction|11|7-postCommandAction }//GEN-END:|7-commandAction|11|7-postCommandAction // write post-action user code here }//GEN-BEGIN:|7-commandAction|12| //</editor-fold>//GEN-END:|7-commandAction|12| //<editor-fold defaultstate="collapsed" desc=" Generated Getter: waitScreen ">//GEN-BEGIN:|13-getter|0|13-preInit /** * Returns an initiliazed instance of waitScreen component.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -