Gw baru aja script buat login di MIDP. Tapi login-nya pake canvas bukan pake form. Kenapa pake canvas? ada beberapa alasan kenapa aku lebih memilih canvas yaitu:
1. dari sisi UI canvas lebih fleksible & mudah make nya. Sedangkan form???? you know-lah gimana form itu
2. aku belum tau cara manggil dari yang high level gui ke low level gui (bisa atau kagak aku jg belum tau seh sebenarnya). Tapi kalo dari low level gui mah kagak bisa manggi high level gui.
3. page2 script aku yang lain juga make canvas semua, so......nanggung donk kalo just for login page pake form, ya sekalian aja login nya pake canvas semua biar kagak nanggung2.
4. mmmm........ dipikir2 dulu deh
Nah, ini neh script yang udah aku bikin. Mudah2an aja udah kagak ada bug lagi. Kalo ada bug, as soon as possible aku benerin. Script ini dibuat make emulator nokia s60 3rd dan midp 2.
LoginForm.java
package com.form;
import javax.microedition.lcdui.Graphics;
import com.MobileAPMain;
import com.nokia.mid.ui.FullCanvas;
import com.util.Engine;
import com.util.Library;
import com.util.Setting;
/*
* Kelas ini digunakan untuk menggambar form Login
*/
public class LoginForm extends FullCanvas implements Runnable{
private MobileAPMain main;
private Engine engine;
private boolean nim=true;
private boolean pwd=false;
private String pesan="";
private String pwdBintang="";
private long waktu=0;
private long maxBedaWaktu=600;
private String keyTemp="";
private int keyBefore=0;
private int banyakKeyBefore=0;
boolean upperCase=false;
private int loop=0;
public LoginForm(MobileAPMain main) {
super();
this.main=main;
}
protected void keyPressed(int key){
long currWaktu=System.currentTimeMillis();
if (key==Library.keyTop || key==Library.keyBottom) {
ChangeField(key);
}
else if (key==Library.keyPagar) {
if (!upperCase) upperCase=true;
else upperCase=false;
repaint();
}
else if (key==Library.keyOptionLeft) {
String mesg="";
if (!mesg.equals("")) {
}
else if (mesg.equals("")) {
pesan=Library.errLogin;
repaint();
}
}
else if (key==Library.keyOptionRight) main.exitApp();
else {
if (key==Library.keyC) {
if (nim && !main.pn_uname.equals("")) {
if (keyTemp.equals("")) main.pn_uname=main.pn_uname.substring(0, main.pn_uname.length()-1);
else keyTemp="";
}
else if (pwd && !main.pn_pass.equals("")) {
if (keyTemp.equals("")) {
main.pn_pass=main.pn_pass.substring(0, main.pn_pass.length()-1);
pwdBintang=pwdBintang.substring(0, pwdBintang.length()-1);
}
else keyTemp="";
}
}
else {
long bedaWaktu=currWaktu-waktu;
PropertyLogin(key,bedaWaktu);
}
repaint();
}
}
protected void paint(Graphics g) {
g.setColor(Library.ColorWhiteR, Library.ColorWhiteG, Library.ColorWhiteB);
g.fillRect(0, 0, this.getWidth(), this.getHeight());
g.setColor(Library.ColorBlackR, Library.ColorBlackG, Library.ColorBackgorundB);
g.drawString(pesan, 5, 30, Graphics.LEFT);
g.drawRect(Setting.xRect, Setting.yRect, Setting.widthRect, Setting.heightRect);
g.drawString("NIM", Setting.xString, Setting.yString, Graphics.LEFT);
g.drawRect(Setting.xRectField, Setting.yRectNim, Setting.widthField, Setting.heightField);
g.drawString("PASSWORD", Setting.xString, Setting.yPwd, Graphics.LEFT);
g.drawRect(Setting.xRectField, Setting.yRectPwd, Setting.widthField, Setting.heightField);
if (nim) {
g.drawString(main.pn_uname+keyTemp+"|", Setting.xFill, Setting.yString, Graphics.LEFT);
g.drawString(pwdBintang, Setting.xFill, Setting.yPwd, Graphics.LEFT);
}
else if (pwd){
g.drawString(main.pn_uname, Setting.xFill, Setting.yString, Graphics.LEFT);
g.drawString(pwdBintang+keyTemp+"|", Setting.xFill, Setting.yPwd, Graphics.LEFT);
}
g.drawString(Library.optionLogin, Setting.xOptionPilih, Setting.yOption, Graphics.LEFT);
g.drawString(Library.optionOut, Setting.xOptionBack, Setting.yOption, Graphics.RIGHT);
if (pwd) {
loop=0;
Thread th=new Thread(this);
th.start();
}
waktu=System.currentTimeMillis();
}
private void ChangeField(int key){
keyBefore=0;
banyakKeyBefore=1;
if (nim) {
main.pn_uname += keyTemp;
pwd=true;
nim=false;
}
else if (pwd) {
main.pn_pass += keyTemp;
pwdBintang += "*";
nim=true;
pwd=false;
}
keyTemp="";
repaint();
}
public void run() {
while (loop<10)>=10 && !keyTemp.equals("")) {
main.pn_pass += keyTemp;
pwdBintang += "*";
keyTemp="";
banyakKeyBefore=1;
repaint();
}
}
private void PropertyKeySame(long bedaWaktu,String[] prop) {
banyakKeyBefore++;
if (bedaWaktu>maxBedaWaktu) {
if (nim) {
main.pn_uname += keyTemp;
}
else if(pwd) {
main.pn_pass += keyTemp;
pwdBintang += "*";
}
banyakKeyBefore=1;
}
int i=2;
boolean stop=false;
while (i<=prop.length && !stop) { if (banyakKeyBefore==i) { keyTemp=prop[i-1]; stop=true; } i++; } if (!stop && banyakKeyBefore>=prop.length) {
keyTemp=prop[0];
banyakKeyBefore=1;
}
}
private void PropertyKeyDifferent(int key,String prop) {
if (nim) main.pn_uname += keyTemp;
else if(pwd) {
main.pn_pass += keyTemp;
if (!main.pn_pass.equals("") && !keyTemp.equals("")) pwdBintang += "*";
}
keyBefore=key;
banyakKeyBefore=1;
keyTemp=prop;
}
private String[] MakeCase(String[] prop) {
if (upperCase) {
for (int i=0;i
if (keyBefore==key)
PropertyKeySame(bedaWaktu,prop);
else
PropertyKeyDifferent(key,prop[0]);
}
else if (key==Library.key2) {
String[] prop={"a","b","c","2"};
prop = MakeCase(prop);
if (keyBefore==key)
PropertyKeySame(bedaWaktu,prop);
else
PropertyKeyDifferent(key,prop[0]);
}
else if (key==Library.key3) {
String[] prop={"d","e","f","3"};
prop = MakeCase(prop);
if (keyBefore==key)
PropertyKeySame(bedaWaktu,prop);
else
PropertyKeyDifferent(key,prop[0]);
}
else if (key==Library.key4) {
String[] prop={"g","h","i","4"};
prop = MakeCase(prop);
if (keyBefore==key)
PropertyKeySame(bedaWaktu,prop);
else
PropertyKeyDifferent(key,prop[0]);
}
else if (key==Library.key5) {
String[] prop={"j","k","l","5"};
prop = MakeCase(prop);
if (keyBefore==key)
PropertyKeySame(bedaWaktu,prop);
else
PropertyKeyDifferent(key,prop[0]);
}
else if (key==Library.key6) {
String[] prop={"m","n","o","6"};
prop = MakeCase(prop);
if (keyBefore==key)
PropertyKeySame(bedaWaktu,prop);
else
PropertyKeyDifferent(key,prop[0]);
}
else if (key==Library.key7) {
String[] prop={"p","q","r","s","7"};
prop = MakeCase(prop);
if (keyBefore==key)
PropertyKeySame(bedaWaktu,prop);
else
PropertyKeyDifferent(key,prop[0]);
}
else if (key==Library.key8) {
String[] prop={"t","u","v","8"};
prop = MakeCase(prop);
if (keyBefore==key)
PropertyKeySame(bedaWaktu,prop);
else
PropertyKeyDifferent(key,prop[0]);
}
else if (key==Library.key9) {
String[] prop={"w","x","y","9"};
prop = MakeCase(prop);
if (keyBefore==key)
PropertyKeySame(bedaWaktu,prop);
else
PropertyKeyDifferent(key,prop[0]);
}
}
}
Tidak ada komentar:
Posting Komentar