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

 

 


Tema destacado: Estamos en la red social de Mastodon


  Mostrar Mensajes
Páginas: 1 ... 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 [78] 79
771  Programación / Java / Re: JFileChooser en: 26 Octubre 2009, 16:20 pm
claro si funcionaria aunke tambien podrias llevar el obj file para la class ProbandoJFrame bien sea haciendo el obj publico|protected o le haces un getter para optener el obj desde ProbandoJFrame usando open.getFileXml o protegido open.FileXml

Saludos

772  Programación / Java / Re: JFileChooser en: 26 Octubre 2009, 15:14 pm
netbeans no me gusta... :-\  pero para seleccionar archivo seria asi .

Código
  1. JFileChooser chooser = new JFileChooser();
  2. chooser.showOpenDialog(new JFrame());
  3. File fileXML=chooser.getSelectedFile();
773  Programación / Java / Re: manejar entrada, salida y cambios de jugadores de futbol con clases hilos en: 23 Octubre 2009, 05:44 am
 :huh: especifica mas tu problema.

774  Programación / Java / Re: SERVIDOR CON MULTIPLES CLIENTES en: 23 Octubre 2009, 05:39 am
es facil solo tienes que crear un obj usuario por cada conexion entrante y comunicarte con el enviandole algun command/msg.

Código
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.io.PrintWriter;
  5. import java.net.InetAddress;
  6. import java.net.ServerSocket;
  7. import java.net.Socket;
  8. import java.net.UnknownHostException;
  9. import java.util.Hashtable;
  10.  
  11. /**
  12.  * @Autor Leyer
  13.  * @see   GlassFish Tools Bundle For Eclipse
  14.  *
  15.  * Servidor simple para multiples conexiones
  16.  */
  17. interface config{
  18. public static final int    _port    = 8081;
  19. public static final int    _backlog = 500;
  20. public static final String _host    = "localhost";
  21. }
  22. public class server extends ServerSocket implements Runnable
  23. {
  24. private class user extends Thread{
  25. private BufferedReader reader      = null;
  26. private PrintWriter    printWriter = null;
  27. private Socket  socket             = null;
  28. private boolean connected          = false;
  29. private int     nro = 0;
  30. private String username = null;
  31. public user(Socket socket, int nro){
  32. this.socket = socket;
  33. try {
  34. reader = new BufferedReader(new InputStreamReader(server.this.socket.getInputStream()));
  35.    printWriter = new PrintWriter(this.socket.getOutputStream());
  36. connected = true;
  37. username = this.socket.getLocalAddress().getHostAddress();
  38. this.nro = nro;
  39. } catch (IOException e) {
  40. e.printStackTrace();
  41. }
  42. }
  43.             void writer(String msg){
  44. printWriter.println(msg);
  45. }
  46. public boolean isActive() {
  47. return connected;
  48. }
  49. public void setActive(boolean active) {
  50. this.connected = active;
  51. }
  52. @Override
  53. public void run() {
  54. while(connected){
  55. try {
  56. if(reader.ready()){
  57. String msg = reader.readLine();
  58. System.out.println(" User:"+nro+ "+"+username+"-> "+msg);
  59. if(msg.equalsIgnoreCase("disconnected")){
  60. handler.remove(username);
  61. }
  62. }
  63. } catch (IOException e) {
  64. e.printStackTrace();
  65. }
  66. }
  67. }}
  68. private Socket      socket    = null;
  69. boolean init                    = true;
  70. private Hashtable< String, user> handler  = new Hashtable<String, user>();
  71. int nro = 0;
  72. @Override public void run() {
  73. while(init){
  74. try {socket = accept();
  75. System.out.println("New User: "+socket.getLocalAddress().getHostAddress());
  76. handler.put(socket.getLocalAddress().getHostAddress(), new user(socket,nro));
  77. handler.get(socket.getLocalAddress().getHostAddress()).writer("true");
  78. nro ++;
  79. } catch (IOException e) {
  80. e.printStackTrace();
  81. }
  82. }
  83. }
  84. public boolean isInit() {
  85. return init;
  86. }
  87. public void setInit(boolean init) {
  88. this.init = init;
  89. }
  90. public server(int port, int backlog, InetAddress bindAddr)
  91. throws IOException {
  92. super(port, backlog, bindAddr);
  93. System.out.println("---------------------------------------");
  94. System.out.println("Server is OK");
  95. System.out.println("---------------------------------------");
  96. new Thread(this).start();
  97. }
  98. /**
  99. * @param args
  100. * @throws IOException
  101. * @throws UnknownHostException
  102. */
  103. public static void main(String[] args) throws UnknownHostException
  104. new server(config._port,
  105. config._backlog,
  106. InetAddress.getByName(config._host));
  107. }
  108. }

Saludos
775  Programación / Java / Re: Error ejecución, calcular velocidad de rotación de Satelite. en: 20 Octubre 2009, 06:19 am
 :¬¬ no se ami me da cero 0 todo el tiempo
776  Programación / Java / Re: ejercicispo de java con vector en: 20 Octubre 2009, 05:53 am
Segundo! :P demaciadoooooooooooo facil

Código
  1. import java.util.Scanner;
  2. import java.util.Vector;
  3.  
  4. public class Test2 {
  5. private Vector<Integer> vectorA = new Vector<Integer>();
  6. private Vector<Float>  vectorP = new Vector<Float>();
  7. private Scanner scanner = new Scanner(System.in);
  8. public Test2() {
  9. vectorA.addElement(19);
  10. vectorA.addElement(23);
  11. vectorA.addElement(33);
  12. vectorA.addElement(18);
  13. vectorA.addElement(17);
  14.  
  15. for(int index=0;index<5;index++){
  16. System.out.println("Peso del Alumno Nro: "+index);
  17. float p =scanner.nextFloat();
  18. vectorP.addElement(p);
  19. }
  20. System.out.println("============================================================================");
  21. for(int index=0;index<5;index++){
  22. System.out.println("Alumno "+index+" Edad: "+vectorA.get(index)+" Peso: "+vectorP.get(index));
  23. }
  24. int pM = vectorA.get(0);
  25. Float pN = vectorP.get(0);
  26. int index;
  27. int p = 0,y =0;
  28. for(index=0;index<5;index++){
  29. if(!(pM>vectorA.get(index))){
  30. pM = vectorA.get(index);
  31. p = index;
  32. }
  33. }
  34. for(index=0;index<5;index++){
  35. if(!(pN<vectorP.get(index))){
  36. pN = vectorP.get(index);
  37. y= index;
  38. }
  39. }
  40. System.out.println("============================================================================");
  41. System.out.println("Peso de la Persona con mas edad: "+vectorP.get(p)+" Edad: "+vectorA.get(p));
  42. System.out.println("Edad de la persona con menor peso: "+vectorP.get(y)+" Edad: "+vectorA.get(y));
  43. System.out.println("============================================================================");
  44. System.out.print("Ingrese la edad de la persona a buscar: ");
  45. int n = scanner.nextInt();
  46. if(n>0){
  47. if(vectorA.contains(n)){
  48. System.out.println("===============================[DATOS]======================================\n");
  49. for(int j=0;j<5;j++){
  50. if(vectorA.get(j) == n){
  51. System.out.println("Encontrado: "+vectorA.get(j)+" Peso: "+vectorP.get(j)+"\n");
  52. break;
  53. }
  54. }
  55. System.out.println("============================================================================");
  56. }else
  57. System.out.println("No encontrado!: "+n);
  58. }
  59.  
  60. }
  61. /**
  62. * @param args
  63. */
  64. public static void main(String[] args) {
  65. new Test2();
  66.  
  67. }
  68. }
777  Programación / Java / Re: Ejercicio de java con vector en: 20 Octubre 2009, 04:54 am
jaja estaba tan aburrido que me puce ha hacerlos :-* pero bueno no se si sea asi ya que soy malo en la programacion cuando se trata de matematicas esta es la 1


Código
  1. import java.util.Random;
  2. import java.util.Vector;
  3.  
  4. public class test {
  5. public static final int SIZE    = 100;
  6.  
  7. private Vector<Integer> vectorA = null;
  8. private Vector<Integer> vectorB = null;
  9. private Vector<Integer> vectorC = null;
  10. private Random random;
  11. public test() {
  12. vectorA = new Vector<java.lang.Integer>();
  13. vectorB = new Vector<java.lang.Integer>();
  14. vectorC = new Vector<java.lang.Integer>();
  15. random = new Random();
  16. System.out.println("---------------[ Vector ]--------------------");
  17. for(int index=0;index<11;index++){
  18. vectorA.addElement(random.nextInt(SIZE));
  19. }
  20. System.out.println(vectorA+"\n");
  21. int m=vectorA.get(0);;
  22. int n=vectorA.get(0);;
  23. int posN =0;
  24. int posM =0;
  25. int pN   =0;
  26. int iN   =0;
  27. for(int index=1;index<11;index++){
  28. double b = vectorA.get(index);
  29. double b1 = b % 2;
  30. if (b1 == 0) {pN++;vectorB.addElement(index);
  31. }else{        iN++;vectorC.addElement(index);
  32. }
  33. if(!(n<vectorA.get(index))){n = vectorA.get(index);
  34. posN = index;
  35. }
  36. if(!(m>vectorA.get(index))){m = vectorA.get(index);
  37. posM = index;
  38. }
  39. }
  40. System.out.println("---------------[ Menor < ]-------------------");
  41. System.out.print("Nro: "+n);
  42. System.out.println("  Posición: "+posN+"\n");
  43. System.out.println("---------------[ Mayor > ]-------------------");
  44. System.out.print("Nro: "+m);
  45. System.out.println("  Posición: "+posM+"\n");
  46. System.out.println("---------------[ Promedio ]-------------------");
  47. if((pN*100/10)>(iN*100/10))
  48. System.out.println("Promedio Mayor los Pares: "+pN*100/10+"\n");
  49. else
  50. System.out.println("Promedio Mayor los Impares: "+iN*100/10+"\n");
  51. System.out.println("---------------[ Vector A|B|C < ]-------------------\n");
  52. System.out.println("Vector A: "+vectorA);
  53. System.out.println("Vector B: "+vectorB);
  54. System.out.println("Vector C: "+vectorC);
  55. }
  56. public static void main(String[] args) {
  57. new test();
  58. }
  59. }
778  Programación / Java / Re: Obtener certificación oficial de "sun" en: 14 Octubre 2009, 04:24 am
guao tifa :D yo hice un curso de un año de java por parte de IBM y me dieron un vaucher para precentarlo ::) me dieron 7 meses para estudiar  :P
779  Programación / Java / Re: Como obtener la ruta de la llamada al programa (java)? en: 7 Octubre 2009, 06:22 am
ni yo pero creo q lo que dices es esto que cuando se ejecute te diga en que lugar fue ejecutado. y los archivos que se encuentran en ese directorio.

import java.io.File;
public class viw {
   public static void main(String[] args) {
      File file = new File(".");
      File file2 = new File(file.getAbsolutePath());
                System.out.println(file.getAbsolutePath());
      File[] list = file2.listFiles();
      for(File index: list){
         System.out.println(index.getName());
      }
   }
}

Saludos.
780  Programación / Java / Re: Ayuda GUI en: 13 Septiembre 2009, 07:48 am
-.- q te cuesta hacerlas desde 0  :P
Páginas: 1 ... 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 [78] 79
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines