📄 login.java
字号:
/* * Copyright 2004 Grzegorz Grasza groz@gryf.info * * This file is part of mobber. Mobber is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by the Free * Software Foundation; either version 2 of the License, or (at your option) any later version. * Mobber is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * You should have received a copy of the GNU General Public License along with mobber; * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307 USA . */import javax.microedition.lcdui.*;import java.io.*;import javax.microedition.rms.*;public class Login extends Form implements CommandListener{ TextField jid, passwd; ChoiceGroup sync = new ChoiceGroup(null, Choice.MULTIPLE); String server = "gryf.info", port = "5222", username = "", password = "", resource = "mobile"; int show = 0, priority = 6; String status = ""; Login() { super(Label.login); RecordStore store = null; try { store = RecordStore.openRecordStore("account", true); if(store.getNumRecords() == 1) { byte[] data=store.getRecord(1); DataInputStream str=new DataInputStream(new ByteArrayInputStream(data)); server=str.readUTF(); username=str.readUTF(); password=str.readUTF(); resource=str.readUTF(); } } catch(Exception e) { //e.printStackTrace(); } if(store!=null) { try { store.closeRecordStore(); } catch(Exception e) { //e.printStackTrace(); } } jid = new TextField("JID", username + '@' + server + '/' + resource, 64, TextField.EMAILADDR); passwd = new TextField(Label.password, password, 32, TextField.PASSWORD); try { append(new ImageItem(null, Image.createImage("/mobber.png"), ImageItem.LAYOUT_CENTER | ImageItem.LAYOUT_NEWLINE_BEFORE | ImageItem.LAYOUT_NEWLINE_AFTER, "mobber")); } catch(Exception e) { //e.printStackTrace(); } append(jid); append(passwd); sync.append(Label.sync, null); sync.setSelectedIndex(0, true); append(sync); addCommand(Action.login); addCommand(Action.exit); setCommandListener(this); setTicker(new Ticker(" m o bber Copyright (c) Grzegorz Grasza")); } public void commandAction(Command c, Displayable s) { if(c == Action.login) { String tmp = jid.getString(); int x, y; username = tmp.substring(0, x=tmp.indexOf('@')); if((y=tmp.indexOf('/')) != -1) { server = tmp.substring(++x, y); resource = tmp.substring(++y); } else server = tmp.substring(x); password = passwd.getString(); RecordStore store = null; try { store = RecordStore.openRecordStore("account",true); if(store.getNumRecords()>0) { store.closeRecordStore(); RecordStore.deleteRecordStore("account"); store = RecordStore.openRecordStore("account",true); } ByteArrayOutputStream bstr = new ByteArrayOutputStream(); DataOutputStream str = new DataOutputStream(bstr); str.writeUTF(server); str.writeUTF(username); str.writeUTF(password); str.writeUTF(resource); byte data[] = bstr.toByteArray(); store.addRecord(data,0,data.length); } catch(Exception e) { //e.printStackTrace(); } if(store != null) { try { store.closeRecordStore(); } catch(Exception e) { //e.printStackTrace(); } } if(sync.isSelected(0)) mobber.roster.restore(); mobber.jabber = new Jabber(server, port, username, password, resource); mobber.display.setCurrent(mobber.roster); } else // exit mobber.kill(); }};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -