Fuente de señal multicontacto
importar java.awt.container;
importar java.awt.font;
importar java.awt.gridlayout;
Importar evento de acción Java .
Importar evento de acción Java . >
Importar evento Java.awt.
Importar javax. p>Importar javax.swing.jframe;
Importar javax.swing.jlabel;
Importar javax.swing.jmenu;
Importar javax.swing.jmenubar ;
Importar javax.swing.jmenuitem;
Importar javax.swing.jpanel;
Importar javax.swing.timer;
La clase pública ScanLei1 extiende JFrame para implementar ActionListener{
private static final long serialVersionUID = 1L;
Contenedor privado contentPane
Btn JButton privado
JButton privado[]btns;
JLabel privado b 1;
JLabel privado b2
JLabel privado b3
Temporizador privado
fila int privada = 9;
int privada col = 9;
int privada bon = 10; ]a;
Int privado b;
Int privado []a 1;
JPanel privado p, p1, p2, P3; p>Escaneo público 1 (título de cadena){
Super(título);
panel de contenido = getContentPane();
setSize(297, 377);
this.setBounds(400, 100, 400, 500);
setDefaultCloseOperation(JFrame.
EXIT _ ON _ CLOSE);
timer =new Timer(1000, (escucha de acción)this);
a = new int[fila 2][col 2]; p>
p>
init GUI();
}
public void initGUI(){
P3 = nuevo JPanel();
b = bon
JMenuBar menuBar = nuevo JMenuBar();
JMenu menú 1 = nuevo JMenu(" juego ");
jmenu 2 = nuevo jmenu(" ayuda ");
j menuitem mi 1 = nuevo j menuitem(" primario ");
JMenuItem mi2 = nuevo JMenuItem(" intermedio ") ;
JMenuItem mi3 = new JMenuItem(" avanzado ");
mi 1 . addactionlistener(this
menu 1 .
mi2 . addactionlistener(este);
menú 1 . menú 1 . agregar( mi3);
barra de menú. agregar(menú 1);
barra de menú. bar);
barra de menú. p>
b 1 = new JLabel(bon " ");
a 1 = new int[bon];
BTN = nuevo JButton(" inicio ");
BTN addactionlistener(this
B2 = nuevo JLabel(" 0 "); = new JLabel(" ");
btns = new JButton[row * col];
p = new JPanel();
p . (nuevo BorderLayout());
panel de contenido. add(p);
p.add(p3, BorderLayout. Norte);
//combo = new jcombobox(new object[]{ "primary", "intermediate", "advanced" });
//Agregar monitoreo
/* combo . additem oyente(nuevo elemento oyente(){
}});*/
p 1 = nuevo JPanel();
//En esa posición
//((diseño de flujo)p 1. obtener diseño()). setAlignment(FlowLayout.
Derecha);
p 1. agregar(b 1);
p 1. agregar(BTN);
p 1. agregar(B2);
p 1. add(B3);
p.add(p3, BorderLayout. Norte);
p.add(p1, BorderLayout. Centro);
p2 = new JPanel();
p2.setLayout(new GridLayout(fila, columna, 0, 0));
for(int I = 0; i lt fila * columna; i ){
btns[I]= nuevo JButton(" ");
btns[i]. setMargin(new Insets(0, 0, 0, 0));
btns[i]. setFont(newFont(null,Font.Bold,25));
btns[i]. addActionListener(este);
btns[i]. addmouse oyente(nuevo evento de mouse normore());
p2 add(btns[I]);
}
contentPane.add(p, BorderLayout . Norte);
contentPane.add(p2, BorderLayout. Center
}
Public void go(){
; set visible(true);
}
Public static void main(String[] args){
Nuevo ScanLei1("Buscaminas"). go();
}
public void out(int[][] a, JButton[] btns, ActionEvent e, int i, int x, int y){ p>
int p = 1;
if(a[x][y]==0){
a[x][y]= 10; p>p>
btns[i]. establecer habilitado(falso); //33
for(int l = y-1; l lt= y 1; l ){
int m = x-1-1;
int n = l-1;
p = 1;
salida . >
if (n gt-1 amp; ampn ltcol amp ampm gt-1 amp; ampm lt fila)
{
for(int q = 0; q lt fila) ) con fila. ampp = = 1; q ){//col- gt; fila;
if((n col * q) gt; = (m * col)) amp((n). col * q) lt; (m 1)*col)){
if(a[x-1][l]!= 0 amperios ampa[x-1][l]!=10) {
btns[n col*q]. setText(a[x-1][l] " ");
a[x-1][l]= 10;
btns[n col*q].
establecer habilitado(falso);
}
else if(a[x-1][l]==0){
//a[x -1][l]= 10;
btns[n col*q]. establecer habilitado(falso);
out(a, btns, e, n col*q, x-1, l////55////
a); [x-1][l]= 10;
btns[n col*q]. establecer habilitado(falso);
}
p = 0;
}
}
}
p = 1;
m = x;
si (n gt-1 amp; ampn ltcol amp ampm gt-1 amp; ampm ltcol) p>
{
for(int q = 0; q lt clasifica y clasifica. ampp = = 1; q){
if((n col * q) gt ;=(m * col)) amp; amp((n col * q) lt; (m 1)*col)){
if(a[x 1][l]!= 0 amp ampa[x 1][l]! =10){
btns[n col*q]. setText(a[x 1][l] " ");
a[x 1][l]= 10;
btns[n col*q]. establecer habilitado(falso);
}
else if(a[x 1][l]==0){
out(a, btns, e, n col*q, x 1, l); ///55////
a[x 1][l]= 10;
btns[n col *q]. establecer habilitado(falso);
}
p = 0;
}
}
}
}
int m = x-1;
int n = y-1-1
p = 1;
p>
p>
if (n gt-1 amp; ampn ltcol amp ampm gt-1 amp; ampm ltcol)
{
for(int q = 0; q lt fila con fila. ampp = = 1; q ){
if((n col * q) gt; = (m * col)) amp((n col * q) lt; (m 1 )*col)){
if(a[x][y-1]!= 0 amperios ampa[x][y-1]!=10){
btns [n col*q]. setText(a[x][y-1] " ");
a[x][y-1]= 10;
btns[n col*q]. establecer habilitado(falso);
}
else if(a[x][y-1]==0){
out(a, btns , e, n col*q, x, y-1);
a[x][y-1]=
btns[n col*q].
establecer habilitado(falso);
}
p = 0;
}
}
}
p = 1;
m = x-1;
n = y 1-1
Si (n gt-1; amp; ampn ltcol amp ampm gt-1 amp; ampm ltcol)
{
for(int q = 0; q lt fila y fila. ampp = = 1; q ){
if((n col * q) gt;=(m * col)) amp((n col * q) lt;(m 1)*col)){
if(a[x][y 1]!= 0 amp ampa[x][y 1]!=10){
btns[n col*q]. setText(a[x][y 1] " ");
a[x][y 1]= 10;
btns[n col*q]. establecer habilitado(falso);
}
else if(a[x][y 1]==0){
out(a, btns, e, n col*q, x, y 1);
a[x][y 1]= 10;
btns[n col*q]. establecer habilitado(falso);
}
p = 0;
}
}
}
}
}
acción de anulación pública realizada (evento de acción e){
if(e . getactioncommand()= = " elemental "){
fila = 9;
col = 9;
bon = 10;
a 1 = nuevo int[bon ];
b = bon
//setSize(297, 377);
a = new int[fila 2][col 2]; p>
p>
este .eliminar(p2);
temporizador();
b 1 . >
B2 . settext(" 0 ");
B3 . settext(" ");
btns = nuevo JButton[fila * col]; p>p2 = new JPanel();
p2.setLayout(new GridLayout(row, col, 0, 0));
for(int I = 0; i lt fila * columna; i) {
btns[I]= nuevo JButton(" ");
btns[i]. setMargin(new Insets(0, 0, 0, 0));
btns[i]. setFont(newFont(null,Font.Bold,25));
btns[i]. addActionListener(este);
btns[i].
addmouse oyente(nuevo evento de ratón normore());
p2 add(btns[I]);
}
contentPane.add(p2, BorderLayout . center);
//setSize(297, 377);
this . pack();
for(int I = 0; está bien *columna; i ){
btns[i]. setText(" ");
btns[i]. setEnabled(true);
}
for(int I = 0; i lt fila 2; i){
for(int j = 0; j ltcol 2; j ){
a[I][j]= 0;
}
}
} más si( e .getactioncommand()= = " intermedio "){
fila = 16
col = 16
bon = 40
//setSize(33*col, 33 * fila 80);
a 1 = nuevo int[bon];
a = nuevo int[fila 2][col 2] ;
b = bon
this . remove(p2);
temporizador . stop(); " 40 ");
B2 . settext(" 0 ");
B3 . settext(" "); col];
p2 = new JPanel();
p2.setLayout(new GridLayout(fila, col, 0, 0));
for( int I = 0; i lt fila * columna; i ){
btns[I]= nuevo JButton(" ");
btns[i]. setMargin(new Insets(0, 0, 0, 0));
btns[i]. setFont(newFont(null,Font.Bold,25));
btns[i]. addActionListener(este);
btns[i]. addmouse oyente(nuevo evento de ratón normore());
p2 add(btns[I]);
}
contentPane.add(p2, BorderLayout . center);
este paquete();
//setSize(33*col, 33 * fila 80);
for(int I =. 0;iltrow*column;i){
btns[i]. setText(" ");
btns[i].
setEnabled(true);
}
for(int I = 0; i lt fila 2; i){
for(int j = 0; j ltcol 2; j ){
a[I][j]= 0;
}
}
} más si( e.getactioncommand()= = "avanzado"){
fila = 16;
col = 32
bon = 99
setSize(33*col, 33 * fila 80);
a 1 = nuevo int[bon];
a = nuevo int[fila 2][col 2]; p>
p>
b = bon
este .eliminar(p2);
temporizador . settext(" 99 " );
B2 . settext(" 0 ");
B3 . fila * columna];
p2 = nuevo JPanel();
p2.setLayout(nuevo GridLayout(fila, columna, 0, 0)); for(int I = 0; i lt fila * columna; i ){
btns[I]= new JButton(" ");
btns[i]. setMargin(new Insets(0, 0, 0, 0));
btns[i]. setFont(newFont(null,Font.Bold,25));
btns[i]. addActionListener(este);
btns[i]. addmouse oyente(nuevo evento de ratón normore());
p2 add(btns[I]);
}
contentPane.add(p2, BorderLayout . center);
//setSize(33*col, 33 * fila 80);
este paquete();
for(int I =. 0;iltrow*column;i){
btns[i]. setText(" ");
btns[i]. setEnabled(true);
}
for(int I = 0; i lt fila 2; i){
for(int j = 0; j ltcol 2; j ){
a[I][j]= 0;
}
}
}
if(e.getSource()==btn){
temporizador . start();
b = bon
B3. " ");
//system out . println(bon);
//Vacío
for(int I = 0; I lt línea * columna; i ){
btns[i]. setText(" ");
btns[i].
setEnabled(true);
}
for(int I = 0; i lt fila 2; i){
for(int j = 0; j ltcol 2;j){
a[I][j]= 0;
}
}
//Generar aleatorio Número
for(int I = 0; i ltboni)
{ int p = 1
int m = (int)(matemáticas. aleatorio(); * fila * col);
mientras(p==1){
int l = 1;
int j;
for(j = 0; j lt i amp ampl = = 1; j ){
if(a1[j]==m){
m =(int)(matemáticas .random()* fila * col);
l = 0;
}
}
if(j==i ){
a 1[I]= m
p = 0
}
}
}
b 1 . settext(bon " ");
B2 . settext(" 0 ");
//Mi
<. p>for(int I = 0; i ltboni ){int x =(a 1[I]/col 1);
int y =(a 1[I ] col 1);
a[x][y]= 100;
}
for(int I = 0; i lt fila 2; i ) {
for(int j = 0; j ltcol 2; j ){
if(I = = 0 | | j = = 0 | | I = = fila 1 | | j = = col 1){
a[I][j]= 0;
}
}
}< / p>
for(int I = 1; i lt= fila; i){
for(int j = 1; j lt= colj){
if( a [i][j]! =100){
for(int l = j-1; l lt= j 1; l ){
if(a[I- 1 ][l]= = 100){
a[I][j];
}
if(a[I 1][l] = = 100){
a[I][j];
}
}
si(a[I][j] -1]= = 100){
a[I][j];
}
if(a[I][j 1]= = 100){
a[I][j];
}
}
}
}
}
if(e.getSource()==timer)
{
String time=b2.getText() .
trim();
int t = entero . parse int(time);
//system out . gt;=600){
temporizador . stop();
} En caso contrario {
t
B2. " ");
}
}
for(int I = 0; iltcol * rowi){
if(btns [ i].getText()!="★")
{
int x = I/col 1;
int y = I col 1; /p>
if(e . getsource()== btns[I] amp; ampa[x][y]==100){
btns[i]. setText("★");
btns[i]. establecer habilitado(falso);
a[x][y]= 10;
for(int k = 0; k ltcol * rowk){
int m 1 = k/col 1;
int n 1 = k col 1;
if(a[m1][n1]!= 10 amp; ampbtns[k]. getText()=="★"){
btns[k]. setText(" * o * ");
}
}
for(int j = 0; j ltcol * filaj ){
int m = j/col 1;
int n = j col 1;
if(a[m][n]==100){
btns[j]. setText("★");
btns[j]. set enable(false);
B3.setText("¡¡Perdiste!!!");
}
btns[j]. establecer habilitado(falso);
a[m][n]= 10;
}
temporizador stop();
else if(e . getsource()= = btns[I]){
if(a[x][y]==0){
salida(a, btns, e, I, x, y);
a[x][y]=
btns[i]. establecer habilitado(falso);
}
if(a[x][y]!= 0 amperios ampa[x][y]!=10){
contratos[i]. setText(a[x][y] " ");
btns[i].
establecer habilitado (falso);
a[x][y]= 10;
}
}
}si no ( btns[i].getText()=="★"){
}
}
}
Clase NormoreMouseEvent MouseAdapter extendido {
clic del mouse en vacío público (evento del mouse e){
system out . println(b); * rowi ){
int x 1 = I/col 1;
int y 1 = I col 1;
if(e . getsource() = = btns[I] amp; ampbtns[i]. getText()! = "★" amp; e.getButton()==MouseEvent.Button3){
btns[i]. setText("★");
B-;
if(b==0){
int flag = 0;
for(int j = 0; j ltcol * filaj ){
int x = j/col 1;
int y = j col 1;
if(a[x][y]= = 100 amp; ampbtns[j].getText()=="★"){
flag;
}
}
if(flag==bon){
timer . stop();
B3.setText("¡Tú ganas!");
}
}
b 1. settext(b " ");
}
} más if(e . getsource()= = btns[I] amp; ampbtns[i].getText()== "★" amp; ampa[x1][y1]!=-1){
if(e.getButton()==MouseEvent.Button3){
btns[i]. setText(" ");
b;
if (b gtbon){
b 1. settext(bon " ");
}
En caso contrario {
b 1 . settext(b " ");
}
btns[i]. setEnabled(true);
}
}
}
}
}
}