elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Recuerda que debes registrarte en el foro para poder participar (preguntar y responder)


  Mostrar Temas
Páginas: 1 [2] 3
11  Programación / Java / Error con arraylist en: 5 Marzo 2021, 17:33 pm
Hola buenas tardes, me sale el siguiente error:

Exception in thread "AWT-EventQueue-0" java.lang.IndexOutOfBoundsException: Index 2 out of bounds for length 1


Cuando ejecuto este codigo:

public void menuJugador() {
JLabel cartaNum = new JLabel();
cartaNum.setBounds(420,250,120,120);


ImageIcon imagen = new ImageIcon(miControl.getJugador().cartasEnMano.get(indice)+".jpg");
JLabel btn = new JLabel();
btn.setBounds(270,350,120,180);

JLabel turno = new JLabel("Turno de: "+miControl.getJugador().getNombre());
turno.setBounds(0,0,200,20);
panel.add(turno);


JButton boton = new JButton("Siguiente");
boton.setBounds(420,360,100,30);


JButton boton3 = new JButton("Tirar");
boton3.setBounds(420,410,100,30);

JButton boton4 = new JButton("Agrupar");
boton4.setBounds(420,460,100,30);



btn.setIcon(new ImageIcon(imagen.getImage().getScaledInstance(btn.getWidth(),btn.getHeight(),Image.SCALE_SMOOTH)));
panel.add(btn);
panel.add(boton);
panel.add(boton3);
panel.add(boton4);
panel.add(cartaNum);
boton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (indice < miControl.getJugador().cartasEnMano.size()) {
r=indice;
ImageIcon imagen = new ImageIcon(miControl.getJugador().cartasEnMano.get(indice)+".jpg");
cartaNum.setText("Carta numero: "+ indice);
btn.setIcon(new ImageIcon(imagen.getImage().getScaledInstance(btn.getWidth(),btn.getHeight(),Image.SCALE_SMOOTH)));
indice++;

} else {
indice=0;
r=0;
}

}

} );

boton3.addActionListener(new ActionListener() { //al presionar este boton salta el error
public void actionPerformed(ActionEvent e) {
miControl.tirarCarta(r,miControl.getJugador()); ¿
indice=0;
r=0;


}




});

------------------------------------------------------------------------------------------------------------------------------------------


public void tirarCarta( int op, Jugador j) {
//op va a ser la carta a tirar y jugador va a ser el jugador que la tira
mesa.add(j.cartasEnMano.get(op)); //mesa es un arrayList y cartas en mano es un arraylist que
esta en la clase Jugador
j.cartasEnMano.remove(j.cartasEnMano.get(op));


}


Si alguien me puede ayudar se lo agradeceria
12  Programación / Java / java.lang.UnsupportedClassVersionError en: 17 Febrero 2021, 23:31 pm
Hola, estoy tratando de compilar un codigo y me sale el siguiente error:

Error: LinkageError occurred while loading main class Menu
java.lang.UnsupportedClassVersionError: Menu (class file version 58.65535) was compiled with preview features that are unsupported. This version of the Java Runtime only recognizes preview features for class file version 59.65535

Nose como hacer para solucionarlo, alguien podria ayudarme?

Muchas gracias
13  Programación / Java / Error occurred during initialization of boot layer en: 10 Febrero 2021, 21:00 pm
Hola.Me sale el error "Package jdk.internal.jimage in both module java.base and module jrt.fs" cuando quiero ejecutar este codigo y nose porque:

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTextField;
import java.awt.Font;
import java.awt.Color;
import javax.swing.SwingConstants;
import javax.swing.JButton;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.awt.GridLayout;
import javax.swing.BoxLayout;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.ImageIcon;

import net.miginfocom.swing.MigLayout;
import java.awt.CardLayout;
import javax.swing.JTextArea;

public class Menu extends JFrame {

   private JPanel contentPane;
   private JTextField txtAgregarJugador;
   private JButton boton1;
   private JPanel panel;
   static ArrayList<String> vectorNombres = new ArrayList<String>();

   /**
    * Launch the application.
    */
   public static void main(String[] args) {
      /*EventQueue.invokeLater(new Runnable() {
         public void run() {
            try {*/
               Menu frame = new Menu();
               frame.setVisible(true);
            /*} catch (Exception e) {
               e.printStackTrace();
            }
         }
      });*/
      //elementosVector();
   }

   public static void elementosVector() {
      vectorNombres.add("Carta 1");
      vectorNombres.add("Carta 2");
      vectorNombres.add("Carta 3");
      vectorNombres.add("Carta 4");
   }
   /**
    * Create the frame.
    */
   public Menu() {
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      setBounds(200, 200, 634, 460);
      contentPane = new JPanel();
      contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
      setContentPane(contentPane);
     
      txtAgregarJugador = new JTextField();
      txtAgregarJugador.setBounds(new Rectangle(0, 0, 25, 23));
      txtAgregarJugador.setBounds(122, 28, 179, 33);
      txtAgregarJugador.setHorizontalAlignment(SwingConstants.CENTER);
      txtAgregarJugador.setBackground(new Color(192, 192, 192));
      txtAgregarJugador.setEnabled(false);
      txtAgregarJugador.setFont(new Font("Arial", Font.ITALIC, 13));
      txtAgregarJugador.setText("Nombre jugador");
      txtAgregarJugador.setToolTipText("Agregar jugador");
      txtAgregarJugador.setColumns(10);
     
      boton1 = new JButton("Agregar jugador");
      boton1.setForeground(new Color(255, 0, 255));
      boton1.setBackground(new Color(218, 112, 214));
      boton1.setBounds(new Rectangle(122, 85, 179, 31));
      boton1.setFont(new Font("Trebuchet MS", Font.PLAIN, 11));
      contentPane.setLayout(null);
      contentPane.add(txtAgregarJugador);
      contentPane.add(boton1);
     
      JTextArea textArea = new JTextArea();
      textArea.setBackground(new Color(255, 245, 238));
      textArea.setForeground(new Color(255, 105, 180));
      textArea.setToolTipText("mostrarJugadores");
      textArea.setBounds(10, 263, 419, 185);
      contentPane.add(textArea);
     
      JButton boton2 = new JButton("Iniciar juego");
      boton2.setBackground(new Color(255, 0, 255));
      boton2.setForeground(new Color(255, 0, 255));
      boton2.setBounds(318, 219, 108, 33);
      contentPane.add(boton2);
     
      panel = new JPanel();
      panel.setBounds(0, 0, 436, 252);
      contentPane.add(panel);
     
      for(int i=0;i<vectorNombres.size();i++) {
          JButton btn = new JButton("");
          btn.setIcon(new ImageIcon(Class.class.getResource("C:\\Users\\54232\\Documents\\Cartas" + vectorNombres.get(i) + ".pjg")));
          panel.add(btn);
      }

   }
}

Si alguien puede ayudarme se lo agradeceria!
14  Programación / Programación General / Error en java en: 10 Febrero 2021, 20:58 pm
Hola! buenas tardes. Me sale el error "Package jdk.internal.jimage in both module java.base and module jrt.fs" cuando quiero ejecutar este codigo:

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTextField;
import java.awt.Font;
import java.awt.Color;
import javax.swing.SwingConstants;
import javax.swing.JButton;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.awt.GridLayout;
import javax.swing.BoxLayout;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.ImageIcon;

import net.miginfocom.swing.MigLayout;
import java.awt.CardLayout;
import javax.swing.JTextArea;

public class Menu extends JFrame {

   private JPanel contentPane;
   private JTextField txtAgregarJugador;
   private JButton boton1;
   private JPanel panel;
   static ArrayList<String> vectorNombres = new ArrayList<String>();

   /**
    * Launch the application.
    */
   public static void main(String[] args) {
      /*EventQueue.invokeLater(new Runnable() {
         public void run() {
            try {*/
               Menu frame = new Menu();
               frame.setVisible(true);
            /*} catch (Exception e) {
               e.printStackTrace();
            }
         }
      });*/
      //elementosVector();
   }

   public static void elementosVector() {
      vectorNombres.add("Carta 1");
      vectorNombres.add("Carta 2");
      vectorNombres.add("Carta 3");
      vectorNombres.add("Carta 4");
   }
   /**
    * Create the frame.
    */
   public Menu() {
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      setBounds(200, 200, 634, 460);
      contentPane = new JPanel();
      contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
      setContentPane(contentPane);
      
      txtAgregarJugador = new JTextField();
      txtAgregarJugador.setBounds(new Rectangle(0, 0, 25, 23));
      txtAgregarJugador.setBounds(122, 28, 179, 33);
      txtAgregarJugador.setHorizontalAlignment(SwingConstants.CENTER);
      txtAgregarJugador.setBackground(new Color(192, 192, 192));
      txtAgregarJugador.setEnabled(false);
      txtAgregarJugador.setFont(new Font("Arial", Font.ITALIC, 13));
      txtAgregarJugador.setText("Nombre jugador");
      txtAgregarJugador.setToolTipText("Agregar jugador");
      txtAgregarJugador.setColumns(10);
      
      boton1 = new JButton("Agregar jugador");
      boton1.setForeground(new Color(255, 0, 255));
      boton1.setBackground(new Color(218, 112, 214));
      boton1.setBounds(new Rectangle(122, 85, 179, 31));
      boton1.setFont(new Font("Trebuchet MS", Font.PLAIN, 11));
      contentPane.setLayout(null);
      contentPane.add(txtAgregarJugador);
      contentPane.add(boton1);
      
      JTextArea textArea = new JTextArea();
      textArea.setBackground(new Color(255, 245, 238));
      textArea.setForeground(new Color(255, 105, 180));
      textArea.setToolTipText("mostrarJugadores");
      textArea.setBounds(10, 263, 419, 185);
      contentPane.add(textArea);
      
      JButton boton2 = new JButton("Iniciar juego");
      boton2.setBackground(new Color(255, 0, 255));
      boton2.setForeground(new Color(255, 0, 255));
      boton2.setBounds(318, 219, 108, 33);
      contentPane.add(boton2);
      
      panel = new JPanel();
      panel.setBounds(0, 0, 436, 252);
      contentPane.add(panel);
      
      for(int i=0;i<vectorNombres.size();i++) {
          JButton btn = new JButton("");
          btn.setIcon(new ImageIcon(Class.class.getResource("C:\\Users\\54232\\Documents\\Cartas" + vectorNombres.get(i) + ".pjg")));
          panel.add(btn);
      }

   }
}

Si alguien puede ayudarme se lo agradeceria.
15  Programación / Java / Mostrar cartas GUI en: 10 Febrero 2021, 06:15 am
Hola buenas tardes. Estoy haciendo un juego de cartas y necesito mostrar todas las cartas que tengo en un mazo y nosé como hacer. Los nombres de las cartas están cargados en un array. Por ejemplo: "2 de oro", "1 de espada". Necesito vincular el nombre con la imagen de la carta.
Si alguien me puede ayudar se lo agradecería mucho

[MOD] No esta permitido publicar el mismo post en distintos subforos. Seran borrados directamente.

Leer las Reglas del Foro.
16  Programación / Java / Problema con archivos en: 23 Octubre 2020, 01:34 am
Hola buenas tardes, estoy haciendo un programa en java con archivos, directorios, tengo que agregar el nombre de los archivos por teclado y validar que ese mismo nombre no exista en el directorio, para eso cree un array de archivos, donde guardo los nombres de los archivos y su correspondiente ubicacion.
El problema es que la validacion tira un resultado incorrecto cuando pongo dos archivos con el mismo nombre, no me tendria que dejar agregar el mismo nombre de archivo al array archi y sin embargo lo agrega igual,  si alguien me podria ayudar se lo agradeceria.

public class Archivo {

   String nombre;
   int longitud;
   String ubicacion;
   int bloqueInicial;
   int bloqueFinal;
   
   
   public void setNombre(String nombre) {
      this.nombre=nombre;
   }
   
   public void setLongitud(int l) {
      this.longitud=l;
   }
   
   public void setUbicacion(String ubicacion) {
      this.ubicacion=ubicacion;
   }
   
   public void setBloqueInicial(int bloque) {
      this.bloqueInicial=bloque;
   }
   
   public void setBloqueFinal(int bloque) {
      this.bloqueFinal=bloque;
   }
   
   public String getNombre() {
      return this.nombre;
   }
   
   public int getLongitud() {
   return this.longitud;
   }

    public String getUbicacion() {
    return this.ubicacion;
    }
   
    public int getBloqueInicial() {
       return this.bloqueInicial;
    }
   
    public int getBloqueFinal() {
       return this.bloqueFinal;
    }
-----------------------------------------------------------------------------------------

import java.io.*;
import java.util.ArrayList;
import java.util.Scanner;

public class Directorio {
  static File directorio;
  static File archivo;
  int bloqueS=0;
  static int iArchivo=0;

 static ArrayList<Archivo> archi = new ArrayList<>();
private Scanner nombre;
 

public void crearDirectorio () {
   
     directorio = new File("directorio2");
   directorio.mkdir();
}


public boolean verificar (String nombre) {
boolean t=true;

   for (int i=0; i<archi.size();i++) {
      if (archi.get(i).getNombre()==nombre) {
         t=false;
         System.out.println("es igual");
      }
   }
   return t;
}


public void agregarArchivo () {   //agrega el archivo al directorio y al array
   boolean c;
       for (int i=0; i<3;i++) {
      System.out.println("Ingrese nombre de archivo");
      Scanner nom= new Scanner(System.in);
      String nombre= nom.nextLine();
      c=verificar(nombre);
      if (c!=false) {
       try {
      archivo = new File(directorio,nombre);
      archivo.createNewFile();
   
      Archivo aux = new Archivo();
     aux.setNombre(archivo.getName());
     aux.setUbicacion(archivo.getAbsolutePath());
     aux.setLongitud((int)archivo.length());
     archi.add(aux);
    
   } catch (IOException e) {
      e.printStackTrace();
   }
      
   } else
      System.out.println("El nombre con ese archivo ya existe");
   
   }
}

public static void mostrarArchivos() {
   System.out.println("                           FAT                             ");
   for (int i=0; i<archi.size(); i++) {
    System.out.println(" ");
   System.out.println("**********************************************************************");
   System.out.println("     Numero de bloque: "+i);
   //System.out.println("     Bloque sig: "+archi.get(i).bloqueSig);
   System.out.println("     Longitud: "+archi.get(i).longitud);
   System.out.println("     Nombre de archivo:   "+archi.get(i).getNombre());
   //System.out.println("     Estado bloque: "+archi.get(i).getEstado());
   System.out.println("     Ubicacion en disco: "+archi.get(i).getUbicacion());
    System.out.println("***********************************************************************");
   System.out.println(" ");
   
 
       
   }
   }

public static void main(String[] args) {
   Directorio d = new Directorio();
   d.crearDirectorio();
   d.agregarArchivo();
   d.mostrarArchivos();
    }
   
   
}
   
17  Programación / Java / Problemas con directorio en: 16 Octubre 2020, 00:39 am
Hola buenas noches, tengo un problema al mostrar la longitud del directorio, aunque haya archivos dentro de el me muestra que la longitud es 0 y nose porque, si alguien me puede ayudar se lo agradecería.

import java.io.*;
import java.util.ArrayList;

public class Directorio {
static File directorio;


public void crearDirectorio () {

try {
File directorio = new File("directorio");
directorio.mkdir();
File archivo = new File(directorio,"archivo.txt");
File archivo2 = new File(directorio,"archivo2.txt");
archivo.createNewFile();
archivo2.createNewFile();
System.out.println(directorio.length()); //aqui quiero mostrar la longitud del directorio, tiene dos archivos dentro
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}



public static void mostrarDirectorio() {
File mostrar = new File(directorio.getAbsolutePath());
String[] archivos = mostrar.list();
for (int i=0; i<archivos.length; i++) {
System.out.println(archivos);
}
}




public static void main(String[] args) {
Directorio d = new Directorio();
d.crearDirectorio();
//d.mostrarDirectorio();
}


}
18  Programación / Java / Crear ficheros en: 23 Septiembre 2020, 00:27 am
Hola! buenas tardes! tengo que crear un fichero ingresando sus campos y los datos por teclado y nose como hacer ya que nunca trabaje con archivos en este lenguaje. Si alguien me podria mostrar algun ejemplo o algo se lo agradeceria. Muchas gracias
19  Programación / Java / Ideas para un juego! en: 23 Agosto 2020, 03:53 am
Hola!! buenas noches!
Tengo que programar un juego para la uni en java utilizando MVC, puede ser de cartas o de dados, y necesito alguna idea porque no se cual elegir! tiene que ser de dificultad media.
Si podrian darme alguna sugerencia se lo agradeceria.
De mas esta decir que solo busco una idea y no el juego ya realizado jaja

 Muchas gracias!!!!!  :D :D
20  Seguridad Informática / Hacking / Saber de donde proviene un mail en: 9 Julio 2020, 20:39 pm
Hola, buenas tardes! Quería saber si alguien sabia alguna manera de rastrear de donde proviene un mail de outlook, ya que me estan acosando hace un tiempo y necesito saber quien es la persona que esta haciendo esto, muchas gracias.
Páginas: 1 [2] 3
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines