我正在为我的 java 应用程序开发控制台。我希望能够将damageShip 写入控制台,并在其后添加一些数字。我希望能够过滤掉第一个检查它是否等于任何命令,以及它是否采用它后面的数字并使用这些数字调用一个函数。我有这两门课可能会有所帮助。
打包窗口;
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){
}
}
}