Java - ayuda algo sencillo !!

 
Vista:

ayuda algo sencillo !!

Publicado por jose (1 intervención) el 20/04/2010 03:42:28
cambiar de diferente color las casillas del tablero de ajedrez...

tienen que ser tres colores y que esten ordenas como debe de ser... ayudaaa!!

codigo html:

<html>
<head>
</head>
<body>
<form action="/sesion9/backend/tablero.be.jsp">
X:<input type="text" id="x" name="x"><br/>
Y:<input type="text" id="y" name="y"><br/>
<input type="submit" value="Dibujar tablero">

Colores:

Color 1: <input type="text" id="color1" name="Color1" size="20">
Color 2: <input type="text" id="color2" name="Color2" size="20">
Color 3: <input type="text" id="color3" name="Color3" size="20">

</form>
</body>
</html>

codigo java:

<%
String xstr = request.getParameter("x");
String ystr = request.getParameter("y");
int x = Integer.parseInt(xstr);
int y = Integer.parseInt(ystr);
boolean negro = false;
StringBuffer tablero = new StringBuffer();
tablero.append("<table border='1'>");
for(int i = 0; i < y ; i++ ) {
tablero.append("<tr>");
for(int j = 0; j < x; j++) {
String css = "background: white";
if(negro) {
css = "background: black";
negro = false;
} else {
negro = true;
}
if(x % 2 == 0) {
if(j == x - 1) {
negro = !negro;
}
}
tablero.append("<td style='" + css +"'>...</td>");
}
tablero.append("</tr>");
}
tablero.append("</table>");

%>

<%=x%><br/>
<%=y%>
<br/>
<%=tablero%>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder