vendredi 22 janvier 2016

How do I do JPanel if statments

I am trying to make a panel to open up programs that i make. Right now the panel is suppose to pop up and have a selection of programs and you are suppose to choose one and hit "Start Game". I need to learn how to JPanel if statements if i want to do this.

I don't know how to make this if statement work for the jPanel. I have tried looking it up but i seem to not be able to find anything and when I start up the program the panel does not even pop up.

package games;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

public class Games extends JPanel {
    private JComboBox Game;
    private JButton start;





    public static void main (String[] args) {
        JFrame frame = new JFrame ("Games");
        frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add (new Games());
        frame.pack();
        frame.setVisible (true);

    }
    public Games() {

        //construct preComponents
        String[] GameItems = {"Select Game", "PokeFight", "PokeFightOnline", "PokeFightServer"};

        //construct components
        Game = new JComboBox (GameItems);
        start = new JButton ("Start Game");

        //adjust size and set layout
        setPreferredSize (new Dimension (468, 234));
        setLayout (null);

        //add components
        add (Game);
        add (start);

        //set component bounds (only needed by Absolute Positioning)
        Game.setBounds (135, 80, 205, 30);
        start.setBounds (180, 190, 100, 25);
//        IfGame();

                 if (Game.equals("PokeFight") && start.equals("StartGame")){
                         System.out.println("TRUE");
                 }
                
        }
        
        
    }

Aucun commentaire:

Enregistrer un commentaire