?? micropocha.java
字號:
/*
* MicroPocha.java
*
* Created on 3 de junio de 2005, 15:31
*/
package telefono;
import java.io.IOException;
import java.util.Calendar;
import java.util.NoSuchElementException;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
/**
*
* @author Enrique Vicent Ramis
*/
public class MicroPocha extends MIDlet implements javax.microedition.lcdui.CommandListener
{
private Partida partida=null;
private static Almacen almacen=null;
/** Creates a new instance of MicroPocha */
public MicroPocha()
{
almacen = new telefono.almacen.AlmacenMicropocha(this);
}
public static Almacen getAlmacen()
{
return almacen;
}
private Form crearPartida;//GEN-BEGIN:MVDFields
private List menuEntrada;
private Alert about;
private ChoiceGroup tipoJuego;
private TextField textField1;
private TextField textField2;
private TextField textField3;
private TextField textField4;
private TextField textField5;
private Command cancelCommand1;
private Command irATablero;
private Alert noImplementado;
private Form salida;
private Command exitCommand1;
private Command cancelCommand2;
private Command exitCommand3;
private telefono.Tablero tablero;
private Command pantallaGrafico;
private Command SalirDeTablero;
private telefono.Grafico grafico;
private Command backCommand1;
private Image image1;
private Image image2;
private ImageItem imageItem2;
private StringItem stringItem1;
private StringItem stringItem2;
private Command itemCommand1;
private List cargarPartida;
private Command screenCommand1;
private Command borrarRms1;
private Command okCommand1;
private Command borrarRms;
private Command GuardarComoCommand;
private Form guardarComo;
private StringItem stringItem3;
private TextField guardaComoTextField;
private Command okCommand2;
private Command cancelCommand4;
private Image image3;
private ImageItem imageItem3;
private Command backCommand2;
private Command backCommand3;
private Command cancelCarga;
private Command reset;
private Command screenCommand3;//GEN-END:MVDFields
//GEN-LINE:MVDMethods
/** This method initializes UI of the application.//GEN-BEGIN:MVDInitBegin
*/
private void initialize() {//GEN-END:MVDInitBegin
// Insert pre-init code here
getDisplay().setCurrent(get_menuEntrada());//GEN-LINE:MVDInitInit
// Insert post-init code here
}//GEN-LINE:MVDInitEnd
/**
* 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
/** 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 == menuEntrada) {//GEN-BEGIN:MVDCABody
if (command == menuEntrada.SELECT_COMMAND) {
switch (get_menuEntrada().getSelectedIndex()) {
case 0://GEN-END:MVDCABody
// Insert pre-action code here
getDisplay().setCurrent(get_crearPartida());//GEN-LINE:MVDCAAction6
// Insert post-action code here
break;//GEN-BEGIN:MVDCACase6
case 2://GEN-END:MVDCACase6
// Insert pre-action code here
getDisplay().setCurrent(get_about(), get_menuEntrada());//GEN-LINE:MVDCAAction8
// Insert post-action code here
break;//GEN-BEGIN:MVDCACase8
case 3://GEN-END:MVDCACase8
// Insert pre-action code here
exitMIDlet();//GEN-LINE:MVDCAAction25
// Insert post-action code here
break;//GEN-BEGIN:MVDCACase25
case 1://GEN-END:MVDCACase25
// Insert pre-action code here
//reinicializamos, siempre
cargarPartida=null;
getDisplay().setCurrent(get_cargarPartida());//GEN-LINE:MVDCAAction72
// Insert post-action code here
break;//GEN-BEGIN:MVDCACase72
}
}
} else if (displayable == grafico) {
if (command == backCommand1) {//GEN-END:MVDCACase72
// Insert pre-action code here
getDisplay().setCurrent(get_tablero());//GEN-LINE:MVDCAAction39
// Insert post-action code here
}//GEN-BEGIN:MVDCACase39
} else if (displayable == crearPartida) {
if (command == cancelCommand1) {//GEN-END:MVDCACase39
// Insert pre-action code here
getDisplay().setCurrent(get_menuEntrada());//GEN-LINE:MVDCAAction20
// Insert post-action code here
} else if (command == irATablero) {//GEN-LINE:MVDCACase20
creaPartida();
getDisplay().setCurrent(get_tablero());//GEN-LINE:MVDCAAction22
// Insert post-action code here
}//GEN-BEGIN:MVDCACase22
} else if (displayable == salida) {
if (command == cancelCommand2) {//GEN-END:MVDCACase22
// Insert pre-action code here
getDisplay().setCurrent(get_tablero());//GEN-LINE:MVDCAAction30
// Insert post-action code here
} else if (command == exitCommand1) {//GEN-LINE:MVDCACase30
// Insert pre-action code here
exitMIDlet();//GEN-LINE:MVDCAAction28
// Insert post-action code here
} else if (command == itemCommand1) {//GEN-LINE:MVDCACase28
partida.reiniciar();
get_tablero().reiniciar();
getDisplay().setCurrent(get_tablero());//GEN-LINE:MVDCAAction47
// Insert post-action code here
} else if (command == reset) {//GEN-LINE:MVDCACase47
// Insert pre-action code here
getDisplay().setCurrent(get_menuEntrada());//GEN-LINE:MVDCAAction80
// Insert post-action code here
}//GEN-BEGIN:MVDCACase80
} else if (displayable == cargarPartida) {
if (command == okCommand1) {//GEN-END:MVDCACase80
int seleccionado=cargarPartida.getSelectedIndex();
if(seleccionado!=-1)
{
String objetivo=cargarPartida.getString(seleccionado);
try
{
String xml=almacen.cargar(objetivo);
this.fromXml(xml);
getDisplay().setCurrent(get_tablero());//GEN-LINE:MVDCAAction55
}
catch (NoSuchElementException ex)
{
ex.printStackTrace();
}
catch (IOException ex)
{
ex.printStackTrace();
}
catch (XmlPullParserException ex)
{
ex.printStackTrace();
}
}//si seleccionado
} else if (command == borrarRms) {//GEN-LINE:MVDCACase55
int seleccionado=cargarPartida.getSelectedIndex();
if(seleccionado!=-1)
{
String objetivo=cargarPartida.getString(seleccionado);
try
{
almacen.borrar(objetivo);
cargarPartida.delete(seleccionado);
}
catch (NoSuchElementException ex)
{
ex.printStackTrace();
}
catch (IOException ex)
{
ex.printStackTrace();
}
}
// Do nothing//GEN-LINE:MVDCAAction53
// Insert post-action code here
} else if (command == cancelCarga) {//GEN-LINE:MVDCACase53
// Insert pre-action code here
getDisplay().setCurrent(get_menuEntrada());//GEN-LINE:MVDCAAction78
// Insert post-action code here
}//GEN-BEGIN:MVDCACase78
} else if (displayable == guardarComo) {
if (command == cancelCommand4) {//GEN-END:MVDCACase78
// Insert pre-action code here
getDisplay().setCurrent(get_tablero());//GEN-LINE:MVDCAAction68
// Insert post-action code here
} else if (command == okCommand2) {//GEN-LINE:MVDCACase68
String nombre=guardaComoTextField.getString();
try
{
almacen.guardar(nombre);
}
catch (IOException ex)
{
ex.printStackTrace();
}
getDisplay().setCurrent(get_tablero());//GEN-LINE:MVDCAAction66
// Insert post-action code here
}//GEN-BEGIN:MVDCACase66
} else if (displayable == tablero) {
if (command == pantallaGrafico) {//GEN-END:MVDCACase66
// Insert pre-action code here
getDisplay().setCurrent(get_grafico());//GEN-LINE:MVDCAAction34
// Insert post-action code here
} else if (command == GuardarComoCommand) {//GEN-LINE:MVDCACase34
// Insert pre-action code here
getDisplay().setCurrent(get_guardarComo());//GEN-LINE:MVDCAAction61
// Insert post-action code here
} else if (command == SalirDeTablero) {//GEN-LINE:MVDCACase61
// Insert pre-action code here
getDisplay().setCurrent(get_salida());//GEN-LINE:MVDCAAction36
// Insert post-action code here
}//GEN-BEGIN:MVDCACase36
}//GEN-END:MVDCACase36
// Insert global post-action code here
}//GEN-LINE:MVDCAEnd
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -