Olá possuo um aplicativo feito em J2ME de consulta a notas
O sistema é estruturado em um projeto em J2ME e uma servlett
o projeto j2me possui apenas uma classe que realiza todas as funções
Gostaria de aplicar padrões de projeto na refatoração dessa classe mas estou com dúvidas…
Não sei qual padrão ou padrões seriam aceitos nessa classe
Se alguem puder me ajudar…
Agradeço
Abaixo segue o código da classe
package midlet;
import java.io.IOException;
import javax.microedition.io.;
import javax.microedition.midlet.;
import javax.microedition.lcdui.;
import java.io.;
import javax.microedition.rms.RecordStore;
import javax.microedition.rms.RecordStoreException;
//import net.sourceforge.floggy.FloggyException;
//import net.sourceforge.floggy.ObjectSet;
//import net.sourceforge.floggy.PersistableManager;
//import java.util.Date;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import javax.microedition.rms.RecordEnumeration;
import javax.microedition.rms.RecordStore;
import javax.microedition.rms.RecordStoreException;
import javax.microedition.rms.RecordStoreNotOpenException;
public class AplicacaoSCN extends MIDlet implements CommandListener {
/**
* Creates a new instance of AplicacaoSCN
*/
public AplicacaoSCN() {
initialize();
}
private Form fInicial;//GEN-BEGIN:MVDFields
private Command cmSairfInicial;
private Command cmOKfInicial;
private Ticker tickerInicial;
private TextField tfUsuario;
private StringItem stringItemInicial;
private List listEscolha;
private Form fGravar;
private Command cmOKfGravar;
private Command cmSairfGravar;
private Command cmSairfVisualizar;
private Command cmOKfVisualizar;
private Command cancelCommand1;
private Command cmOKfEscolha;
private Command cmVoltarfEscolha;
private Alert alertloginaceito;
private Alert alertloginincorreto;
private Form fApresentacao;
private Command cmAcessarfApresentacao;
private Command cmAjudafApresentacao;
private Ticker tickerfApresentacao;
private Command cmSairfApresentacao;
private Alert alerterro;
private Command cmVoltarfGravar;
private Command cmVoltarfVisualizar;
private Command cmSairlistEscolha;
private Ticker ticker1;
private Command cmOklistEscolha;
private Alert alertlistEscolha;
private TextField tfAno;
private Command cmokmostrar;
private Command cmSairMostrar;
private List listResultado;
private Command okCommand1;
private Form fteste;
private StringItem strmaterias;
private Alert alertGravados;
private Alert alerterro1;
private StringItem strnome;
private StringItem strano;
private StringItem strmatricula;
private StringItem strcurso;
private Ticker tickerfteste;
private Command okfteste;
private StringItem strmaterias1;
private Command okgravadas;
private Command cmlimparrms;
private Command cmvoltarnotasexcluidas;
private Command backCommand1;
private Command okconfirmarexclusao;
private TextField tfSenha;//GEN-END:MVDFields
//GEN-LINE:MVDMethods
private String matCodigo;
private String aluDataNascimento;
private String resultUsuario;
private String resultSenha;
private String aldAnoCorrente;
public static final String DADOS = “rms”;
private DataOutputStream os = null;
private DataInputStream in = null;
private String mostrarid;
/** This method initializes UI of the application.//GEN-BEGIN:MVDInitBegin
*/
private void initialize() {//GEN-END:MVDInitBegin
this.refreshdados();
//this.get_strmatricula().setText(this.matriculaatual);
// this.get_strano().setText(this.anoatual);
// this.get_strnome().setText(this.nomeatual);
//this.get_strnome().setText(this.nomeatual);
// this.get_strcurso().setText(this.cursoatual);
//this.get_strmaterias1().setText(this.materiaatual);
//Insert pre-init code here
getDisplay().setCurrent(get_fApresentacao());//GEN-LINE:MVDInitInit
// Insert post-init code here
}//GEN-LINE:MVDInitEnd
/** Called by the system to indicate that a command has been invoked on a particular displayable.//GEN-BEGIN:MVDCABegin
-
@param command the Command that ws invoked
-
@param displayable the Displayable on which the command was invoked
*/
public void commandAction(Command command, Displayable displayable) {//GEN-END:MVDCABegin
// Insert global pre-action code here
if (displayable == fInicial) {//GEN-BEGIN:MVDCABody
if (command == cmSairfInicial) {//GEN-END:MVDCABody
// Insert pre-action code here
exitMIDlet();//GEN-LINE:MVDCAAction9
// Insert post-action code here
} else if (command == cmOKfInicial) {//GEN-LINE:MVDCACase9//se no fInicial o usuario escolher o comando OK try { // se os campos usuario E senha estiverem nulos if(("").equals(tfUsuario.getString()) && ("").equals(tfSenha.getString())) { //retorna ao fInicial com os campos usuario e senha em branco get_alerterro().setString( "\n o seguinte erro: \n Existem campos nulos!" ); getDisplay().setCurrent(get_alerterro(), get_fInicial()); // limpar os campos tfUsuario.setString(""); tfSenha.setString(""); } //se os campos usuario OU senha estiverem nulos else if(("").equals(tfUsuario.getString()) || ("").equals(tfSenha.getString())) { //então retorna ao fInicial,com os campos usuario e senha em branco get_alerterro().setString( "\n Ocorreu o seguinte erro : \n Existem campos nulos! \n " ); getDisplay().setCurrent(get_alerterro(), get_fInicial()); // limpar os campos tfUsuario.setString(""); tfSenha.setString(""); } else { //caso contrário, cria duas variáveis que recebem os valores dos conteúdos digitados nos textfields this.matCodigo = tfUsuario.getString(); this.aluDataNascimento= tfSenha.getString(); //e chama o método de conexão à web e ao banco de dados que utiliza uma thread ThreadLogin tl= new ThreadLogin(); tl.start(); } } catch (Exception e) { //tratamento de execeções- erros ma aplicação get_alerterro().setString( "\n Erro: \n Os Campos não podem ser nulos! \n " ); getDisplay().setCurrent(get_alerterro(), get_fInicial()); tfUsuario.setString(""); tfSenha.setString(""); //e.printStackTrace(); } // Do nothing//GEN-LINE:MVDCAAction11 }//GEN-BEGIN:MVDCACase11} else if (displayable == fGravar) {
if (command == cmSairfGravar) {//GEN-END:MVDCACase11
// Insert pre-action code here
exitMIDlet();//GEN-LINE:MVDCAAction51
// Insert post-action code here
} else if (command == cmOKfGravar) {//GEN-LINE:MVDCACase51
// Insert pre-action code here
//se no formulário inicial o usuario escolher o comando OK
try {// se o campo ano estiver nulo if(("").equals(tfAno.getString())) { //retorna ao fGravar com o campo ano limpo get_alerterro().setString( "\n Ocorreu o seguinte erro: \n O ano não foi informado!!!" ); getDisplay().setCurrent(get_alerterro(), get_fGravar()); // limpar os campo tfAno.setString(""); } else { //caso contrário cria uma variavel que recebe o valor this.aldAnoCorrente = tfAno.getString(); ThreadGravarNotas tg= new ThreadGravarNotas(); tg.start(); } } catch (Exception e) { //tratamento de execeções- erros ma aplicação get_alerterro().setString( "\n ERRO: \n Favor informar o ano! \n " ); getDisplay().setCurrent(get_alerterro(), get_fGravar()); tfAno.setString(""); } // Do nothing//GEN-LINE:MVDCAAction49 // Insert post-action code here } else if (command == cmVoltarfGravar) {//GEN-LINE:MVDCACase49 // Insert pre-action code here getDisplay().setCurrent(get_listEscolha());//GEN-LINE:MVDCAAction82 // Insert post-action code here }//GEN-BEGIN:MVDCACase82} else if (displayable == listEscolha) {
if (command == listEscolha.SELECT_COMMAND) {
switch (get_listEscolha().getSelectedIndex()) {
case 1://GEN-END:MVDCACase82
// Insert pre-action code here
// Do nothing//GEN-LINE:MVDCAAction21
getDisplay().setCurrent(get_fteste());
this.get_strmatricula().setText(this.matriculaatual);
this.get_strano().setText(this.anoatual);
this.get_strnome().setText(this.nomeatual);
this.get_strnome().setText(this.nomeatual);
this.get_strcurso().setText(this.cursoatual);
this.get_strmaterias1().setText(this.materiaatual);
break;//GEN-BEGIN:MVDCACase21
case 0://GEN-END:MVDCACase21
// Insert pre-action code here
getDisplay().setCurrent(get_fGravar());//GEN-LINE:MVDCAAction23
// Insert post-action code here
break;//GEN-BEGIN:MVDCACase23
}
} else if (command == cmSairlistEscolha) {//GEN-END:MVDCACase23
// Insert pre-action code here
exitMIDlet();//GEN-LINE:MVDCAAction86
// Insert post-action code here
}//GEN-BEGIN:MVDCACase86
} else if (displayable == fApresentacao) {
if (command == cmAjudafApresentacao) {//GEN-END:MVDCACase86
alertAjuda = new Alert( "Sistema de Consulta a Notas Acadêmicas: ",
"\n ORIENTAÇÕES DE USO DO SISTEMA: \n"+
" \n ################################## " +
"\n Escolha a opção Acessar o Sistema "+
"\n digite seu USUARIO (nº de matrícula) "+
"\n e sua SENHA (data de nascimento) \n"+
"\n *Caso sua escolha seja visualizar notas "+
"\n ,após gravadas,elas serão mostradas. "+
"\n *Caso sua escolha seja gravar notas "+
"\n ,após informar o ano as notas serão "+
"\n gravadas,e poderão serem vistas "+
"\n acessando a opção visualizar notas "+
" \n ################################## " , null, AlertType.INFO );
alertAjuda.setTimeout( Alert.FOREVER );
getDisplay().setCurrent( alertAjuda, get_fApresentacao() );
// Insert pre-action code here
// Do nothing//GEN-LINE:MVDCAAction73
// Insert post-action code here
} else if (command == cmSairfApresentacao) {//GEN-LINE:MVDCACase73
// Insert pre-action code here
// Do nothing//GEN-LINE:MVDCAAction76
// Insert post-action code here
} else if (command == cmAcessarfApresentacao) {//GEN-LINE:MVDCACase76
// Insert pre-action code here
getDisplay().setCurrent(get_fInicial());//GEN-LINE:MVDCAAction71
// Insert post-action code here
}//GEN-BEGIN:MVDCACase71
} else if (displayable == fteste) {
if (command == okfteste) {//GEN-END:MVDCACase71
getDisplay().setCurrent(get_listEscolha());
// Insert pre-action code here
// Do nothing//GEN-LINE:MVDCAAction140
// Insert post-action code here
}//GEN-BEGIN:MVDCACase140
} else if (displayable == alertGravados) {
if (command == okgravadas) {//GEN-END:MVDCACase140
this.refreshdados();
getDisplay().setCurrent(get_listEscolha());
// Do nothing//GEN-LINE:MVDCAAction144
// Insert post-action code here
}//GEN-BEGIN:MVDCACase144
}//GEN-END:MVDCACase144
// Insert global post-action code here
}//GEN-LINE:MVDCAEnd
/**
* This method should return an instance of the display.
*/
public Display getDisplay() {//GEN-FIRST:MVDGetDisplay
return Display.getDisplay(this);
}//GEN-LAST:MVDGetDisplay
/**
* This method should exit the midlet.
*/
public void exitMIDlet() {//GEN-FIRST:MVDExitMidlet
getDisplay().setCurrent(null);
destroyApp(true);
notifyDestroyed();
}//GEN-LAST:MVDExitMidlet
/** This method returns instance for fInicial component and should be called instead of accessing fInicial field directly.//GEN-BEGIN:MVDGetBegin6
* @return Instance for fInicial component
*/
public Form get_fInicial() {
if (fInicial == null) {//GEN-END:MVDGetBegin6
// Insert pre-init code here
fInicial = new Form(null, new Item[] {//GEN-BEGIN:MVDGetInit6
get_tfUsuario(),
get_tfSenha(),
get_stringItemInicial()
});
fInicial.addCommand(get_cmSairfInicial());
fInicial.addCommand(get_cmOKfInicial());
fInicial.setCommandListener(this);
fInicial.setTicker(get_tickerInicial());//GEN-END:MVDGetInit6
// Insert post-init code here
}//GEN-BEGIN:MVDGetEnd6
return fInicial;
}//GEN-END:MVDGetEnd6
/** This method returns instance for cmSairfInicial component and should be called instead of accessing cmSairfInicial field directly.//GEN-BEGIN:MVDGetBegin8
* @return Instance for cmSairfInicial component
*/
public Command get_cmSairfInicial() {
if (cmSairfInicial == null) {//GEN-END:MVDGetBegin8
// Insert pre-init code here
cmSairfInicial = new Command("Sair", Command.EXIT, 1);//GEN-LINE:MVDGetInit8
// Insert post-init code here
}//GEN-BEGIN:MVDGetEnd8
return cmSairfInicial;
}//GEN-END:MVDGetEnd8
/** This method returns instance for cmOKfInicial component and should be called instead of accessing cmOKfInicial field directly.//GEN-BEGIN:MVDGetBegin10
* @return Instance for cmOKfInicial component
*/
public Command get_cmOKfInicial() {
if (cmOKfInicial == null) {//GEN-END:MVDGetBegin10
// Insert pre-init code here
cmOKfInicial = new Command("Login", Command.OK, 1);//GEN-LINE:MVDGetInit10
// Insert post-init code here
}//GEN-BEGIN:MVDGetEnd10
return cmOKfInicial;
}//GEN-END:MVDGetEnd10
/** This method returns instance for tickerInicial component and should be called instead of accessing tickerInicial field directly.//GEN-BEGIN:MVDGetBegin12
* @return Instance for tickerInicial component
*/
public Ticker get_tickerInicial() {
if (tickerInicial == null) {//GEN-END:MVDGetBegin12
// Insert pre-init code here
tickerInicial = new Ticker("SISTEMA ACAD\u00CAMICO DE CONSULTA A NOTAS");//GEN-LINE:MVDGetInit12
// Insert post-init code here
}//GEN-BEGIN:MVDGetEnd12
return tickerInicial;
}//GEN-END:MVDGetEnd12
/** This method returns instance for tfUsuario component and should be called instead of accessing tfUsuario field directly.//GEN-BEGIN:MVDGetBegin13
* @return Instance for tfUsuario component
*/
public TextField get_tfUsuario() {
if (tfUsuario == null) {//GEN-END:MVDGetBegin13
// Insert pre-init code here
tfUsuario = new TextField("Usuario:", null, 120, TextField.ANY);//GEN-LINE:MVDGetInit13
// Insert post-init code here
}//GEN-BEGIN:MVDGetEnd13
return tfUsuario;
}//GEN-END:MVDGetEnd13
/** This method returns instance for stringItemInicial component and should be called instead of accessing stringItemInicial field directly.//GEN-BEGIN:MVDGetBegin15
* @return Instance for stringItemInicial component
*/
public StringItem get_stringItemInicial() {
if (stringItemInicial == null) {//GEN-END:MVDGetBegin15
// Insert pre-init code here
stringItemInicial = new StringItem("", "Favor informar os dados acima");//GEN-LINE:MVDGetInit15
// Insert post-init code here
}//GEN-BEGIN:MVDGetEnd15
return stringItemInicial;
}//GEN-END:MVDGetEnd15
/** This method returns instance for listEscolha component and should be called instead of accessing listEscolha field directly.//GEN-BEGIN:MVDGetBegin17
* @return Instance for listEscolha component
*/
public List get_listEscolha() {
if (listEscolha == null) {//GEN-END:MVDGetBegin17
// Insert pre-init code here
listEscolha = new List(null, Choice.IMPLICIT, new String[] {//GEN-BEGIN:MVDGetInit17
"Gravar Notas",
"Visualizar Notas"
}, new Image[] {
null,
null
});
listEscolha.addCommand(get_cmSairlistEscolha());
listEscolha.setCommandListener(this);
listEscolha.setTicker(get_ticker1());
listEscolha.setSelectedFlags(new boolean[] {
false,
false
});//GEN-END:MVDGetInit17
// Insert post-init code here
}//GEN-BEGIN:MVDGetEnd17
return listEscolha;
}//GEN-END:MVDGetEnd17
/** This method returns instance for fGravar component and should be called instead of accessing fGravar field directly.//GEN-BEGIN:MVDGetBegin44
* @return Instance for fGravar component
*/
public Form get_fGravar() {
if (fGravar == null) {//GEN-END:MVDGetBegin44
// Insert pre-init code here
fGravar = new Form(null, new Item[] {get_tfAno()});//GEN-BEGIN:MVDGetInit44
fGravar.addCommand(get_cmOKfGravar());
fGravar.addCommand(get_cmSairfGravar());
fGravar.addCommand(get_cmVoltarfGravar());
fGravar.setCommandListener(this);//GEN-END:MVDGetInit44
// Insert post-init code here
}//GEN-BEGIN:MVDGetEnd44
return fGravar;
}//GEN-END:MVDGetEnd44
/** This method returns instance for cmOKfGravar component and should be called instead of accessing cmOKfGravar field directly.//GEN-BEGIN:MVDGetBegin48
* @return Instance for cmOKfGravar component
*/
public Command get_cmOKfGravar() {
if (cmOKfGravar == null) {//GEN-END:MVDGetBegin48
// Insert pre-init code here
cmOKfGravar = new Command("Ok", Command.OK, 1);//GEN-LINE:MVDGetInit48
// Insert post-init code here
}//GEN-BEGIN:MVDGetEnd48
return cmOKfGravar;
}//GEN-END:MVDGetEnd48
/** This method returns instance for cmSairfGravar component and should be called instead of accessing cmSairfGravar field directly.//GEN-BEGIN:MVDGetBegin50
* @return Instance for cmSairfGravar component
*/
public Command get_cmSairfGravar() {
if (cmSairfGravar == null) {//GEN-END:MVDGetBegin50
// Insert pre-init code here
cmSairfGravar = new Command("Exit", Command.EXIT, 1);//GEN-LINE:MVDGetInit50
// Insert post-init code here
}//GEN-BEGIN:MVDGetEnd50
return cmSairfGravar;
}//GEN-END:MVDGetEnd50
/** This method returns instance for cmSairfVisualizar component and should be called instead of accessing cmSairfVisualizar field directly.//GEN-BEGIN:MVDGetBegin52
* @return Instance for cmSairfVisualizar component
*/
public Command get_cmSairfVisualizar() {
if (cmSairfVisualizar == null) {//GEN-END:MVDGetBegin52
// Insert pre-init code here
cmSairfVisualizar = new Command("Exit", Command.EXIT, 1);//GEN-LINE:MVDGetInit52
// Insert post-init code here
}//GEN-BEGIN:MVDGetEnd52
return cmSairfVisualizar;
}//GEN-END:MVDGetEnd52
/** This method returns instance for cmOKfVisualizar component and should be called instead of accessing cmOKfVisualizar field directly.//GEN-BEGIN:MVDGetBegin54
* @return Instance for cmOKfVisualizar component
*/
public Command get_cmOKfVisualizar() {
if (cmOKfVisualizar == null) {//GEN-END:MVDGetBegin54
// Insert pre-init code here
cmOKfVisualizar = new Command("Ok", Command.OK, 1);//GEN-LINE:MVDGetInit54
// Insert post-init code here
}//GEN-BEGIN:MVDGetEnd54
return cmOKfVisualizar;
}//GEN-END:MVDGetEnd54
/** This method returns instance for cancelCommand1 component and should be called instead of accessing cancelCommand1 field directly.//GEN-BEGIN:MVDGetBegin58
* @return Instance for cancelCommand1 component
*/
public Command get_cancelCommand1() {
if (cancelCommand1 == null) {//GEN-END:MVDGetBegin58
// Insert pre-init code here
cancelCommand1 = new Command("Cancel", Command.CANCEL, 1);//GEN-LINE:MVDGetInit58
// Insert post-init code here
}//GEN-BEGIN:MVDGetEnd58
return cancelCommand1;
}//GEN-END:MVDGetEnd58
/** This method returns instance for cmOKfEscolha component and should be called instead of accessing cmOKfEscolha field directly.//GEN-BEGIN:MVDGetBegin60
* @return Instance for cmOKfEscolha component
*/
public Command get_cmOKfEscolha() {
if (cmOKfEscolha == null) {//GEN-END:MVDGetBegin60
// Insert pre-init code here
cmOKfEscolha = new Command("Ok", Command.OK, 1);//GEN-LINE:MVDGetInit60
// Insert post-init code here
}//GEN-BEGIN:MVDGetEnd60
return cmOKfEscolha;
}//GEN-END:MVDGetEnd60
/** This method returns instance for cmVoltarfEscolha component and should be called instead of accessing cmVoltarfEscolha field directly.//GEN-BEGIN:MVDGetBegin63
* @return Instance for cmVoltarfEscolha component
*/
public Command get_cmVoltarfEscolha() {
if (cmVoltarfEscolha == null) {//GEN-END:MVDGetBegin63
// Insert pre-init code here
cmVoltarfEscolha = new Command("Back", Command.BACK, 1);//GEN-LINE:MVDGetInit63
// Insert post-init code here
}//GEN-BEGIN:MVDGetEnd63
return cmVoltarfEscolha;
}//GEN-END:MVDGetEnd63
/** This method returns instance for alertloginaceito component and should be called instead of accessing alertloginaceito field directly.//GEN-BEGIN:MVDGetBegin65
* @return Instance for alertloginaceito component
*/
public Alert get_alertloginaceito() {
if (alertloginaceito == null) {//GEN-END:MVDGetBegin65
// Insert pre-init code here
alertloginaceito = new Alert(null, "", null, AlertType.CONFIRMATION);//GEN-BEGIN:MVDGetInit65
alertloginaceito.setTimeout(-2);//GEN-END:MVDGetInit65
// Insert post-init code here
}//GEN-BEGIN:MVDGetEnd65
return alertloginaceito;
}//GEN-END:MVDGetEnd65
/** This method returns instance for alertloginincorreto component and should be called instead of accessing alertloginincorreto field directly.//GEN-BEGIN:MVDGetBegin66
* @return Instance for alertloginincorreto component
*/
public Alert get_alertloginincorreto() {
if (alertloginincorreto == null) {//GEN-END:MVDGetBegin66
// Insert pre-init code here
alertloginincorreto = new Alert(null, "usu\u00E1rio ou senha invalido(s)!!!!", null, AlertType.ERROR);//GEN-BEGIN:MVDGetInit66
alertloginincorreto.setTimeout(-2);//GEN-END:MVDGetInit66
// Insert post-init code here
}//GEN-BEGIN:MVDGetEnd66
return alertloginincorreto;
}//GEN-END:MVDGetEnd66
/** This method returns instance for fApresentacao component and should be called instead of accessing fApresentacao field directly.//GEN-BEGIN:MVDGetBegin67
* @return Instance for fApresentacao component
*/
public Form get_fApresentacao() {
if (fApresentacao == null) {//GEN-END:MVDGetBegin67
// Insert pre-init code here
fApresentacao = new Form(null, new Item[0]);//GEN-BEGIN:MVDGetInit67
fApresentacao.addCommand(get_cmAcessarfApresentacao());
fApresentacao.addCommand(get_cmAjudafApresentacao());
fApresentacao.addCommand(get_cmSairfApresentacao());
fApresentacao.setCommandListener(this);
fApresentacao.setTicker(get_tickerfApresentacao());//GEN-END:MVDGetInit67
// Insert post-init code here
}//GEN-BEGIN:MVDGetEnd67
return fApresentacao;
}//GEN-END:MVDGetEnd67
/** This method returns instance for cmAcessarfApresentacao component and should be called instead of accessing cmAcessarfApresentacao field directly.//GEN-BEGIN:MVDGetBegin70
* @return Instance for cmAcessarfApresentacao component
*/
public Command get_cmAcessarfApresentacao() {
if (cmAcessarfApresentacao == null) {//GEN-END:MVDGetBegin70
// Insert pre-init code here
cmAcessarfApresentacao = new Command("Acessar o Sistema", Command.OK, 1);//GEN-LINE:MVDGetInit70
// Insert post-init code here
}//GEN-BEGIN:MVDGetEnd70
return cmAcessarfApresentacao;
}//GEN-END:MVDGetEnd70
/** This method returns instance for cmAjudafApresentacao component and should be called instead of accessing cmAjudafApresentacao field directly.//GEN-BEGIN:MVDGetBegin72
* @return Instance for cmAjudafApresentacao component
*/
public Command get_cmAjudafApresentacao() {
if (cmAjudafApresentacao == null) {//GEN-END:MVDGetBegin72
// Insert pre-init code here
cmAjudafApresentacao = new Command("Ajuda", Command.HELP, 1);//GEN-LINE:MVDGetInit72
// Insert post-init code here
}//GEN-BEGIN:MVDGetEnd72
return cmAjudafApresentacao;
}//GEN-END:MVDGetEnd72
/** This method returns instance for tickerfApresentacao component and should be called instead of accessing tickerfApresentacao field directly.//GEN-BEGIN:MVDGetBegin74
* @return Instance for tickerfApresentacao component
*/
public Ticker get_tickerfApresentacao() {
if (tickerfApresentacao == null) {//GEN-END:MVDGetBegin74
// Insert pre-init code here
tickerfApresentacao = new Ticker("Sistema de Consulta a Notas");//GEN-LINE:MVDGetInit74
// Insert post-init code here
}//GEN-BEGIN:MVDGetEnd74
return tickerfApresentacao;
}//GEN-END:MVDGetEnd74
/** This method returns instance for cmSairfApresentacao component and should be called instead of accessing cmSairfApresentacao field directly.//GEN-BEGIN:MVDGetBegin75
* @return Instance for cmSairfApresentacao component
*/
public Command get_cmSairfApresentacao() {
if (cmSairfApresentacao == null) {//GEN-END:MVDGetBegin75
// Insert pre-init code here
cmSairfApresentacao = new Command("Sair", Command.EXIT, 1);//GEN-LINE:MVDGetInit75
// Insert post-init code here
}//GEN-BEGIN:MVDGetEnd75
return cmSairfApresentacao;
}//GEN-END:MVDGetEnd75
/** This method returns instance for alerterro component and should be called instead of accessing alerterro field directly.//GEN-BEGIN:MVDGetBegin80
* @return Instance for alerterro component
*/
public Alert get_alerterro() {
if (alerterro == null) {//GEN-END:MVDGetBegin80
// Insert pre-init code here
alerterro = new Alert(null, "Existem campos sem preencher!!!!", null, null);//GEN-BEGIN:MVDGetInit80
alerterro.setTimeout(-2);//GEN-END:MVDGetInit80
// Insert post-init code here
}//GEN-BEGIN:MVDGetEnd80
return alerterro;
}//GEN-END:MVDGetEnd80
/** This method returns instance for cmVoltarfGravar component and should be called instead of accessing cmVoltarfGravar field directly.//GEN-BEGIN:MVDGetBegin81
* @return Instance for cmVoltarfGravar component
*/
public Command get_cmVoltarfGravar() {
if (cmVoltarfGravar == null) {//GEN-END:MVDGetBegin81
// Insert pre-init code here
cmVoltarfGravar = new Command("Voltar", Command.BACK, 1);//GEN-LINE:MVDGetInit81
// Insert post-init code here
}//GEN-BEGIN:MVDGetEnd81
return cmVoltarfGravar;
}//GEN-END:MVDGetEnd81
/** This method returns instance for cmVoltarfVisualizar component and should be called instead of accessing cmVoltarfVisualizar field directly.//GEN-BEGIN:MVDGetBegin83
* @return Instance for cmVoltarfVisualizar component
*/
public Command get_cmVoltarfVisualizar() {
if (cmVoltarfVisualizar == null) {//GEN-END:MVDGetBegin83
// Insert pre-init code here
cmVoltarfVisualizar = new Command("Voltar", Command.BACK, 1);//GEN-LINE:MVDGetInit83
// Insert post-init code here
}//GEN-BEGIN:MVDGetEnd83
return cmVoltarfVisualizar;
}//GEN-END:MVDGetEnd83
/** This method returns instance for cmSairlistEscolha component and should be called instead of accessing cmSairlistEscolha field directly.//GEN-BEGIN:MVDGetBegin85
* @return Instance for cmSairlistEscolha component
*/
public Command get_cmSairlistEscolha() {
if (cmSairlistEscolha == null) {//GEN-END:MVDGetBegin85
// Insert pre-init code here
cmSairlistEscolha = new Command("Sair", Command.EXIT, 1);//GEN-LINE:MVDGetInit85
// Insert post-init code here
}//GEN-BEGIN:MVDGetEnd85
return cmSairlistEscolha;
}//GEN-END:MVDGetEnd85
/** This method returns instance for ticker1 component and should be called instead of accessing ticker1 field directly.//GEN-BEGIN:MVDGetBegin87
* @return Instance for ticker1 component
*/
public Ticker get_ticker1() {
if (ticker1 == null) {//GEN-END:MVDGetBegin87
// Insert pre-init code here
ticker1 = new Ticker("BEM VINDO(A)....... Escolha uma das op\u00E7\u00F5es abaixo:");//GEN-LINE:MVDGetInit87
// Insert post-init code here
}//GEN-BEGIN:MVDGetEnd87
return ticker1;
}//GEN-END:MVDGetEnd87
/** This method returns instance for cmOklistEscolha component and should be called instead of accessing cmOklistEscolha field directly.//GEN-BEGIN:MVDGetBegin88
* @return Instance for cmOklistEscolha component
*/
public Command get_cmOklistEscolha() {
if (cmOklistEscolha == null) {//GEN-END:MVDGetBegin88
// Insert pre-init code here
cmOklistEscolha = new Command("Ok", Command.OK, 1);//GEN-LINE:MVDGetInit88
// Insert post-init code here
}//GEN-BEGIN:MVDGetEnd88
return cmOklistEscolha;
}//GEN-END:MVDGetEnd88
/** This method returns instance for alertlistEscolha component and should be called instead of accessing alertlistEscolha field directly.//GEN-BEGIN:MVDGetBegin90
* @return Instance for alertlistEscolha component
*/
public Alert get_alertlistEscolha() {
if (alertlistEscolha == null) {//GEN-END:MVDGetBegin90
// Insert pre-init code here
alertlistEscolha = new Alert(null, "<Enter Text>", null, null);//GEN-BEGIN:MVDGetInit90
alertlistEscolha.setTimeout(-2);//GEN-END:MVDGetInit90
// Insert post-init code here
}//GEN-BEGIN:MVDGetEnd90
return alertlistEscolha;
}//GEN-END:MVDGetEnd90
/** This method returns instance for tfAno component and should be called instead of accessing tfAno field directly.//GEN-BEGIN:MVDGetBegin91
* @return Instance for tfAno component
*/
public TextField get_tfAno() {
if (tfAno == null) {//GEN-END:MVDGetBegin91
// Insert pre-init code here
tfAno = new TextField("Favor informar o ano abaixo:", "", 120, TextField.ANY);//GEN-LINE:MVDGetInit91
// Insert post-init code here
}//GEN-BEGIN:MVDGetEnd91
return tfAno;
}//GEN-END:MVDGetEnd91
/** This method returns instance for cmokmostrar component and should be called instead of accessing cmokmostrar field directly.//GEN-BEGIN:MVDGetBegin94
* @return Instance for cmokmostrar component
*/
public Command get_cmokmostrar() {
if (cmokmostrar == null) {//GEN-END:MVDGetBegin94
// Insert pre-init code here
cmokmostrar = new Command("Ok", Command.OK, 1);//GEN-LINE:MVDGetInit94
// Insert post-init code here
}//GEN-BEGIN:MVDGetEnd94
return cmokmostrar;
}//GEN-END:MVDGetEnd94
/** This method returns instance for cmSairMostrar component and should be called instead of accessing cmSairMostrar field directly.//GEN-BEGIN:MVDGetBegin96
* @return Instance for cmSairMostrar component
*/
public Command get_cmSairMostrar() {
if (cmSairMostrar == null) {//GEN-END:MVDGetBegin96
// Insert pre-init code here
cmSairMostrar = new Command("Exit", Command.EXIT, 1);//GEN-LINE:MVDGetInit96
// Insert post-init code here
}//GEN-BEGIN:MVDGetEnd96
return cmSairMostrar;
}//GEN-END:MVDGetEnd96
/** This method returns instance for listResultado component and should be called instead of accessing listResultado field directly.//GEN-BEGIN:MVDGetBegin101
* @return Instance for listResultado component
*/
public List get_listResultado() {
if (listResultado == null) {//GEN-END:MVDGetBegin101
// Insert pre-init code here
listResultado = new List(null, Choice.IMPLICIT, new String[0], new Image[0]);//GEN-BEGIN:MVDGetInit101
listResultado.setCommandListener(this);
listResultado.setSelectedFlags(new boolean[0]);//GEN-END:MVDGetInit101
// Insert post-init code here
}//GEN-BEGIN:MVDGetEnd101
return listResultado;
}//GEN-END:MVDGetEnd101
/** This method returns instance for okCommand1 component and should be called instead of accessing okCommand1 field directly.//GEN-BEGIN:MVDGetBegin107
* @return Instance for okCommand1 component
*/
public Command get_okCommand1() {
if (okCommand1 == null) {//GEN-END:MVDGetBegin107
// Insert pre-init code here
okCommand1 = new Command("Ok", Command.OK, 1);//GEN-LINE:MVDGetInit107
// Insert post-init code here
}//GEN-BEGIN:MVDGetEnd107
return okCommand1;
}//GEN-END:MVDGetEnd107
/** This method returns instance for fteste component and should be called instead of accessing fteste field directly.//GEN-BEGIN:MVDGetBegin113
* @return Instance for fteste component
*/
public Form get_fteste() {
if (fteste == null) {//GEN-END:MVDGetBegin113
// Insert pre-init code here
fteste = new Form(null, new Item[] {//GEN-BEGIN:MVDGetInit113
get_strano(),
get_strmatricula(),
get_strnome(),
get_strcurso(),
get_strmaterias1()
});
fteste.addCommand(get_okfteste());
fteste.setCommandListener(this);
fteste.setTicker(get_tickerfteste());//GEN-END:MVDGetInit113
// Insert post-init code here
}//GEN-BEGIN:MVDGetEnd113
return fteste;
}//GEN-END:MVDGetEnd113
/** This method returns instance for strmaterias component and should be called instead of accessing strmaterias field directly.//GEN-BEGIN:MVDGetBegin120
* @return Instance for strmaterias component
*/
public StringItem get_strmaterias() {
if (strmaterias == null) {//GEN-END:MVDGetBegin120
// Insert pre-init code here
strmaterias = new StringItem("", "");//GEN-LINE:MVDGetInit120
// Insert post-init code here
}//GEN-BEGIN:MVDGetEnd120
return strmaterias;
}//GEN-END:MVDGetEnd120
/** This method returns instance for alertGravados component and should be called instead of accessing alertGravados field directly.//GEN-BEGIN:MVDGetBegin122
* @return Instance for alertGravados component
*/
public Alert get_alertGravados() {
if (alertGravados == null) {//GEN-END:MVDGetBegin122
// Insert pre-init code here
alertGravados = new Alert(null, "Notas Gravadas com sucesso...", null, null);//GEN-BEGIN:MVDGetInit122
alertGravados.addCommand(get_okgravadas());
alertGravados.setCommandListener(this);
alertGravados.setTimeout(-2);//GEN-END:MVDGetInit122
// Insert post-init code here
}//GEN-BEGIN:MVDGetEnd122
return alertGravados;
}//GEN-END:MVDGetEnd122
/** This method returns instance for alerterro1 component and should be called instead of accessing alerterro1 field directly.//GEN-BEGIN:MVDGetBegin125
* @return Instance for alerterro1 component
*/
public Alert get_alerterro1() {
if (alerterro1 == null) {//GEN-END:MVDGetBegin125
// Insert pre-init code here
alerterro1 = new Alert(null, "Informa\u00E7\u00F5es n\u00E3o encontradas no banco de dados!!!!!!!Tente novamente.....", null, null);//GEN-BEGIN:MVDGetInit125
alerterro1.setTimeout(-2);//GEN-END:MVDGetInit125
// Insert post-init code here
}//GEN-BEGIN:MVDGetEnd125
return alerterro1;
}//GEN-END:MVDGetEnd125
/** This method returns instance for strnome component and should be called instead of accessing strnome field directly.//GEN-BEGIN:MVDGetBegin132
* @return Instance for strnome component
*/
public StringItem get_strnome() {
if (strnome == null) {//GEN-END:MVDGetBegin132
// Insert pre-init code here
strnome = new StringItem("Nome do Aluno:\n", "<Enter Text>");//GEN-LINE:MVDGetInit132
// Insert post-init code here
}//GEN-BEGIN:MVDGetEnd132
return strnome;
}//GEN-END:MVDGetEnd132
/** This method returns instance for strano component and should be called instead of accessing strano field directly.//GEN-BEGIN:MVDGetBegin133
* @return Instance for strano component
*/
public StringItem get_strano() {
if (strano == null) {//GEN-END:MVDGetBegin133
// Insert pre-init code here
strano = new StringItem("Ano:\n\n", "");//GEN-LINE:MVDGetInit133
// Insert post-init code here
}//GEN-BEGIN:MVDGetEnd133
return strano;
}//GEN-END:MVDGetEnd133
/** This method returns instance for strmatricula component and should be called instead of accessing strmatricula field directly.//GEN-BEGIN:MVDGetBegin134
* @return Instance for strmatricula component
*/
public StringItem get_strmatricula() {
if (strmatricula == null) {//GEN-END:MVDGetBegin134
// Insert pre-init code here
strmatricula = new StringItem("Matr\u00EDcula:\n", "<Enter Text>");//GEN-LINE:MVDGetInit134
// Insert post-init code here
}//GEN-BEGIN:MVDGetEnd134
return strmatricula;
}//GEN-END:MVDGetEnd134
/** This method returns instance for strcurso component and should be called instead of accessing strcurso field directly.//GEN-BEGIN:MVDGetBegin135
* @return Instance for strcurso component
*/
public StringItem get_strcurso() {
if (strcurso == null) {//GEN-END:MVDGetBegin135
// Insert pre-init code here
strcurso = new StringItem("Curso:", "<Enter Text>");//GEN-LINE:MVDGetInit135
// Insert post-init code here
}//GEN-BEGIN:MVDGetEnd135
return strcurso;
}//GEN-END:MVDGetEnd135
/** This method returns instance for tickerfteste component and should be called instead of accessing tickerfteste field directly.//GEN-BEGIN:MVDGetBegin136
* @return Instance for tickerfteste component
*/
public Ticker get_tickerfteste() {
if (tickerfteste == null) {//GEN-END:MVDGetBegin136
// Insert pre-init code here
tickerfteste = new Ticker("Sistema Acad\u00EAmico de Consulta a Notas");//GEN-LINE:MVDGetInit136
// Insert post-init code here
}//GEN-BEGIN:MVDGetEnd136
return tickerfteste;
}//GEN-END:MVDGetEnd136
/** This method returns instance for okfteste component and should be called instead of accessing okfteste field directly.//GEN-BEGIN:MVDGetBegin139
* @return Instance for okfteste component
*/
public Command get_okfteste() {
if (okfteste == null) {//GEN-END:MVDGetBegin139
// Insert pre-init code here
okfteste = new Command("Voltar", Command.OK, 1);//GEN-LINE:MVDGetInit139
// Insert post-init code here
}//GEN-BEGIN:MVDGetEnd139
return okfteste;
}//GEN-END:MVDGetEnd139
/** This method returns instance for strmaterias1 component and should be called instead of accessing strmaterias1 field directly.//GEN-BEGIN:MVDGetBegin141
* @return Instance for strmaterias1 component
*/
public StringItem get_strmaterias1() {
if (strmaterias1 == null) {//GEN-END:MVDGetBegin141
// Insert pre-init code here
strmaterias1 = new StringItem("\n\n*****Mat\u00E9rias e Notas*********\n\n", "<Enter Text>");//GEN-LINE:MVDGetInit141
// Insert post-init code here
}//GEN-BEGIN:MVDGetEnd141
return strmaterias1;
}//GEN-END:MVDGetEnd141
/** This method returns instance for okgravadas component and should be called instead of accessing okgravadas field directly.//GEN-BEGIN:MVDGetBegin143
* @return Instance for okgravadas component
*/
public Command get_okgravadas() {
if (okgravadas == null) {//GEN-END:MVDGetBegin143
// Insert pre-init code here
okgravadas = new Command("Ok", Command.OK, 1);//GEN-LINE:MVDGetInit143
// Insert post-init code here
}//GEN-BEGIN:MVDGetEnd143
return okgravadas;
}//GEN-END:MVDGetEnd143
/** This method returns instance for cmlimparrms component and should be called instead of accessing cmlimparrms field directly.//GEN-BEGIN:MVDGetBegin145
* @return Instance for cmlimparrms component
*/
public Command get_cmlimparrms() {
if (cmlimparrms == null) {//GEN-END:MVDGetBegin145
// Insert pre-init code here
cmlimparrms = new Command("excluir notas", Command.OK, 1);//GEN-LINE:MVDGetInit145
// Insert post-init code here
}//GEN-BEGIN:MVDGetEnd145
return cmlimparrms;
}//GEN-END:MVDGetEnd145
/** This method returns instance for cmvoltarnotasexcluidas component and should be called instead of accessing cmvoltarnotasexcluidas field directly.//GEN-BEGIN:MVDGetBegin149
* @return Instance for cmvoltarnotasexcluidas component
*/
public Command get_cmvoltarnotasexcluidas() {
if (cmvoltarnotasexcluidas == null) {//GEN-END:MVDGetBegin149
// Insert pre-init code here
cmvoltarnotasexcluidas = new Command("Voltar", Command.BACK, 1);//GEN-LINE:MVDGetInit149
// Insert post-init code here
}//GEN-BEGIN:MVDGetEnd149
return cmvoltarnotasexcluidas;
}//GEN-END:MVDGetEnd149
/** This method returns instance for backCommand1 component and should be called instead of accessing backCommand1 field directly.//GEN-BEGIN:MVDGetBegin154
* @return Instance for backCommand1 component
*/
public Command get_backCommand1() {
if (backCommand1 == null) {//GEN-END:MVDGetBegin154
// Insert pre-init code here
backCommand1 = new Command("N\u00E3o", Command.BACK, 1);//GEN-LINE:MVDGetInit154
// Insert post-init code here
}//GEN-BEGIN:MVDGetEnd154
return backCommand1;
}//GEN-END:MVDGetEnd154
/** This method returns instance for okconfirmarexclusao component and should be called instead of accessing okconfirmarexclusao field directly.//GEN-BEGIN:MVDGetBegin158
* @return Instance for okconfirmarexclusao component
*/
public Command get_okconfirmarexclusao() {
if (okconfirmarexclusao == null) {//GEN-END:MVDGetBegin158
// Insert pre-init code here
okconfirmarexclusao = new Command("Sim", Command.OK, 1);//GEN-LINE:MVDGetInit158
// Insert post-init code here
}//GEN-BEGIN:MVDGetEnd158
return okconfirmarexclusao;
}//GEN-END:MVDGetEnd158
/** This method returns instance for tfSenha component and should be called instead of accessing tfSenha field directly.//GEN-BEGIN:MVDGetBegin161
* @return Instance for tfSenha component
*/
public TextField get_tfSenha() {
if (tfSenha == null) {//GEN-END:MVDGetBegin161
// Insert pre-init code here
tfSenha = new TextField("Senha", null, 120, TextField.ANY | TextField.PASSWORD);//GEN-LINE:MVDGetInit161
// Insert post-init code here
}//GEN-BEGIN:MVDGetEnd161
return tfSenha;
}//GEN-END:MVDGetEnd161
private String cursoatual;
private Alert alertAjuda;
private String nomeatual;
private String anoatual;
private String materiaatual;
private String matriculaatual;
//é uma exigência do java que seja criada uma thread para abrir conexão com o servlet
// aqui se encontra a tread responsável pelo login
private class ThreadLogin extends Thread{
public String url = "http://localhost:8080/Servlettcc/SCN?comm=login"; // enviando comando como parametro
public void run() {
HttpConnection http = null;
try {
http = (HttpConnection)Connector.open(url, Connector.READ_WRITE);
http.setRequestProperty("User-Agent", "Profile/MIDP-2.1 , Configuration/CLDC-1.1");
http.setRequestProperty("Content-Language", "en-US");
http.setRequestMethod(HttpConnection.POST);
System.out.println( "\n a conexão http foi aberta ");
os = http.openDataOutputStream();
os.writeUTF(matCodigo.trim());
os.writeUTF(aluDataNascimento.trim());
os.flush();
System.out.println( "\n Enviando String url: " + url );
} catch (IOException ex) {
System.out.println( "\n Erro ao enviar url");
getDisplay().setCurrent(get_alerterro(), get_fInicial());
}
try {
in = http.openDataInputStream();
System.out.println( "\n Passei pelo fluxo de entrada de dados" );
} catch (IOException ex) {
System.out.println( "\n erro na entrada de fluxo de dados" );
}
try {
// entrada de fluxo de dados
resultUsuario = in.readUTF();
resultSenha = in.readUTF();
if ( ("").equals(resultUsuario) && ("").equals(resultSenha) ){
System.out.println( " resultUsuario = null");
getDisplay().setCurrent(get_alerterro(), get_fInicial());
resultUsuario = null;
resultSenha = null;
} else {
try {
// se o resultUsuario e resultsenha <> null
alertloginaceito = new Alert( "\n Seja Bem Vindo(a):\n ","\n Bem Vindo(a): \n " + resultUsuario, null, AlertType.CONFIRMATION) ;
getDisplay().setCurrent(get_listEscolha());
os.close();
System.out.println( "\n a saida de dados foi fechada");
in.close();
System.out.println( "\n a entrada de dados foi fechada");
http.close();
System.out.println( "\n a conexão http foi fechada ");
resultUsuario = null;
resultSenha = null;
} catch (IOException ex) {
}
}
} catch (IOException ex) {
System.out.println( "erro login");
stringItemInicial.setLabel("Erro: ");
stringItemInicial.setText("Dados não encontrados. Por favor, Faça seu login novamente!");
getDisplay().setCurrent(get_fInicial());
tfUsuario.setString("");
tfSenha.setString("");
resultUsuario = null;
resultSenha = null;
}
}
}
private class ThreadGravarNotas extends Thread {
public String url ="http://localhost:8080/Servlettcc/SCN?comm=notas";
private String aluNome;
private String curNome;
private String disNome;
private float aldNota1;
private float aldNota2;
private float aldNota3;
private float aldNota4;
private String resultUsuario;
private String aluAnoResult;
private String aluNomeResult;
private String aluCursoResult;
private String aluMateriaResult;
private Alert alertResultado;
private List listaResultado;
private int id;
public void run() {
HttpConnection http = null;
try {
//abre a conexão HTTP
http = (HttpConnection)Connector.open(url, Connector.READ_WRITE);
http.setRequestProperty("User-Agent", "Profile/MIDP-2.1 , Configuration/CLDC-1.1");
http.setRequestProperty("Content-Language", "en-US");
http.setRequestMethod(HttpConnection.POST);
System.out.println( "\n a conexão http foi aberta ");
//abre a saida de dados do celular
os = http.openDataOutputStream();
os.writeUTF(matCodigo.trim());
os.writeUTF(aldAnoCorrente.trim());
os.flush();
System.out.println( " Enviando o codigo e o ano ( "+aldAnoCorrente+")");
} catch (IOException ex) {
System.out.println( "\n erro ao enviar codigo e ano " );
getDisplay().setCurrent(get_alerterro(), get_fGravar());
}
try {
in = http.openDataInputStream();
System.out.println( " foi aberta a entrada de fluxo de dados " );
} catch (IOException ex) {
System.out.println( "erro ao abrir entrada de fluxo de dados" );
}
try {
resultUsuario =in.readUTF();
aluAnoResult =in.readUTF();
aluNomeResult = in.readUTF();
aluCursoResult= in.readUTF();
aluMateriaResult= in.readUTF();
System.out.println("codigo do aluno = " + resultUsuario);
System.out.println("Ano = " + aluAnoResult);
System.out.println("Nome do aluno = " +aluNomeResult );
System.out.println("Nome do curso = " +aluCursoResult);
System.out.println( aluMateriaResult);
System.out.println( "\n os dados do servlet foram recebidos" );
if ( ("").equals( resultUsuario )){
System.out.println( "\n resultUsuario = null");
System.out.println("codigo do aluno = " + resultUsuario);
System.out.println("Ano = " + aluAnoResult);
System.out.println("Nome do aluno = " +aluNomeResult );
System.out.println("Nome do curso = " + aluCursoResult);
System.out.println(aluMateriaResult);
getDisplay().setCurrent(get_alerterro1(), get_fGravar());
} else {
String matricula = this.resultUsuario;
String ano = this.aluAnoResult;
String nome = this.aluNomeResult;
String curso = this.aluCursoResult;
String materias = this.aluMateriaResult;
try {
if (this.gravar(matricula,ano,nome,curso,materias)){
getDisplay().setCurrent(get_alertGravados());
}else{
getDisplay().setCurrent(get_alerterro(), get_fGravar());
}
} catch (RecordStoreException ex) {
ex.printStackTrace();
}
// alertResultado = new Alert( " NOTAS ACADÊMICAS: ",
// " \nCodigo Aluno: " + resultUsuario +
// " \nAno: " + aluAnoResult +
// " \nNome do Aluno: " + aluNomeResult +
// " \nCurso: " + aluCursoResult +
// " \n ################################## " +
// " \n " + aluMateriaResult +
// " \n ################################## " , null, AlertType.INFO );
// alertResultado.setTimeout( Alert.FOREVER );
// getDisplay().setCurrent( alertResultado, get_fGravar() );
os.close();
System.out.println( "\n a saida de dados foi fechada");
in.close();
System.out.println( "\n a entrada de dados foi fechada");
http.close();
System.out.println( "\n a conexão http foi fechada");
}
} catch (IOException ex) {
System.out.println( "\n catch resultUsuario");
getDisplay().setCurrent(get_alerterro1(), get_fGravar());
}
}
private boolean gravar(String matricula, String ano, String nome, String curso, String materias)throws RecordStoreException {
RecordStore rec = RecordStore.openRecordStore(DADOS,true);
int id = this.obterID(rec);
if (id != -1){
ByteArrayOutputStream dados;
//array onde ficará o registro
dados = new ByteArrayOutputStream();
// gravação de dados no array
DataOutputStream gravar = new DataOutputStream(dados);
try {
gravar.writeUTF(matricula);
gravar.writeUTF(ano);
gravar.writeUTF(nome);
gravar.writeUTF(curso);
gravar.writeUTF(materias);
gravar.flush();
System.out.println("pegando dados para gravar no rms");
} catch (IOException ex) {
ex.printStackTrace();
rec.closeRecordStore();
System.out.println("dados não gravados no rms");
return false;
}
//gravando o registro no RMS
// setRecord(int recordId, byte[] newData,int offset,
//int numBytes)
//recordId = indice do recorde a ser inserido
//newData = array de bytes a ser inserido no recordStore
//offset = índice da primeira posição de array a ser inserido no RecordStore
//numBytes = tamanho total do array de bytes
rec.setRecord(id,dados.toByteArray(),0,dados.size());
rec.closeRecordStore();
System.out.println("dados Gravados com sucesso no rms");
return true;
}
return false;
}
//param rs O RescordStore de onde tirar o ID
// return = Retorna o ID do primeiro registro disponível no RecodStore ou -1 em caso de erro
private int obterID(RecordStore rs){
// Obtem o primeiro ID de record disponível no RecordStore rs caso não exista
//nenhum Record gravado cria um record contendo ' ' e retorna o ID deste.
if (rs != null){
try {
id=1;
if (rs.getNumRecords() == 0){
byte[] dados = null;
dados = new byte[1];
dados[0] = ' ';
id = rs.addRecord(dados,0,dados.length);
System.out.println("o id foi obtido "+ id);
return id;
}else{
RecordEnumeration re = rs.enumerateRecords(null,null,false);
while (re.hasNextElement()) {
id= re.nextRecordId();
System.out.println("novo id obtido "+ id);
return id;
}
}
}catch (RecordStoreException ex) {
ex.printStackTrace();
System.out.println("erro ao obter id ");
return -1;
}
}
return -1;
}
}
/**
* Obtem os dados armazenados no RMS e transfere para as variáveis
*
*/
public void refreshdados() {
RecordStore rs = null;
try {
try {
rs = RecordStore.openRecordStore(DADOS, true);
RecordEnumeration re = rs.enumerateRecords(null,null,false);
if (rs.getNumRecords() != 0){
ByteArrayInputStream dados = null;
dados = new ByteArrayInputStream( re.nextRecord());
DataInputStream ler = new DataInputStream(dados);
try{
matriculaatual = ler.readUTF();
anoatual = ler.readUTF();
nomeatual = ler.readUTF();
cursoatual = ler.readUTF();
materiaatual = ler.readUTF();
System.out.println("o leitor de dados foi atualizado ");
dados.close();
ler.close();
}catch(IOException ex){
ex.printStackTrace();
}
}
} catch (RecordStoreException ex) {
ex.printStackTrace();
System.out.println("o leitor não foi atualizado ");
}
}finally{
if (rs != null){
try {
rs.closeRecordStore();
} catch (RecordStoreException ex) {
ex.printStackTrace();
}
}
}
}
public void startApp() {
initialize();
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
}