Quiz)
Quiz)
Quiz)
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to
change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this
template
*/
package buscaminas;
/**
*
* @author Felipe
*/
import buscaminas.cuadro;
import java.awt.Color;
import java.awt.PopupMenu;
import java.awt.event.ActionEvent;
public class VentanaPrincipal extends javax.swing.JFrame implements
ActionsLiatenner{
int contadorMinas= 0;
int numeroCuadros= 0;
private PopupMenu temp;
private int contador;
/**
* Creates new form VentanaPrincipal
*/
public VentanaPrincipal() {
initComponents();
}
public void actionPerformed (ActionEvent e)
{
cuadro temp2 = (cuadro) e.getSource();
if ( temp2.estaMinando());
{
javax.swing.JOptionPane.showMessageDialog(this, " le diste a una mina
perdiste" );
this.contador =0;
}
{
temp2.setBackground(Color.GREEN);
contador++;
if ((numeroCuadros-contadorMinas)== contador)
javax.swing.JOptionPane.showMessageDialog(this, " GANASTE " );
}
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setText("filas");
jLabel2.setText("columnas");
filas.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
filasActionPerformed(evt);
}
});
jButton1.setText("iniciar ");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(18, 18, 18)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 45,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED
)
.addComponent(filas, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(103, 103, 103)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 53,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(columnas, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED
, 36, Short.MAX_VALUE)
.addComponent(jButton1)
.addGap(32, 32, 32))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(25, 25, 25)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout
.Alignment.BASELINE)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE,
24, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE,
24, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(filas, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(columnas, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton1))
.addContainerGap(51, Short.MAX_VALUE))
);
panel_juegoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 0, Short.MAX_VALUE)
);
panel_juegoLayout.setVerticalGroup(
panel_juegoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 215, Short.MAX_VALUE)
);
pack();
}// </editor-fold>
private void filasActionPerformed(java.awt.event.ActionEvent evt) {
iniciar ();
this.paintAll(this.getGraphics());
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code
(optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the
default look and feel.
* For details see
http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info :
javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(VentanaPrincipal.class.getName()).log(java.util.
logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(VentanaPrincipal.class.getName()).log(java.util.
logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(VentanaPrincipal.class.getName()).log(java.util.
logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(VentanaPrincipal.class.getName()).log(java.util.
logging.Level.SEVERE, null, ex);
}
//</editor-fold>
this.panel_juego.setLayout(new java.awt.GridLayout(nfilas,ncol));
this.numeroCuadros= nfilas*ncol;
this.contadorMinas=0;
for ( int i=0; i<nfilas; i++)
{
for ( int j= 0; j<ncol; j++);
{
cuadro temp = new cuadro ();
temp.addActionListenner(this);
if (temp.estaMinando());
this.contadorMinas++;
temp.setvisible(true);
this.panel_juego.add(this.temp);
}
}
}
public ActionEven() {
}
}
}