Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
JMine - JChoose.java

JChoose.java

Caricato da:
Scarica il programma completo

  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5.  
  6. /*
  7.  * JChoose.java
  8.  *
  9.  * Created on 24-set-2010, 16.05.07
  10.  */
  11.  
  12. package jmine.graphics;
  13.  
  14. import com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel;
  15. import java.awt.Dimension;
  16. import java.awt.Font;
  17. import java.awt.Toolkit;
  18. import javax.swing.UIManager;
  19. import javax.swing.UnsupportedLookAndFeelException;
  20. import jmine.exceptions.IllegalNumOfMine;
  21.  
  22. /**
  23.  *
  24.  * @author Paolo
  25.  */
  26. public class JChoose extends javax.swing.JFrame {
  27.  
  28.     /** Creates new form JChoose */
  29.     public JChoose() {
  30.         try {
  31.             UIManager.setLookAndFeel(new NimbusLookAndFeel());
  32.         } catch (UnsupportedLookAndFeelException ex) {
  33.         }
  34.         initComponents();
  35.         this.setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/jmine/graphics/images/mina_piccola.png")));
  36.         this.easy.setSelected(true);
  37.     }
  38.  
  39.     /** This method is called from within the constructor to
  40.      * initialize the form.
  41.      * WARNING: Do NOT modify this code. The content of this method is
  42.      * always regenerated by the Form Editor.
  43.      */
  44.     @SuppressWarnings("unchecked")
  45.     // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  46.     private void initComponents() {
  47.  
  48.         group = new javax.swing.ButtonGroup();
  49.         panel = new javax.swing.JPanel();
  50.         mineLabel = new javax.swing.JLabel();
  51.         jMineLabel = new javax.swing.JLabel();
  52.         gameLabel = new javax.swing.JLabel();
  53.         easy = new javax.swing.JRadioButton();
  54.         medium = new javax.swing.JRadioButton();
  55.         hard = new javax.swing.JRadioButton();
  56.         goToGame = new javax.swing.JLabel();
  57.  
  58.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  59.         setTitle("JMine - by Paolo Ricciuti (C)");
  60.         setResizable(false);
  61.  
  62.         mineLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jmine/graphics/images/mina.png"))); // NOI18N
  63.  
  64.         jMineLabel.setFont(new java.awt.Font("Tempus Sans ITC", 0, 36));
  65.         jMineLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
  66.         jMineLabel.setText("JMine");
  67.  
  68.         gameLabel.setFont(new java.awt.Font("Tempus Sans ITC", 0, 14));
  69.         gameLabel.setText("<html>Scopo del gioco è quello di evitare tutte le mine presenti sulla griglia. Ad aiutarvi nell'impresa alcuni numeri che indicano le mine adiacenti a quella cella!</html>");
  70.  
  71.         group.add(easy);
  72.         easy.setText("Facile (9x9 - 10 mine)");
  73.  
  74.         group.add(medium);
  75.         medium.setText("Medio (16x16 - 40 mine)");
  76.  
  77.         group.add(hard);
  78.         hard.setText("Difficile (16x30 - 99 mine)");
  79.  
  80.         goToGame.setFont(new java.awt.Font("Tempus Sans ITC", 0, 24));
  81.         goToGame.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
  82.         goToGame.setText("Gioca");
  83.         goToGame.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
  84.         goToGame.addMouseListener(new java.awt.event.MouseAdapter() {
  85.             public void mouseClicked(java.awt.event.MouseEvent evt) {
  86.                 goToGameMouseClicked(evt);
  87.             }
  88.             public void mouseEntered(java.awt.event.MouseEvent evt) {
  89.                 goToGameMouseEntered(evt);
  90.             }
  91.             public void mouseExited(java.awt.event.MouseEvent evt) {
  92.                 goToGameMouseExited(evt);
  93.             }
  94.         });
  95.  
  96.         javax.swing.GroupLayout panelLayout = new javax.swing.GroupLayout(panel);
  97.         panel.setLayout(panelLayout);
  98.         panelLayout.setHorizontalGroup(
  99.             panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  100.             .addGroup(panelLayout.createSequentialGroup()
  101.                 .addContainerGap()
  102.                 .addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  103.                     .addGroup(panelLayout.createSequentialGroup()
  104.                         .addComponent(gameLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 208, javax.swing.GroupLayout.PREFERRED_SIZE)
  105.                         .addGap(18, 18, 18)
  106.                         .addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  107.                             .addGroup(panelLayout.createSequentialGroup()
  108.                                 .addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  109.                                     .addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  110.                                         .addComponent(goToGame, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  111.                                         .addComponent(easy))
  112.                                     .addComponent(medium))
  113.                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 23, Short.MAX_VALUE))
  114.                             .addComponent(hard, javax.swing.GroupLayout.DEFAULT_SIZE, 164, Short.MAX_VALUE)))
  115.                     .addGroup(panelLayout.createSequentialGroup()
  116.                         .addComponent(mineLabel)
  117.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  118.                         .addComponent(jMineLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 280, Short.MAX_VALUE)))
  119.                 .addContainerGap())
  120.         );
  121.         panelLayout.setVerticalGroup(
  122.             panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  123.             .addGroup(panelLayout.createSequentialGroup()
  124.                 .addContainerGap()
  125.                 .addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
  126.                     .addComponent(jMineLabel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  127.                     .addComponent(mineLabel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  128.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  129.                 .addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  130.                     .addGroup(panelLayout.createSequentialGroup()
  131.                         .addComponent(easy)
  132.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  133.                         .addComponent(medium)
  134.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  135.                         .addComponent(hard)
  136.                         .addGap(21, 21, 21)
  137.                         .addComponent(goToGame, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE))
  138.                     .addComponent(gameLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 167, Short.MAX_VALUE))
  139.                 .addContainerGap())
  140.         );
  141.  
  142.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  143.         getContentPane().setLayout(layout);
  144.         layout.setHorizontalGroup(
  145.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  146.             .addComponent(panel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  147.         );
  148.         layout.setVerticalGroup(
  149.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  150.             .addComponent(panel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  151.         );
  152.  
  153.         java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
  154.         setBounds((screenSize.width-416)/2, (screenSize.height-338)/2, 416, 338);
  155.     }// </editor-fold>//GEN-END:initComponents
  156.  
  157.     private void goToGameMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_goToGameMouseClicked
  158.         int width=0;
  159.         int height=0;
  160.         int mine=0;
  161.         if(this.easy.isSelected()){
  162.             width=9;
  163.             height=9;
  164.             mine=10;
  165.         }else if(this.medium.isSelected()){
  166.             width=16;
  167.             height=16;
  168.             mine=40;
  169.         }else if(this.hard.isSelected()){
  170.             width=30;
  171.             height=16;
  172.             mine=99;
  173.         }
  174.         JMine jmine=null;
  175.         try {
  176.             jmine = new JMine(width, height, mine);
  177.         } catch (IllegalNumOfMine ex) {
  178.         }
  179.         jmine.setSize((width*30)+60, (height*30)+100);
  180.         Dimension screen= Toolkit.getDefaultToolkit().getScreenSize();
  181.         int x=(screen.width-jmine.getSize().width)/2;
  182.         int y=(screen.height-jmine.getSize().height)/2;
  183.         jmine.setLocation(x, y);
  184.         jmine.setVisible(true);
  185.         this.setVisible(false);
  186.     }//GEN-LAST:event_goToGameMouseClicked
  187.  
  188.     private void goToGameMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_goToGameMouseEntered
  189.         this.goToGame.setFont(new Font(this.goToGame.getFont().getFontName(), Font.BOLD, this.goToGame.getFont().getSize()+10));
  190.     }//GEN-LAST:event_goToGameMouseEntered
  191.  
  192.     private void goToGameMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_goToGameMouseExited
  193.         this.goToGame.setFont(new Font(this.goToGame.getFont().getFontName(), 0, this.goToGame.getFont().getSize()-10));
  194.     }//GEN-LAST:event_goToGameMouseExited
  195.  
  196.     /**
  197.     * @param args the command line arguments
  198.     */
  199.     public static void main(String args[]) {
  200.         java.awt.EventQueue.invokeLater(new Runnable() {
  201.             public void run() {
  202.                 new JChoose().setVisible(true);
  203.             }
  204.         });
  205.     }
  206.  
  207.     // Variables declaration - do not modify//GEN-BEGIN:variables
  208.     private javax.swing.JRadioButton easy;
  209.     private javax.swing.JLabel gameLabel;
  210.     private javax.swing.JLabel goToGame;
  211.     private javax.swing.ButtonGroup group;
  212.     private javax.swing.JRadioButton hard;
  213.     private javax.swing.JLabel jMineLabel;
  214.     private javax.swing.JRadioButton medium;
  215.     private javax.swing.JLabel mineLabel;
  216.     private javax.swing.JPanel panel;
  217.     // End of variables declaration//GEN-END:variables
  218.  
  219. }