过滤掉文本java

时间:2013-11-01 07:13:14

标签: java text filter parentheses

我正在为我的java应用程序的控制台工作。我希望能够将damageShip写入控制台,并在其后面添加一些数字。我希望能够过滤掉第一次检查它是否等于任何命令,如果它是采用它后面的数字并使用这些数字调用函数。我有这两个类可能会有所帮助     包Windows;

import javax.swing.*;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class ConsoleWindow {
static JFrame window = new JFrame("Console");
static JPanel panel = new JPanel(new GridLayout(1,2,5,5));
static JPanel panel2 = new JPanel(new GridLayout(1,1,5,5));
static JTextField cmd = new JTextField(50);
static JButton execute = new JButton("GO");
public static void openWindow(){
    panel.add(cmd);
    panel2.add(execute);
    window.setLayout(new FlowLayout());
    window.add(panel);
    window.add(panel2);
    window.pack();
    execute.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent arg0) {
            // TODO Auto-generated method stub

        }

    });
    window.setVisible(true);
}
}


public class Stats {
public static int shipShields = 1000;
public static int crewNum = 100;
public static int shipHealth = 1000;
public static void killCrew(int amount){
    System.out.println("Killing "+amount+" crew");
}
public static void damageShip(int amount){
    System.out.println("Damaging ship for "+amount+" damage");
    if(shipShields > 0 && amount < shipShields){

    }

}
}

1 个答案:

答案 0 :(得分:0)

检查commons-cli它完全符合您的要求,内部正在针对预先定义的选项解析String[]