import java.sql.SQLException;
import totalcross.db.sqlite.SQLiteUtil;
import totalcross.io.IOException;
import totalcross.sample.util.Colors;
import totalcross.sql.PreparedStatement;
import totalcross.sql.Statement;
import totalcross.sys.Settings;
import totalcross.sys.Vm;
import totalcross.ui.Button;
import totalcross.ui.Check;
import totalcross.ui.Container;
import totalcross.ui.Edit;
import totalcross.ui.ImageControl;
import totalcross.ui.ScrollContainer;
import totalcross.ui.dialog.MessageBox;
import totalcross.ui.event.ControlEvent;
import totalcross.ui.event.Event;
import totalcross.ui.gfx.Color;
import totalcross.ui.image.Image;
import totalcross.ui.image.ImageException;
import totalcross.util.InvalidDateException;
public class Login extends ScrollContainer {
private Edit edPass, edLogin;
private Button btLogin, btRegister;
setBackForeColors(Colors.BACKGROUND, Colors.ON_BACKGROUND);
ic = new ImageControl(new Image("images/logo.png"));
add(ic, LEFT, TOP+100, FILL, PARENTSIZE+30);
edLogin.caption = "Login";
//edLogin.setBackColor(Color.RED);
add(edLogin, CENTER, AFTER+60, PARENTSIZE+90, PREFERRED+30);
edPass.caption = "Password";
//edPass.setBackColor(Color.RED);
edPass.setMode(Edit.PASSWORD_ALL);
add(edPass, SAME, AFTER+70, PARENTSIZE+90, PREFERRED+30);
ch = new Check("Remember Me");
add(ch, LEFT+86, AFTER+100, PARENTSIZE, PREFERRED+30);
btLogin = new Button("Login");
btLogin.setBackColor(Color.WHITE);
add(btLogin, CENTER, AFTER+140, PARENTSIZE+80, PREFERRED+60);
btRegister = new Button("Register Now");
btRegister.transparentBackground = true;
btRegister.setBorder(BORDER_NONE);
add(btRegister, CENTER, AFTER, PARENTSIZE+30, PREFERRED+20);
btRegister.addPressListener(e -> {Vm.exec("url", "http://www.totalcross.com", 0, true);});
util = new SQLiteUtil(Settings.appPath,"database.db");
Statement st = util.con().createStatement();
st.execute("create table if not exists person (login varchar(20), password varchar(20))");
} catch (IOException | ImageException | SQLException e) {
// TODO Auto-generated catch block
public void onEvent(Event e){
case ControlEvent.PRESSED:
MessageBox.showException(ee, true);
private void doInsert() throws SQLException, InvalidDateException, ImageException {
if (edLogin.getLength() == 0 || edPass.getLength() == 0){
MessageBox mb = new MessageBox("Message","Please fill all fields!",new String[]{"Close"});
mb.setBackForeColors(Color.WHITE, Color.BLACK);
// simple example of how you can insert data into SQLite..
String sql = "insert into person values(?,?)";
PreparedStatement st = util.con().prepareStatement(sql);
st.setString(1, edLogin.getText());
st.setString(2, edPass.getText());
MessageBox mbox = new MessageBox(null,"Data inserted successfully!");
mbox.setBackForeColors(Color.WHITE, Color.BLACK);