📄 twittering.java
字号:
/*
******************************************************************************
Main Twittering midlet GUI and handling
Copyright (C) 2007 Timothy Lim Sheng Hwee
This program 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.
This program 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 this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Author: Timothy Lim Sheng Hwee
Email : LimShengHwee@gmail.com
******************************************************************************
*/
package Twittering;
import java.util.Vector;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
/**
*
* @author Administrator
*/
public class Twittering extends MIDlet implements CommandListener, ItemCommandListener, ItemStateListener
{
/** Creates a new instance of Twittering */
public Twittering()
{
initialize();
}
private Form formMain;//GEN-BEGIN:MVDFields
private Form formSettings;
private Command goToSettings;
private Command goToTweets;
private Command goToDirectMsgs;
private Command exitApp;
private Command saveSettings;
private Command exitSettings;
private TextField settingsUser;
private TextField settingsPass;
private TextField whatAreYouDoing;
private StringItem sendTweetBtn;
private Spacer spacer1;
private TextField dmMsg;
private StringItem sendDirectMessageBtn;
private TextField dmUserText;
private StringItem lblDM;
private Command goToMainPage;
private Command sendTweet;
private Command sendDirectMsg;
private Command popupSelectUser;
private Command clearTweet;
private Command clearDirectMsgText;
private Form formSelectUser;
private Command refreshUserList;
private Command backToMain;
private Command selectFriend;
private Form formInitError;
private Command exit;
private Command clearSettings;
private StringItem intiError;
private Command sendTweetItem;
private Command sendDirectMessageItem;
private Command saveWhatAreYouDoing;
private Command saveUsername;
private Command saveDirectMessage;
private Command clearUserName;
private Command editWAYD;
private Command cmdDone;
private Command cmdBacktoMain;
private Command editDM;
private StringItem lblWAYD;
private Form form1;
private StringItem strLicense;
private Spacer spacer2;
private Command cmdAbout;//GEN-END:MVDFields
public final int MODE_WAYD = 0;
public final int MODE_DM = 1;
private int mode;
private Alert popup;
private Data data;
private DB_RS db;
private ClientCommandHandler currCommand;
public final String DB_STRING = "Twittering";
public final String DB_USER = "U";
public final String DB_PASS = "P";
public final String DB_FRIENDS = "F";
public final String DB_DM_USER = "DM_U";
public final String DB_DM_MSG = "DM_MSG";
public final String DB_TWEET_MSG = "TWT_MSG";
public final int MAX_MSG = 160;
public void itemStateChanged(Item item)
{
if (item == get_dmMsg())
{
updateCharsAvailable(true);
}
else if (item == get_whatAreYouDoing())
{
updateCharsAvailable(false);
}
}
//GEN-LINE:MVDMethods
private void updateCharsAvailable(boolean directMsg)
{
if (directMsg)
{
get_dmMsg().setLabel("Characters available: " + (MAX_MSG - get_dmMsg().getString().length()));
}
else
{
get_whatAreYouDoing().setLabel("Characters available: " + (MAX_MSG - get_whatAreYouDoing().getString().length()));
}
}
/** Called by the system to indicate that a command has been invoked on a particular item.//GEN-BEGIN:MVDICABegin
* @param command the Command that ws invoked
* @param item the Item on which the command was invoked
*/
public void commandAction(Command command, Item item)
{//GEN-END:MVDICABegin
// Insert global pre-action code here
if (item == sendDirectMessageBtn)//GEN-BEGIN:MVDICABody
{
if (command == sendDirectMsg)
{//GEN-END:MVDICABody
// Insert pre-action code here
sendDirectMessage();
// Do nothing//GEN-LINE:MVDICAAction37
// Insert post-action code here
}//GEN-BEGIN:MVDICACase37
}
else if (item == sendTweetBtn)
{
if (command == sendTweet)
{//GEN-END:MVDICACase37
// Insert pre-action code here
sendTweet();
// Do nothing//GEN-LINE:MVDICAAction35
// Insert post-action code here
}//GEN-BEGIN:MVDICACase35
}
else if (item == dmUserText)
{
if (command == popupSelectUser)
{//GEN-END:MVDICACase35
// Insert pre-action code here
getDisplay().setCurrent(get_formSelectUser());
// Do nothing//GEN-LINE:MVDICAAction41
// Insert post-action code here
}//GEN-BEGIN:MVDICACase41
else if (command == saveUsername)
{//GEN-END:MVDICACase41
try
{
db.open();
getData().setDirectMessageUser(get_dmUserText().getString());
if(getData().getDirectMessageUser() != null) db.write(DB_DM_USER, getData().getDirectMessageUser(), false);
db.close();
}
catch(Exception e)
{
getDisplay().setCurrent(get_PopupPage("ERROR", "DB error: " + db.getError().getMessage(), null, AlertType.ERROR),getDisplay().getCurrent());
}
// Insert pre-action code here
// Do nothing//GEN-LINE:MVDICAAction81
// Insert post-action code here
}//GEN-BEGIN:MVDICACase81
else if (command == clearUserName)
{//GEN-END:MVDICACase81
get_dmUserText().setString("");
try
{
db.open();
db.delete(DB_DM_USER);
db.close();
}
catch(Exception e)
{
getDisplay().setCurrent(get_PopupPage("ERROR", "DB error: " + db.getError().getMessage(), null, AlertType.ERROR),getDisplay().getCurrent());
}
// Insert pre-action code here
// Do nothing//GEN-LINE:MVDICAAction85
// Insert post-action code here
}//GEN-BEGIN:MVDICACase85
}
else if (item == whatAreYouDoing)
{
if (command == clearTweet)
{//GEN-END:MVDICACase85
get_whatAreYouDoing().setString("");
updateCharsAvailable(false);
try
{
db.open();
db.delete(DB_TWEET_MSG);
db.close();
}
catch(Exception e)
{
getDisplay().setCurrent(get_PopupPage("ERROR", "DB error: " + db.getError().getMessage(), null, AlertType.ERROR),getDisplay().getCurrent());
}
// Insert pre-action code here
// Do nothing//GEN-LINE:MVDICAAction47
// Insert post-action code here
}//GEN-BEGIN:MVDICACase47
else if (command == sendTweetItem)
{//GEN-END:MVDICACase47
// Insert pre-action code here
sendTweet();
// Do nothing//GEN-LINE:MVDICAAction73
// Insert post-action code here
}//GEN-BEGIN:MVDICACase73
else if (command == saveWhatAreYouDoing)
{//GEN-END:MVDICACase73
try
{
db.open();
getData().setTweetMsg(get_whatAreYouDoing().getString());
if(getData().getTweetMsg() != null) db.write(DB_TWEET_MSG, getData().getTweetMsg(), false);
db.close();
}
catch(Exception e)
{
getDisplay().setCurrent(get_PopupPage("ERROR", "DB error: " + db.getError().getMessage(), null, AlertType.ERROR),getDisplay().getCurrent());
}
// Insert pre-action code here
// Do nothing//GEN-LINE:MVDICAAction79
// Insert post-action code here
}//GEN-BEGIN:MVDICACase79
}
else if (item == dmMsg)
{
if (command == clearDirectMsgText)
{//GEN-END:MVDICACase79
// Insert pre-action code here
get_dmMsg().setString("");
updateCharsAvailable(true);
try
{
db.open();
db.delete(DB_DM_MSG);
db.close();
}
catch(Exception e)
{
getDisplay().setCurrent(get_PopupPage("ERROR", "DB error: " + db.getError().getMessage(), null, AlertType.ERROR),getDisplay().getCurrent());
}
// Do nothing//GEN-LINE:MVDICAAction49
// Insert post-action code here
}//GEN-BEGIN:MVDICACase49
else if (command == sendDirectMessageItem)
{//GEN-END:MVDICACase49
// Insert pre-action code here
sendDirectMessage();
// Do nothing//GEN-LINE:MVDICAAction75
// Insert post-action code here
}//GEN-BEGIN:MVDICACase75
else if (command == saveDirectMessage)
{//GEN-END:MVDICACase75
try
{
db.open();
getData().setDirectMessageMsg(get_dmMsg().getString());
if(getData().getDirectMessageMsg() != null) db.write(DB_DM_MSG, getData().getDirectMessageMsg(), false);
db.close();
}
catch(Exception e)
{
getDisplay().setCurrent(get_PopupPage("ERROR", "DB error: " + db.getError().getMessage(), null, AlertType.ERROR),getDisplay().getCurrent());
}
// Insert pre-action code here
// Do nothing//GEN-LINE:MVDICAAction83
// Insert post-action code here
}//GEN-BEGIN:MVDICACase83
}
else if (item == strLicense)
{
if (command == cmdAbout)
{//GEN-END:MVDICACase83
// Insert pre-action code here
getDisplay().setCurrent(get_PopupPage("", "" +
"Twittering\n" +
"http://sourceforge.net/projects/twittering\n" +
"Copyright (C) 2007, Timothy Lim Sheng Hwee. LimShengHwee@gmail.com\n" +
"\n" +
"This program 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.\n" +
"\n" +
"This program 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.",null, AlertType.INFO),getDisplay().getCurrent());
// Do nothing//GEN-LINE:MVDICAAction111
// Insert post-action code here
}//GEN-BEGIN:MVDICACase111
}//GEN-END:MVDICACase111
else if (command == selectFriend)
{
// Insert pre-action code here
try
{
StringItem friend = (StringItem) item;
get_dmUserText().setString(friend.getText());
getDisplay().setCurrent(get_formMain());
}
catch (Exception e)
{
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -