Zombie process (How to finish the game with JFrame?)

I currently have the following code:

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);


}

For some reason, the zombie process remains. I have no idea why.

I will indicate that this is before I pressed the buttons on the start screen. However, if he has not yet reached the home screen, the zombie process has not yet occurred.

So how can I exit the game correctly?

+4
source share
1 answer

Maybe I should post this in a comment, not as an answer, but I don't have enough reputation. Your code is ok, maybe the process you are seeing is from your IDE?

These are my java processes before I run your code:    [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

Then I run the code that creates the process 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]$

, .

+3

Source: https://habr.com/ru/post/1547328/


All Articles