airanmetal
Bovino adolescente
- Desde
- 5 Mar 2009
- Mensajes
- 52
- Tema Autor
- #1
hola amigos bakunos no se porque no me esta corriendo este programa si alguien me pudiera ayudar se los agradeceria mucho :eolo:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Tablero implements ActionListener {
Random numero= new Random();
static JPanel panel= new JPanel();
static JFrame Tablero= new JFrame("Barcos");
static JPanel panel1= new JPanel();
static ImageIcon imagen=new ImageIcon("olas-mar.jpg");
static ImageIcon imagen1=new ImageIcon("mar.jpg");
static ImageIcon imagen2=new ImageIcon("barco.jpg");
int posicion1=0;
int posicion2=0;
static JButton[][]button1 = new JButton[10][10];
static JButton[][]button2 = new JButton [10][10];
static boolean[][] player= new boolean [10][10];
static boolean [][] PC= new boolean [10][10];
static boolean [][] marcados= new boolean [10][10];
static boolean [][] marcados2= new boolean [10][10];
public void Tablero(){
Tablero.setLayout(new GridLayout(1,2));
panel.setSize (100,100);
panel1.setSize (100,100);
Tablero.add(panel);
Tablero.add(panel1);
Tablero.setSize(1050, 800);
Tablero.setLocationRelativeTo(null);
panel.setBackground(Color.LIGHT_GRAY);
panel1.setBackground(Color.WHITE);
panel.setLayout(new GridLayout(10,10));
panel1.setLayout(new GridLayout(10,10));
for (int x=0; x<10;x++)
for (int y=0;y<10; y++){
button1[x][y]=new JButton();
button2[x][y]=new JButton();
button1[x][y].setBackground(Color.LIGHT_GRAY);
button2[x][y].setBackground(Color.LIGHT_GRAY);
button1[x][y].addActionListener(this);
button2[x][y].setBackground(Color.blue);
button1[x][y].setBackground(Color.blue);
PC[x][y]=false;
player[x][y]=false;
marcados[x][y]=false;
marcados2[x][y]=false;
}
for (int i=0; i<10; i++)
for (int j=0; j<10; j++){
panel.add(button1[j]);
panel1.add(button2[j]);
} for (int pc=0; pc<10;pc++)
for (int pc1=0; pc1<10; pc1++){
int x=Random.obtenerNumero();
int y=Random.obtenerNumero();
if(PC[x][y]==false){
PC[x][y]=true;
}else{
pc--;
pc1--;
}
for (int p=0; p<10; p++)
for (int p1=0; p1<10; p1++){
int a =Random.obtenerNumero();
int b =Random.obtenerNumero();
if(player[a]==false){
player[a]=true;
}else{
p--;
p1--;
}
}
}
Tablero.setVisible(true);
}
public int barcosPC(){
int compu=10-posicion1;
return compu;
}
public int barcosPlayer(){
int Player=10-posicion2;
return Player;
}
public void actionPerformed(ActionEvent e) {
for(int j=0; j<10;j++)
for (int k=0; k<10; k++){
if (e.getSource()==button2[j][k]){
if (marcados2[j][k]==false){
marcados2[j][k]=true;
for (boolean x=false; x=true
for (boolean y=false; y=true
{
int c=Random.obtenerNumero();
int d=Random.obtenerNumero();
if(marcados2[c][d]==false){
if(player[c][d]==true){
button1[c][d].setIcon(imagen2);
posicion2++;
}else{
button1[c][d].setBackground(Color.blue);
}
marcados2[c][d]=true;
x=1;
y=1;
}else{
x=0;
y=0;
}
if (posicion2>9){
JOptionPane.showMessageDialog(null, "Perdiste");
}
}
if (PC[j][k]==true){
button2[j][k].setIcon(imagen2);
posicion1++;
}else {
button2[j][k].setBackground(Color.blue);
}
if (posicion1>9){
JOptionPane.showMessageDialog(null, "Ganaste");
System.exit(0);
}
}
}
}
}
}
---------------------------------------------------------------------------------------------------------------------------------------------------
public class Random {
static int num;
public static int obtenerNumero (){
double posicion1=100*(Math.random());
int x = 0;
num= x;
return num;
}
}
-----------------------------------------------------------------------------------------------------------
import javax.swing.*;
import java.awt.*;
import java.io.*;
public class AppBarcos {
public static void main(String[] args) {
Tablero objeto = new Tablero();
objeto.Tablero();
}
}
---------------------------------------------------------------------------------------------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Tablero implements ActionListener {
Random numero= new Random();
static JPanel panel= new JPanel();
static JFrame Tablero= new JFrame("Barcos");
static JPanel panel1= new JPanel();
static ImageIcon imagen=new ImageIcon("olas-mar.jpg");
static ImageIcon imagen1=new ImageIcon("mar.jpg");
static ImageIcon imagen2=new ImageIcon("barco.jpg");
int posicion1=0;
int posicion2=0;
static JButton[][]button1 = new JButton[10][10];
static JButton[][]button2 = new JButton [10][10];
static boolean[][] player= new boolean [10][10];
static boolean [][] PC= new boolean [10][10];
static boolean [][] marcados= new boolean [10][10];
static boolean [][] marcados2= new boolean [10][10];
public void Tablero(){
Tablero.setLayout(new GridLayout(1,2));
panel.setSize (100,100);
panel1.setSize (100,100);
Tablero.add(panel);
Tablero.add(panel1);
Tablero.setSize(1050, 800);
Tablero.setLocationRelativeTo(null);
panel.setBackground(Color.LIGHT_GRAY);
panel1.setBackground(Color.WHITE);
panel.setLayout(new GridLayout(10,10));
panel1.setLayout(new GridLayout(10,10));
for (int x=0; x<10;x++)
for (int y=0;y<10; y++){
button1[x][y]=new JButton();
button2[x][y]=new JButton();
button1[x][y].setBackground(Color.LIGHT_GRAY);
button2[x][y].setBackground(Color.LIGHT_GRAY);
button1[x][y].addActionListener(this);
button2[x][y].setBackground(Color.blue);
button1[x][y].setBackground(Color.blue);
PC[x][y]=false;
player[x][y]=false;
marcados[x][y]=false;
marcados2[x][y]=false;
}
for (int i=0; i<10; i++)
for (int j=0; j<10; j++){
panel.add(button1[j]);
panel1.add(button2[j]);
} for (int pc=0; pc<10;pc++)
for (int pc1=0; pc1<10; pc1++){
int x=Random.obtenerNumero();
int y=Random.obtenerNumero();
if(PC[x][y]==false){
PC[x][y]=true;
}else{
pc--;
pc1--;
}
for (int p=0; p<10; p++)
for (int p1=0; p1<10; p1++){
int a =Random.obtenerNumero();
int b =Random.obtenerNumero();
if(player[a]==false){
player[a]=true;
}else{
p--;
p1--;
}
}
}
Tablero.setVisible(true);
}
public int barcosPC(){
int compu=10-posicion1;
return compu;
}
public int barcosPlayer(){
int Player=10-posicion2;
return Player;
}
public void actionPerformed(ActionEvent e) {
for(int j=0; j<10;j++)
for (int k=0; k<10; k++){
if (e.getSource()==button2[j][k]){
if (marcados2[j][k]==false){
marcados2[j][k]=true;
for (boolean x=false; x=true

for (boolean y=false; y=true

int c=Random.obtenerNumero();
int d=Random.obtenerNumero();
if(marcados2[c][d]==false){
if(player[c][d]==true){
button1[c][d].setIcon(imagen2);
posicion2++;
}else{
button1[c][d].setBackground(Color.blue);
}
marcados2[c][d]=true;
x=1;
y=1;
}else{
x=0;
y=0;
}
if (posicion2>9){
JOptionPane.showMessageDialog(null, "Perdiste");
}
}
if (PC[j][k]==true){
button2[j][k].setIcon(imagen2);
posicion1++;
}else {
button2[j][k].setBackground(Color.blue);
}
if (posicion1>9){
JOptionPane.showMessageDialog(null, "Ganaste");
System.exit(0);
}
}
}
}
}
}
---------------------------------------------------------------------------------------------------------------------------------------------------
public class Random {
static int num;
public static int obtenerNumero (){
double posicion1=100*(Math.random());
int x = 0;
num= x;
return num;
}
}
-----------------------------------------------------------------------------------------------------------
import javax.swing.*;
import java.awt.*;
import java.io.*;
public class AppBarcos {
public static void main(String[] args) {
Tablero objeto = new Tablero();
objeto.Tablero();
}
}
---------------------------------------------------------------------------------------------