如何用Java中的表替换具有特定索引的文本?

时间:2016-02-02 19:23:01

标签: java

我目前有这个学校项目管理商店,我真的不知道如何更换。变量名目前是我的母语。这是编辑部分:

public static void Modify() { 
    String mod=JOptionPane.showInputDialog("Input the id code of the seller you want to modify: "); 
    int mod1 = new Integer(mod).intValue(); 
    while (i == mod1){ 
        Store.setName(getName()); 
        Store.setSurname(surname); 
        Store.setId(getID()); 
        Store x=new Store(getName(), surname, getID()); 
        Info[i]=x; 
        System.out.println("Registered seller "+ getName() +" "+ surname);
    }
}

我也这样做是为了搜索它并且不起作用:

public static void Search(){
    String code1= JOptionPane.showInputDialog("Input the code of the seller you are searching for: ");
    int code = new Integer(code1).intValue();
    String answer = Store.getName();
    for (int i=0; i<numri;i++){
        if (Store.getID()==code)
        {
            answer=Store.getName();
            System.out.println("The seller you are looking for is: " + answer);
        }
        else 
            System.out.println("The seller you are looking for cannot be found");
        break;
    }
}

它只打印最后一个。

以下是整个代码:

import javax.swing.JOptionPane;

public class Store{
    private static String name;
    public static String surname;
    private static int ID;

  static String nr = JOptionPane.showInputDialog("Input the number of sellers you want to register: ");
static int number=new Integer(nr).intValue();

 static Store[] Info = new Store[number];
private static int i;
//Input of info
public Store(String name, String surname, int id) {

    }
public static void setName(String namee){
    String e = JOptionPane.showInputDialog("Write the sellers name: ");
    setname(e);
}
public static void setSurname(String surnamee){
    String m = JOptionPane.showInputDialog("Write the sellers surname: ");
    surname=m;
}
public static void setId(int ID){
    String ID1 = JOptionPane.showInputDialog("Input the id code of the seller: ");
    int Id=new Integer(ID1).intValue();
    ID=Id;
}

public static void FillTable() //Registering sellers
{for (int i =0; i<number; i++){
    Store.setName(getName());
    Store.setSurname(surname);
    Store.setId(getID());
    Store x=new Store(getName(), surname, getID());
    Info[i]=x;
    System.out.println("Registered seller "+ getname() +" "+ surname);}}

//Search
public static void Search(){
    String code1= JOptionPane.showInputDialog("Write the code of the seller you want to find: ");
    int code = new Integer(code1).intValue();
    String answer = Store.getName();
    for (int i=0; i<number;i++){
        if (Store.getID()==code)
        {answer=Store.getname();
        System.out.println("The seller you are searching for is: " + answer);
        break;
        }
        else System.out.println("The seller cannot be found.");
        break;
        }


}

// Modifying the sellers
public static void Modify(){
String mod=JOptionPane.showInputDialog("Write the code of the seller you want to modify: ");
 int mod1 = new Integer(mod).intValue();
 while (i == mod1){
     Store.setName(getname());
        Store.setSurname(surname);
        Store.setId(getID());
        Store x=new Store(getName(), surname, getID());
        Info[i]=x;
        System.out.println("Edited seller "+ getName() +" "+ surname);}}




private static void remove(int f) {
    // TODO Auto-generated method stub

}
public static void main(String[] args) {
    Store.FillTable();
    Store.Search();
    Store.Modify();
    }
public static int getID() {
    return ID;
}
public static void setID(int iD) {
    ID = iD;
}
public static String getName() {
    return name;
}
public static void setName(String name) {
    Store.name = name;
}

}

1 个答案:

答案 0 :(得分:0)

字符串的Java国际化可以通过ResourceBundle类完成。它使用起来的简单示例:

public static void main(String[] args) {
    ResourceBundle bundle = ResourceBundle.getBundle("ApplicationMessages", Locale.FRANCE);
    System.out.println(bundle.getString("CountryName"));
    System.out.println(bundle.getString("CurrencyCode"));
}

这里有关于如何开始使用它的简短tutorial,您可以通过Google了解更多示例。它易于使用,但要小心 - 在事故中也很容易为一个场所留下一个字符串。