Пример #1
0
 /**
  * This method initializes jMenuItem
  *
  * @return javax.swing.JMenuItem
  */
 javax.swing.JMenuItem getExitMenuItem() {
   if (exitMenuItem == null) {
     exitMenuItem = new javax.swing.JMenuItem();
     exitMenuItem.setText("Exit");
     exitMenuItem.addActionListener(
         new java.awt.event.ActionListener() {
           public void actionPerformed(java.awt.event.ActionEvent e) {
             System.exit(0);
           }
         });
   }
   return exitMenuItem;
 }
Пример #2
0
  /**
   * This method initializes jMenuItem
   *
   * @return javax.swing.JMenuItem
   */
  javax.swing.JMenuItem getAboutMenuItem() {
    if (aboutMenuItem == null) {
      aboutMenuItem = new javax.swing.JMenuItem();
      aboutMenuItem.setText("About ECJ");
      aboutMenuItem.addActionListener(
          new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent e) {

              if (aboutFrame == null) {

                // construct the frame
                aboutFrame = new JFrame("About ECJ");
                JPanel p = new JPanel(); // 1.3.1 only has borders for JComponents, not Boxes
                p.setBorder(BorderFactory.createEmptyBorder(25, 30, 30, 30));
                Box b = new Box(BoxLayout.Y_AXIS);
                p.add(b, BorderLayout.CENTER);
                aboutFrame.getContentPane().add(p, BorderLayout.CENTER);
                aboutFrame.setResizable(false);
                Font small = new Font("Dialog", 0, 10);

                // start dumping in text
                JLabel j = new JLabel("ECJ");
                j.setFont(new Font("Serif", 0, 36));
                b.add(j);

                j = new JLabel("An Evolutionary Computation System");
                b.add(j);
                j = new JLabel("Version " + Version.version);
                b.add(j);
                JLabel spacer = new JLabel(" ");
                spacer.setFont(new Font("Dialog", 0, 6));
                b.add(spacer);

                j = new JLabel("By " + Version.author);
                b.add(j);

                spacer = new JLabel(" ");
                spacer.setFont(new Font("Dialog", 0, 6));
                b.add(spacer);

                j = new JLabel("Contributors:");
                b.add(j);
                j = new JLabel("     " + Version.contributors);
                b.add(j);
                j = new JLabel("     " + Version.contributors2);
                b.add(j);

                spacer = new JLabel(" ");
                spacer.setFont(new Font("Dialog", 0, 6));
                b.add(spacer);

                // can't figure out why I need a second one...
                spacer = new JLabel(" ");
                spacer.setFont(new Font("Dialog", 0, 6));
                b.add(spacer);

                j = new JLabel("ECJ's homepage is " + Version.authorURL);
                j.setFont(small);
                b.add(j);

                j =
                    new JLabel(
                        "For help, send mail to "
                            + Version.authorEmail0
                            + "@"
                            + Version.authorEmail1);
                j.setFont(small);
                b.add(j);

                j = new JLabel("     " + Version.authorEmail2);
                j.setFont(small);
                b.add(j);

                spacer.setFont(new Font("Dialog", 0, 6));
                b.add(spacer);

                j = new JLabel("Version " + Version.version + " released on " + Version.date + ".");
                j.setFont(small);
                b.add(j);

                String javaVersion = System.getProperties().getProperty("java.version");
                j = new JLabel("Current Java: " + javaVersion);
                j.setFont(small);
                b.add(j);

                j = new JLabel("Minimum Java: " + Version.minimumJavaVersion);
                j.setFont(small);
                b.add(j);

                aboutFrame.pack();
              }

              // if not on screen right now, move to center of screen
              if (!aboutFrame.isVisible()) {

                Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
                d.width -= aboutFrame.getWidth();
                d.height -= aboutFrame.getHeight();
                d.width /= 2;
                d.height /= 2;
                if (d.width < 0) d.width = 0;
                if (d.height < 0) d.height = 0;
                aboutFrame.setLocation(d.width, d.height);
              }

              // show it!
              aboutFrame.setVisible(true);
            }
          });
    }
    return aboutMenuItem;
  }
Пример #3
0
  public NumbrixGUI() throws ParseException { // Board gameBoard) throws ParseException{

    // Board
    this.gameBoard = new Board();

    // Container
    setTitle(TITLE);
    setSize(WIDTH, HEIGHT);
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    // About Frame
    jFrameAbout = new javax.swing.JFrame();
    jFrameAbout.setResizable(false);
    jFrameAbout.setPreferredSize(new Dimension(500, 300));

    jTextAreaAbout = new javax.swing.JTextArea();
    jTextAreaAbout.setBackground(new java.awt.Color(240, 240, 240));
    jTextAreaAbout.setColumns(20);
    jTextAreaAbout.setRows(10);
    jTextAreaAbout.setText(
        "\t\tNumbrix Version 1\n\nClass Project for Artificial Intelligence course.\nUniversity of Florida\nCISE\n\n\n\n\nby Rainer Ledesma\nhttp://www.cise.ufl.edu/~rledesma/\n");
    jTextAreaAbout.setFont(new java.awt.Font("Agency FB", 1, 20)); // NOI18N
    jTextAreaAbout.setEditable(false);
    jTextAreaAbout.setPreferredSize(new Dimension(500, 300));

    javax.swing.GroupLayout jFrameAboutLayout =
        new javax.swing.GroupLayout(jFrameAbout.getContentPane());
    jFrameAbout.getContentPane().setLayout(jFrameAboutLayout);
    jFrameAboutLayout.setHorizontalGroup(
        jFrameAboutLayout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(
                jFrameAboutLayout
                    .createSequentialGroup()
                    .addGap(11, 11, 11)
                    .addComponent(
                        jTextAreaAbout,
                        javax.swing.GroupLayout.PREFERRED_SIZE,
                        javax.swing.GroupLayout.DEFAULT_SIZE,
                        javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
    jFrameAboutLayout.setVerticalGroup(
        jFrameAboutLayout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(
                jFrameAboutLayout
                    .createSequentialGroup()
                    .addGap(0, 16, Short.MAX_VALUE)
                    .addComponent(
                        jTextAreaAbout,
                        javax.swing.GroupLayout.PREFERRED_SIZE,
                        267,
                        javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(0, 17, Short.MAX_VALUE)));
    //

    // Instructions Frame
    jFrameInstructions = new javax.swing.JFrame();
    jFrameInstructions.setResizable(false);
    jFrameInstructions.setPreferredSize(new Dimension(500, 300));

    jTextAreaInstructions = new javax.swing.JTextArea();
    jTextAreaInstructions.setBackground(new java.awt.Color(240, 240, 240));
    jTextAreaInstructions.setColumns(20);
    jTextAreaInstructions.setRows(10);
    jTextAreaInstructions.setText(
        "\t\tNumbrix\n"
            + "The object of Numbrix is to fill the board with sequence of consecutive \n"
            + "numbers from 1 to the maximun cell count. The numbers must fillow a \n"
            + "horizontal or vertical path (no diagonals)\n");
    jTextAreaInstructions.setFont(new java.awt.Font("Agency FB", 1, 20)); // NOI18N
    jTextAreaInstructions.setEditable(false);
    jTextAreaInstructions.setPreferredSize(new Dimension(500, 300));

    javax.swing.GroupLayout jFrameInstructionsLayout =
        new javax.swing.GroupLayout(jFrameInstructions.getContentPane());
    jFrameInstructions.getContentPane().setLayout(jFrameInstructionsLayout);
    jFrameInstructionsLayout.setHorizontalGroup(
        jFrameInstructionsLayout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(
                jFrameInstructionsLayout
                    .createSequentialGroup()
                    .addGap(11, 11, 11)
                    .addComponent(
                        jTextAreaInstructions,
                        javax.swing.GroupLayout.PREFERRED_SIZE,
                        javax.swing.GroupLayout.DEFAULT_SIZE,
                        javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
    jFrameInstructionsLayout.setVerticalGroup(
        jFrameInstructionsLayout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(
                jFrameInstructionsLayout
                    .createSequentialGroup()
                    .addGap(0, 16, Short.MAX_VALUE)
                    .addComponent(
                        jTextAreaInstructions,
                        javax.swing.GroupLayout.PREFERRED_SIZE,
                        267,
                        javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(0, 17, Short.MAX_VALUE)));
    //

    // File Chooser
    jFrameFileChooser = new javax.swing.JFrame();
    jFileChooser = new javax.swing.JFileChooser();
    jFileChooser.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            try {
              jFileChooserActionPerformed(evt);
            } catch (Exception ex) {
              JOptionPane.showMessageDialog(frame, "File Exception");
            }
          }
        });

    javax.swing.GroupLayout jFrameFileChooserLayout =
        new javax.swing.GroupLayout(jFrameFileChooser.getContentPane());
    jFrameFileChooser.getContentPane().setLayout(jFrameFileChooserLayout);
    jFrameFileChooserLayout.setHorizontalGroup(
        jFrameFileChooserLayout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 618, Short.MAX_VALUE)
            .addGroup(
                jFrameFileChooserLayout
                    .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(
                        jFrameFileChooserLayout
                            .createSequentialGroup()
                            .addGap(18, 18, 18)
                            .addComponent(
                                jFileChooser,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                Short.MAX_VALUE)
                            .addGap(18, 18, 18))));
    jFrameFileChooserLayout.setVerticalGroup(
        jFrameFileChooserLayout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 456, Short.MAX_VALUE)
            .addGroup(
                jFrameFileChooserLayout
                    .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(
                        jFrameFileChooserLayout
                            .createSequentialGroup()
                            .addGap(27, 27, 27)
                            .addComponent(
                                jFileChooser,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                Short.MAX_VALUE)
                            .addGap(32, 32, 32))));
    //

    // SidePanel
    jPanelSideBar = new javax.swing.JPanel();
    jButtonRESET = new javax.swing.JButton();
    jButtonSOLVE = new javax.swing.JButton();
    jButtonNEWGAME = new javax.swing.JButton();
    jLabelTIMER = new javax.swing.JLabel();
    jButtonPAUSE = new javax.swing.JButton();

    jButtonRESET.setText("RESET");
    jButtonRESET.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            jButtonRESETActionPerformed(evt);
          }
        });
    jButtonSOLVE.setText("SOLVE");
    jButtonSOLVE.setEnabled(false);
    jButtonSOLVE.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            try {
              jButtonSOLVEActionPerformed(evt);
            } catch (IOException ex) {
              Logger.getLogger(NumbrixGUI.class.getName()).log(Level.SEVERE, null, ex);
            }
          }
        });
    jButtonNEWGAME.setText("NEW GAME");
    jButtonNEWGAME.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            jButtonNEWGAMEActionPerformed(evt);
          }
        });
    jLabelTIMER.setText("TIMER");
    jLabelTIMER.setFont(new java.awt.Font("Agency FB", 1, 18));
    jButtonPAUSE.setText("PAUSE");
    jButtonPAUSE.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            jButtonPAUSEActionPerformed(evt);
          }
        });
    jLabelClock = new javax.swing.JLabel();
    jLabelClock.setFont(new java.awt.Font("Agency FB", 1, 24)); // NOI18N
    jLabelClock.setText("10 : 99 : 60");

    javax.swing.GroupLayout jPanelSideBarLayout = new javax.swing.GroupLayout(jPanelSideBar);
    jPanelSideBar.setLayout(jPanelSideBarLayout);
    jPanelSideBarLayout.setHorizontalGroup(
        jPanelSideBarLayout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(
                jPanelSideBarLayout
                    .createSequentialGroup()
                    .addContainerGap()
                    .addGroup(
                        jPanelSideBarLayout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(
                                jButtonRESET,
                                javax.swing.GroupLayout.Alignment.TRAILING,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                Short.MAX_VALUE)
                            .addComponent(
                                jButtonSOLVE,
                                javax.swing.GroupLayout.Alignment.TRAILING,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                Short.MAX_VALUE)
                            .addComponent(
                                jButtonNEWGAME,
                                javax.swing.GroupLayout.Alignment.TRAILING,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                136,
                                Short.MAX_VALUE)
                            .addComponent(
                                jButtonPAUSE,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                Short.MAX_VALUE)
                            .addGroup(
                                jPanelSideBarLayout
                                    .createSequentialGroup()
                                    .addGroup(
                                        jPanelSideBarLayout
                                            .createParallelGroup(
                                                javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabelTIMER)
                                            .addComponent(
                                                jLabelClock,
                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                97,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGap(0, 0, Short.MAX_VALUE)))
                    .addContainerGap()));
    jPanelSideBarLayout.setVerticalGroup(
        jPanelSideBarLayout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(
                javax.swing.GroupLayout.Alignment.TRAILING,
                jPanelSideBarLayout
                    .createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jLabelTIMER)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(
                        jLabelClock,
                        javax.swing.GroupLayout.PREFERRED_SIZE,
                        32,
                        javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(jButtonPAUSE)
                    .addPreferredGap(
                        javax.swing.LayoutStyle.ComponentPlacement.RELATED, 229, Short.MAX_VALUE)
                    .addComponent(jButtonNEWGAME)
                    .addGap(18, 18, 18)
                    .addComponent(jButtonRESET)
                    .addGap(18, 18, 18)
                    .addComponent(jButtonSOLVE)
                    .addContainerGap()));
    ////////

    // Menu
    jMenuBar1 = new javax.swing.JMenuBar();
    jMenu1 = new javax.swing.JMenu();
    jMenuItemNewGame = new javax.swing.JMenuItem();
    jMenuItemExit = new javax.swing.JMenuItem();
    jMenu2 = new javax.swing.JMenu();
    jMenuItemInstructions = new javax.swing.JMenuItem();
    jMenuItemAbout = new javax.swing.JMenuItem();

    jMenu1.setText("File");
    jMenu2.setText("Edit");

    jMenuItemNewGame.setText("New Game");
    jMenuItemExit.setText("Exit");
    jMenuItemInstructions.setText("Instructions");
    jMenuItemAbout.setText("About Numbrix");

    jMenuBar1.add(jMenu1);
    jMenuBar1.add(jMenu2);
    jMenu1.add(jMenuItemNewGame);
    jMenu1.add(jMenuItemExit);
    jMenu2.add(jMenuItemInstructions);
    jMenu2.add(jMenuItemAbout);

    setJMenuBar(jMenuBar1);

    jMenuItemNewGame.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            jMenuItemNewGameActionPerformed(evt);
          }
        });
    jMenuItemExit.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            jMenuItemExitActionPerformed(evt);
          }
        });
    jMenuItemInstructions.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            jMenuItemInstructionsActionPerformed(evt);
          }
        });
    jMenuItemAbout.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            jMenuItemAboutActionPerformed(evt);
          }
        });
    //

    // SolvedBoardPanel
    jPanelSolvedBoard = new javax.swing.JPanel();
    jPanelSolvedBoard.setBackground(new java.awt.Color(255, 255, 255));

    // Solved Board Frame
    jFrameSolvedBoard = new javax.swing.JFrame();
    jFrameSolvedBoard.setTitle("Numbrix Solution");
    javax.swing.GroupLayout jFrameSolvedBoardLayout =
        new javax.swing.GroupLayout(jFrameSolvedBoard.getContentPane());
    jFrameSolvedBoard.getContentPane().setLayout(jFrameSolvedBoardLayout);
    jFrameSolvedBoardLayout.setHorizontalGroup(
        jFrameSolvedBoardLayout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
            .addGroup(
                jFrameSolvedBoardLayout
                    .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(
                        jPanelSolvedBoard,
                        javax.swing.GroupLayout.Alignment.TRAILING,
                        javax.swing.GroupLayout.DEFAULT_SIZE,
                        400,
                        Short.MAX_VALUE)));
    jFrameSolvedBoardLayout.setVerticalGroup(
        jFrameSolvedBoardLayout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
            .addGroup(
                jFrameSolvedBoardLayout
                    .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(
                        jPanelSolvedBoard,
                        javax.swing.GroupLayout.Alignment.TRAILING,
                        javax.swing.GroupLayout.DEFAULT_SIZE,
                        300,
                        Short.MAX_VALUE)));

    // BoardPanel
    boardPanel = new javax.swing.JPanel();
    boardPanel.setBackground(new java.awt.Color(255, 255, 255));
    // Clock
    gameTimer = new GameTimer(jLabelClock);
    this.gameTimer.start();
    this.gameTimer.run();

    // Initialize
    // init();

    // Container Layout
    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(
                javax.swing.GroupLayout.Alignment.TRAILING,
                layout
                    .createSequentialGroup()
                    .addContainerGap()
                    .addComponent(
                        boardPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 488, Short.MAX_VALUE)
                    .addGap(18, 18, 18)
                    .addComponent(
                        jPanelSideBar,
                        javax.swing.GroupLayout.PREFERRED_SIZE,
                        javax.swing.GroupLayout.DEFAULT_SIZE,
                        javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap()));
    layout.setVerticalGroup(
        layout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(
                javax.swing.GroupLayout.Alignment.TRAILING,
                layout
                    .createSequentialGroup()
                    .addContainerGap()
                    .addGroup(
                        layout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(
                                boardPanel,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                Short.MAX_VALUE)
                            .addComponent(
                                jPanelSideBar,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                Short.MAX_VALUE))
                    .addContainerGap()));
  }