我正在爲我的java應用程序的控制檯工作。我希望能夠在後面用一些數字寫入damageShip到控制檯中。我希望能夠過濾出第一個檢查,如果它等於任何命令,並且如果它是後面的數字並使用這些數字調用函數。我有這兩個類可能是有幫助的。
包裝Windows;過濾掉文本java
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){
}
}
}
問題是什麼? – krokodilko