我目前有以下代码:
package Joehot200;
//Import pure java junk here - No libraries.
public class Main extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
private JPanel contentPane;
/**
* Launch the application.
*/
static Main frame = null;
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
frame = new Main();
frame.setVisible(true);
frame.setTitle("Privateers");
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Main() {
setExtendedState(JFrame.MAXIMIZED_BOTH);
JMenuBar menuBar = new JMenuBar();
setJMenuBar(menuBar);
final JButton btnEnterBattlefield = new JButton("Enter battlefield!");
btnEnterBattlefield.setForeground(Color.red);
//btnEnterBattlefield.setBackground(Color.green);
//btnEnterBattlefield.setOpaque(true);
menuBar.add(btnEnterBattlefield);
btnEnterBattlefield.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
//For the sake of this code example, this does nothing as the error happens even if I do not click the button.
}
});
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
FlowLayout flowLayout = (FlowLayout) contentPane.getLayout();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
}
由于某种原因离开了僵尸进程。我不明白为什么。
我会指出这是在我按下开始屏幕上的任何按钮之前。但是,如果尚未进入开始屏幕,则僵尸进程尚未发生。
那么,我该如何正确退出游戏?
答案 0 :(得分:3)
也许我应该在评论中发布这个,不是作为答案,但我没有声誉。 您的代码没问题,可能是您从IDE中看到的进程?
这是我运行代码之前的java进程:
[victor@aluminio:~/Help/src]$ps -Al | grep java
0 S 118 2651 1 0 80 0 - 169381 ? ? 00:00:24 java
0 S 1000 8151 8148 6 80 0 - 807368 - ? 00:06:18 java
0 S 1000 9047 9028 15 80 0 - 437349 - pts/1 00:07:43 java
然后我运行代码,创建10217进程:
[victor@aluminio:~/Help/src]$java Main &
[1] 10217
[victor@aluminio:~/Help/src]$ps -Al | grep java
0 S 118 2651 1 0 80 0 - 169381 ? ? 00:00:24 java
0 S 1000 8151 8148 6 80 0 - 807368 - ? 00:06:19 java
0 S 1000 9047 9028 15 80 0 - 437349 - pts/1 00:07:43 java
0 S 1000 10217 7232 5 80 0 - 498657 - pts/0 00:00:00 java
然后我关闭窗口,并运行此检查:
[victor@aluminio:~/Help/src]$ps -Al | grep java
0 S 118 2651 1 0 80 0 - 169381 ? ? 00:00:24 java
0 S 1000 8151 8148 6 80 0 - 807368 - ? 00:06:21 java
0 S 1000 9047 9028 14 80 0 - 437349 - pts/1 00:07:44 java
[1]+ Done java Main
[victor@aluminio:~/Help/src]$
该过程按预期完成。