Blog de proyectos Java y JSP
jueves, 2 de julio de 2015
sábado, 30 de noviembre de 2013
Juego de gato
CODIGO:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package pakete1;
import java.awt.event.*;
//import javax.swing.*;
/**
*
* @author Genzo
*/
public class Gato extends JFrame implements ActionListener{
Casilla [][]TABLERO;
int Contador;
/**
* Creates new form Gato
*/
public Gato()
{
initComponents();
Contador = 0;
TABLERO = new Casilla[3][3];
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
TABLERO[i][j] = new Casilla();
TABLERO[i][j].A.setBounds((i*100)+10, (j*100)+10, 100, 100);
TABLERO[i][j].A.addActionListener(this);
this.add(TABLERO[i][j].A);
}
}
}
public void actionPerformed(ActionEvent e)
{
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
if (e.getSource()==TABLERO[i][j].A)
{
Tiro(TABLERO[i][j]);
if(Revisar())
{
JOptionPane.showMessageDialog(null,"Has ganado!");
}
Contador++;
}
}
}
}
void Tiro(Casilla X)
{
ImageIcon ICONO=null;
if(Contador%2==0)
{
ICONO = new ImageIcon(this.getClass().getResource("O.png"));
X.B=1;
}
else
{
ICONO = new ImageIcon(this.getClass().getResource("X.png"));
X.B=4;
}
ICONO = new ImageIcon(ICONO.getImage().getScaledInstance(90, -1, java.awt.Image.SCALE_DEFAULT));
X.A.setIcon(ICONO);
X.A.removeActionListener(this);
}
boolean Revisar()
{
boolean Gano= false;
int Suma=0;
for(int i=0;i<3;i++)
{
Suma=TABLERO[i][0].B+TABLERO[i][1].B+TABLERO[i][2].B;
if(Suma==3 || Suma==12)
{
Gano=true;
break;
}
}
for(int i=0;i<3;i++)
{
Suma=TABLERO[0][i].B+TABLERO[1][i].B+TABLERO[2][i].B;
if(Suma==3 ||Suma==12)
{
Gano=true;
break;
}
}
Suma=TABLERO[0][2].B+TABLERO[1][1].B+TABLERO[2][0].B;
if(Suma==3 ||Suma==12)
Gano=true;
Suma=0;
for(int i=0;i<3;i++)
Suma+=TABLERO[i][i].B;
if(Suma==3 ||Suma==12)
Gano=true;
return Gano;
}
/**
* 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">//GEN-BEGIN:initComponents
private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setPreferredSize(new java.awt.Dimension(320, 350));
setResizable(false);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 564, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 466, Short.MAX_VALUE)
);
pack();
}// </editor-fold>//GEN-END:initComponents
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Gato().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
// End of variables declaration//GEN-END:variables
IMAGEN:
Numeros y login Beans JSP
Codigo:
package bean;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author yusesito
*/
public class beanauxl {
private String nom1;
private String pas1;
private String l1;
public beanauxl(){
nom1="lalo";
pas1="123";
l1="";
}
public String getNom1(){
return(nom1);
}
public void setNom1(String m){
nom1=m;
}
public String getPas1(){
return(pas1);
}
public void setPas1(String n){
pas1=n;
}
public String getL1(){
return(l1);
}
public void setL1(String m){
if(l1.contains("0")|| l1.contains("1")||l1.contains("2")||l1.contains("3")||l1.contains("4")||l1.contains("5")||l1.contains("6")||l1.contains("7")||l1.contains("8")||l1.contains("9"))
{
m="CORRECTO";
l1=m;
}
else
{
System.out.println("ERROR");
}
}
}
IMAGEN:
Rompecabezas En JSP
CODIGO:
<%--
Document : juego
Created on : 30/10/2013, 10:42:44 PM
Author : yusesito
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body bgcolor="yellow">
<center>
<h1>BIENVENIDO!</h1>
<%! String op1,op2,op3,op4; %>
<%
op1=request.getParameter("op1");
op2=request.getParameter("op2");
op3=request.getParameter("op3");
op4=request.getParameter("op4");
%>
<!--Imprimir -->
<center>
<%
if(request.getParameter("op1").equals("1"))
{
op1=request.getParameter("op1");
out.println("<img src=1.png>");
}
else if(request.getParameter("op1").equals("2"))
{
op1=request.getParameter("op1");
out.println("<img src=2.png>");
}
else if(request.getParameter("op1").equals("3"))
{
op1=request.getParameter("op1");
out.println("<img src=3.png>");
}
else if(request.getParameter("op1").equals("4"))
{
op1=request.getParameter("op1");
out.println("<img src=4.png>");
}
else if(request.getParameter("op1").equals("") || request.getParameter("op1").equals("5"))
{
op1=request.getParameter("op1");
out.println("ERROR");
}
if(request.getParameter("op2").equals("2"))
{
op2=request.getParameter("op2");
out.println("<img src=2.png>");
}
else if(request.getParameter("op2").equals("1"))
{
op2=request.getParameter("op2");
out.println("<img src=1.png>");
}
else if(request.getParameter("op2").equals("3"))
{
op2=request.getParameter("op2");
out.println("<img src=3.png>");
}
else if(request.getParameter("op2").equals("4"))
{
op2=request.getParameter("op2");
out.println("<img src=4.png>");
}
else if(request.getParameter("op2").equals("") || request.getParameter("op2").equals("5"))
{
op2=request.getParameter("op2");
out.println("ERROR");
}
if(request.getParameter("op3").equals("3"))
{
op3=request.getParameter("op3");
out.println("<img src=3.png>");
}
else if(request.getParameter("op3").equals("1"))
{
op3=request.getParameter("op3");
out.println("<img src=1.png>");
}
else if(request.getParameter("op3").equals("2"))
{
op3=request.getParameter("op3");
out.println("<img src=2.png>");
}
else if(request.getParameter("op3").equals("4"))
{
op3=request.getParameter("op3");
out.println("<img src=4.png>");
}
else if(request.getParameter("op3").equals("") || request.getParameter("op3").equals("5"))
{
op3=request.getParameter("op3");
out.println("ERROR");
}
if(request.getParameter("op4").equals("4"))
{
op4=request.getParameter("op4");
out.println("<img src=4.png>");
}
else if(request.getParameter("op4").equals("2"))
{
op4=request.getParameter("op4");
out.println("<img src=2.png>");
}
else if(request.getParameter("op4").equals("3"))
{
op4=request.getParameter("op4");
out.println("<img src=3.png>");
}
else if(request.getParameter("op4").equals("1"))
{
op4=request.getParameter("op4");
out.println("<img src=1.png>");
}
else if(request.getParameter("op4").equals("") || request.getParameter("op4").equals("5"))
{
op4=request.getParameter("op4");
out.println("ERROR");
}
%>
</center>
</body>
</html>
IMAGEN:
Login Beans JSP
Codigo Bean:
package beans;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author yusesito
*/
public class BeansAuxi {
private String nom1;
private String pas1;
public BeansAuxi(){
nom1="lalo";
pas1="123";
}
public String getNom1(){
return(nom1);
}
public void setNom1(String m){
nom1=m;
}
public String getPas1(){
return(pas1);
}
public void setPas1(String n){
pas1=n;
}
}
IMAGEN:
Ecuacion de 2do Grado JSP
CODIGO:
<%--
Document : pag2
Created on : 12-nov-2013, 5:34:33
Author : Laboratorio 2
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body bgcolor="green" text="white">
<%! String a,b,c;
double result1 ,result2;
%>
<%
a = (String)request.getParameter("T1");
b = (String)request.getParameter("T2");
c = (String)request.getParameter("T3");
%>
<!--Imprimir -->
<center>
<%
if(request.getParameter("T1").equals("") && request.getParameter("T2").equals("") && request.getParameter("").equals("") )
{
out.println("ERROROROROROR" );
}
else{
int a1 =Integer.parseInt(a);
int b1 = Integer.parseInt(b);
int c1 =Integer.parseInt(c);
int raiz = (b1 * b1) - (4 * a1 * c1);
result1 = (-b1 + Math.sqrt(raiz)) / (2 * a1);
result2 = (-b1 - Math.sqrt(raiz)) / (2 * a1);
out.println("</br></br></br></br><h3>Resultado es:</h3></br>" + "X1: "+result1+"</br>"+"X2: "+ result2 );
}
%>
</body>
</html>
<%--
Document : pag2
Created on : 12-nov-2013, 5:34:33
Author : Laboratorio 2
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body bgcolor="green" text="white">
<%! String a,b,c;
double result1 ,result2;
%>
<%
a = (String)request.getParameter("T1");
b = (String)request.getParameter("T2");
c = (String)request.getParameter("T3");
%>
<!--Imprimir -->
<center>
<%
if(request.getParameter("T1").equals("") && request.getParameter("T2").equals("") && request.getParameter("").equals("") )
{
out.println("ERROROROROROR" );
}
else{
int a1 =Integer.parseInt(a);
int b1 = Integer.parseInt(b);
int c1 =Integer.parseInt(c);
int raiz = (b1 * b1) - (4 * a1 * c1);
result1 = (-b1 + Math.sqrt(raiz)) / (2 * a1);
result2 = (-b1 - Math.sqrt(raiz)) / (2 * a1);
out.println("</br></br></br></br><h3>Resultado es:</h3></br>" + "X1: "+result1+"</br>"+"X2: "+ result2 );
}
%>
</body>
</html>
IMAGEN:
Juego de Hanoi JSP
Codigo:
<%--
Document : pag2
Created on : 25/11/2013, 10:33:03 PM
Author : Personal
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%! String t1,t2,t3; %>
<%
t1=request.getParameter("T1");
t2=request.getParameter("T2");
t3=request.getParameter("T3");
%>
<!--Imprimir -->
<center>
<%
if(request.getParameter("T1").equals("1") && request.getParameter("T2").equals("2") && request.getParameter("T3").equals("3"))
{
t1=request.getParameter("T1");
t2=request.getParameter("T2");
t3=request.getParameter("T3");
out.println("<br><br><br><br><img src=p1.png><br><img src=p2.png><br><img src=p3.png><br><h1>Bien!!!</h1>");
}
else if(request.getParameter("T1").equals("1") )
{
t1=request.getParameter("T1");
out.println("<br><br><br><br><img src=p1.png>");
}
else if(request.getParameter("T2").equals("2") )
{
t2=request.getParameter("T2");
out.println("<br><br><br><br><img src=p2.png>");
}
else if(request.getParameter("T3").equals("3") )
{
t3=request.getParameter("T3");
out.println("<br><br><br><br><img src=p3.png>");
}
if(request.getParameter("T1").equals("3") && request.getParameter("T2").equals("2") && request.getParameter("T3").equals("1"))
{
t1=request.getParameter("T1");
t2=request.getParameter("T2");
t3=request.getParameter("T3");
out.println("<br><br><br><br><h1>ERROR La Piesa 3 y 2 estan mal</h1>");
}
if(request.getParameter("T1").equals("1") && request.getParameter("T2").equals("1") && request.getParameter("T3").equals("1"))
{
t1=request.getParameter("T1");
t2=request.getParameter("T2");
t3=request.getParameter("T3");
out.println("<br><br><br><br><h1>ERROR </h1>");
}
if(request.getParameter("T1").equals("2") && request.getParameter("T2").equals("2") && request.getParameter("T3").equals("2"))
{
t1=request.getParameter("T1");
t2=request.getParameter("T2");
t3=request.getParameter("T3");
out.println("<br><br><br><br><h1>ERROR </h1>");
}
if(request.getParameter("T1").equals("3") && request.getParameter("T2").equals("3") && request.getParameter("T3").equals("3"))
{
t1=request.getParameter("T1");
t2=request.getParameter("T2");
t3=request.getParameter("T3");
out.println("<br><br><br><br><h1>ERROR </h1>");
}
if(request.getParameter("T1").equals("2") && request.getParameter("T2").equals("1") && request.getParameter("T3").equals("3"))
{
t1=request.getParameter("T1");
t2=request.getParameter("T2");
t3=request.getParameter("T3");
out.println("<br><br><br><br><h1>ERROR </h1>");
}
if(request.getParameter("T1").equals("1") && request.getParameter("T2").equals("3") && request.getParameter("T3").equals("2"))
{
t1=request.getParameter("T1");
t2=request.getParameter("T2");
t3=request.getParameter("T3");
out.println("<br><br><br><br><h1>ERROR </h1>");
}
if(request.getParameter("T1").equals("2") && request.getParameter("T2").equals("3") && request.getParameter("T3").equals("1"))
{
t1=request.getParameter("T1");
t2=request.getParameter("T2");
t3=request.getParameter("T3");
out.println("<br><br><br><br><h1>ERROR </h1>");
}
if(request.getParameter("T1").equals("3") && request.getParameter("T2").equals("1") && request.getParameter("T3").equals("2"))
{
t1=request.getParameter("T1");
t2=request.getParameter("T2");
t3=request.getParameter("T3");
out.println("<br><br><br><br><h1>ERROR </h1>");
}
%>
<FORM METHOD="GET" ACTION="ari.jsp" target="mainFrame" >
<input type="submit" value="Jugar Denuevo"></center>
</form>
</body>
</html>
IMAGEN:
Suscribirse a:
Entradas (Atom)