⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 addname.java

📁 深海大战手机游戏
💻 JAVA
字号:
package shipwar;

import javax.microedition.lcdui.*;
import javax.microedition.rms.*;

public class AddName extends TextBox implements CommandListener{
    private Command Addname=new Command("添加",Command.SCREEN,1);
    private Command Return=new Command("返回",Command.EXIT,5);
    private Displayable upinstance;
    private int id,score;
    private boolean exist=false;
    public AddName(int score,Displayable instance,boolean exist){
        super("添加记录名","",10,TextField.ANY);
        this.score=score;
        this.upinstance=instance;
        this.exist=exist;
        this.addCommand(Addname);
        this.addCommand(Return);
        this.setCommandListener(this);
    }

    public AddName(int id,int score,Displayable instance,boolean exist){
        super("添加记录名","",10,TextField.ANY);
        this.upinstance=instance;
        this.id=id;
        this.score=score;
        this.exist=exist;
        this.addCommand(Addname);
        this.addCommand(Return);
        this.setCommandListener(this);
    }

    public void commandAction(Command c,Displayable d){
        if(c==Return)
            Display.getDisplay(shipwarMIDlet.shipwarmidlet).setCurrent(upinstance);
        else if(c==Addname){
            if(this.getString().equals("")){
                Alert a=new Alert("提示信息");
                a.setString("记录名不能为空");
                a.setTimeout(2000);
                Display.getDisplay(shipwarMIDlet.shipwarmidlet).setCurrent(a);
            }else{
                StringDeal stringdeal=new StringDeal();
                stringdeal.setname(this.getString());
                stringdeal.setcount(score);
                if(exist==false){
                    try{
                        byte[] rec=stringdeal.serialize();
                        MainMenu.rs.addRecord(rec,0,rec.length);
                        Alert a=new Alert("提示信息");
                        a.setString("已添加");
                        a.setTimeout(2000);
                        Display.getDisplay(shipwarMIDlet.shipwarmidlet).setCurrent(a,upinstance);
                    }catch(Exception e){
                        System.out.println("解析出错");
                    }
                }else{
                    try{
                        byte[] rec=stringdeal.serialize();
                        MainMenu.rs.setRecord(id,rec,0,rec.length);
                        Alert a=new Alert("提示信息");
                        a.setString("已添加");
                        a.setTimeout(2000);
                        Display.getDisplay(shipwarMIDlet.shipwarmidlet).setCurrent(a,upinstance);
                    }catch(Exception e){
                        System.out.println("解析出错");
                    }
                }
            }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -