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

 

 


Tema destacado: Entrar al Canal Oficial Telegram de elhacker.net


  Mostrar Temas
Páginas: [1] 2 3
1  Programación / Java / Es posible hacer que el pc se prenda a cierta hora? en: 14 Diciembre 2011, 00:05 am
Hola, eso, quería saber si existe alguna librería o similar para java, de antemano gracias, saludos!
2  Programación / Bases de Datos / Es verdad que mysql es orientado a objetos? en: 2 Diciembre 2011, 23:10 pm
Eso, un profesor habló conmigo y dijo que mysql era orientado a objetos, que se podian crear clases y que las columnas podian guardar objetos, estuve buscando info relacionada y solo encontre clases php que manejan mysql, ¿es esto cierto o es parte de la descabellada fantasía de mi profesor o es mi ineptitud la que no me permitió encontrar documentacion?

De antemano, gracias por sus respuestas
3  Programación / PHP / [PHP + JSP] Es posible? en: 2 Diciembre 2011, 21:19 pm
Hola, estuve leyendo en un libro que se podía mezclar java con php, en el servidor tomcat, dejo el extracto del libro:

Introduccion:

Cita de: (2004) Php 5 And Mysql Bible

The relationship between PHP and Java has changed significantly
with each new release. Unsurprisingly, given the source code, PHP
initially had much more in common with C. PHP4 supported integration
of PHP and Java using a Java Servlet environment or, more experimentally,
directly into PHP. Finally, with the overhaul of the object
model in PHP5, there’s a distinctly Java feel to the PHP approach to
object oriented programming. Java users will find much of PHP5’s
new object model very familiar, though with important differences.
Given these changes, as PHP takes on a more Java-like cast, there are
two possibilities for which a discussion of PHP and Java might be
pertinent. You might need to work on a project that requires PHP and
Java or Java Server Pages (JSP) to work in tandem. Or you may be
approaching PHP from a Java background and want to know about
the similarities and differences in order to learn PHP faster. We will
deal with both needs in this chapter.
If you don’t have a need to use Java, or aren’t already


Expolicacion y ejemplo:

Cita de: (2004) Php 5 And Mysql Bible

Java Server Pages and PHP
PHP can fulfill many functions similarly to Java Server Pages (JSP). The JSP servlet engine
serves as a scripting language for use with Java, and, just as PHP, is often used in front end
applications.
Embedded HTML
PHP is more similar to JSP than Java itself in that you are allowed to write HTML directly
rather than using endless print statements. Unlike Java, but like JSP, variables can also be
referenced from within a block of HTML. A simple HTML page using JSP script might look
like this:
<%
String greeting = “Hello, world”;
%>
<HTML>
<HEAD>
<TITLE>Fun with JSP</TITLE>
</HEAD>
<BODY>
<H1><%= greeting %></H1>
</BODY>
</HTML>
Similarly, using PHP, you can write:
<?php
$greeting = “Hello, World”;
?>
<HTML>
<HEAD>
<TITLE>Fun with PHP</TITLE>
722 Part IV ✦ Connections
</HEAD>
<BODY>
<H1><?php echo $greeting ?></H1>
</BODY>
</HTML>
Pages can freely alternate between HTML and JSP, just as in using HTML and PHP.


De antemano, gracias por sus respuestas.

PD: Tengo el apache tomcat instalado, pero es la instalacion que viene por defecto, sinceramente no se por donde empezar, si alguien quiere el libro que me mande un mp y se lo mando por correo. 1083 paginas, esto de java+php empieza en la 719
4  Programación / Java / [Sockets] Sirven en internet? en: 2 Diciembre 2011, 21:07 pm
Hola, estuve viendo unos videotutoriales que me paso un amigo, el tipo se llama nikitus y enseña a crear una conexion con sockets, en el video muestra como hacer un pequeño xat, todo el codigo funka, pero me gustaria saber si es posible hacer que funke en internet, traté de poner mi direccion ip en el programa cliente y pasarselo a un amigo, pero no funciono, codeé en base al video, dos clases, un cliente y un server, en localhost corre bien, pero me gustaría saber, si es posible, que debo cambiarle para que funcione en internet, de antemano gracias.

Clase servidor:

Código
  1.  
  2. import java.net.ServerSocket;
  3. import java.net.Socket;
  4. import java.io.ObjectOutputStream;
  5. import java.io.IOException;
  6. import java.io.ObjectInputStream;
  7. import javax.swing.JOptionPane;
  8.  
  9. public class XServer {
  10.  
  11.  private ServerSocket ss;
  12. private Socket s;
  13. private ObjectOutputStream oos;
  14. private boolean isRunning=true;
  15. private ObjectInputStream ois;
  16. private volatile Command cmd=null;
  17.  
  18.  
  19.    XServer(){
  20.  
  21.          try{
  22.  
  23.     ss = new ServerSocket(9999);
  24.     s = ss.accept();
  25.     oos=new ObjectOutputStream(s.getOutputStream());
  26.     ois=new ObjectInputStream(s.getInputStream());
  27.  
  28.     }catch(IOException ioex){
  29.  
  30.      ioex.printStackTrace();
  31.  
  32.     }
  33.  
  34. this.sender();
  35. this.receiver();
  36. this.dealReceive();
  37. this.autoClose();
  38.  
  39.    }
  40.  
  41.    void sender(){
  42.  
  43. Thread t=new Thread(new Runnable(){
  44.  
  45.  public void run(){
  46.  
  47.   while(XServer.this.isRunning){
  48.  
  49.    int type=0;
  50.  
  51.    try{
  52.  
  53.  String msg=JOptionPane.showInputDialog("Mensaje para el Cliente");
  54.  
  55.   Command c=new Command();
  56.  
  57.   c.setMsg(msg);
  58.  
  59.   type=(msg.equalsIgnoreCase("Close"))? 0:1;
  60.  
  61.   c.setType(type);
  62.  
  63.   oos.writeObject(c);
  64.  
  65.  }catch(IOException ex) {
  66.  
  67.   ex.printStackTrace();
  68.  
  69.  }
  70.  
  71.    if(type==0){
  72.  
  73.     break;
  74.  
  75.    }
  76.  
  77.   }
  78.  
  79.  }
  80.  
  81. });
  82.  
  83. t.start();
  84.  
  85.    }
  86.  
  87.    void receiver(){
  88.  
  89.    Thread t=new Thread(new Runnable(){
  90.  
  91.     public void run(){
  92.  
  93.      while(XServer.this.isRunning){
  94.  
  95.        try{
  96.  
  97.      Thread.sleep(1000);
  98.  
  99.      Object aux=ois.readObject();
  100.  
  101.      if(aux!=null && aux instanceof Command){
  102.  
  103.        XServer.this.cmd = (Command) aux;
  104.  
  105.      }
  106.  
  107.     }catch(InterruptedException intex){
  108.  
  109.      intex.printStackTrace();
  110.  
  111.     }catch(IOException ioex){
  112.  
  113.      ioex.printStackTrace();
  114.  
  115.     }catch(ClassNotFoundException classex){
  116.  
  117.      classex.printStackTrace();
  118.  
  119.     }
  120.  
  121.      }
  122.  
  123.     }
  124.  
  125.    });
  126.  
  127.    t.start();
  128.  
  129.    }
  130.  
  131.    void dealReceive(){
  132.  
  133.     Thread t=new Thread(new Runnable(){
  134.  
  135.      public void run(){
  136.  
  137.       while(XServer.this.isRunning){
  138.  
  139.       try{
  140.  
  141.        Thread.sleep(1000);
  142.  
  143.        Command c=XServer.this.cmd;
  144.  
  145.        if(c.getType().equals("Message")){
  146.  
  147.         System.out.println(c.getMsg());
  148.  
  149.        }else if(c.getType().equals("Action") && c.getMsg().equals("Close")){
  150.  
  151.         XServer.this.isRunning=false;
  152.  
  153.        }
  154.  
  155.     }catch(InterruptedException intex){
  156.  
  157.      intex.printStackTrace();
  158.  
  159.     }catch(NullPointerException nullex){
  160.  
  161.     }finally{
  162.  
  163.       XServer.this.cmd=null;
  164.  
  165.     }
  166.  
  167.     }
  168.  
  169.      }
  170.  
  171.     });
  172.  
  173.     t.start();
  174.  
  175.    }
  176.  
  177.    void autoClose(){
  178.  
  179. Thread t=new Thread(new Runnable(){
  180.  
  181.  public void run(){
  182.  
  183.   while(true){
  184.  
  185.    try{
  186.  
  187.     Thread.sleep(200);
  188.  
  189.     if(!XServer.this.isRunning){
  190.  
  191.      XServer.this.ois.close();
  192.      XServer.this.oos.close();
  193.      XServer.this.s.close();
  194.  
  195.     }
  196.  
  197.    }catch(InterruptedException intex){
  198.  
  199.     intex.printStackTrace();
  200.  
  201.    }catch(IOException ioex){
  202.  
  203.     ioex.printStackTrace();
  204.  
  205.    }
  206.  
  207.   }
  208.  
  209.  }
  210.  
  211. });
  212.  
  213. t.start();
  214.  
  215. }
  216.  
  217. }
  218.  
  219.  
  220.  

Clase cliente:

Código
  1.  
  2. import java.net.Socket;
  3. import java.io.ObjectOutputStream;
  4. import java.io.IOException;
  5. import java.io.ObjectInputStream;
  6. import javax.swing.JOptionPane;
  7.  
  8. public class XClient {
  9.  
  10.  private Socket s;
  11. private ObjectOutputStream oos;
  12. private boolean isRunning=true;
  13. private ObjectInputStream ois;
  14. private volatile Command cmd=null;
  15.  
  16.  
  17.    XClient(){
  18.  
  19.               try{
  20.  
  21.     s=new Socket("10.5.4.124", 9999);
  22.     oos=new ObjectOutputStream(s.getOutputStream());
  23.     ois=new ObjectInputStream(s.getInputStream());
  24.  
  25.     }catch(IOException ioex){
  26.  
  27.      ioex.printStackTrace();
  28.  
  29.     }
  30.  
  31.               this.sender();
  32.               this.receiver();
  33.               this.dealReceive();
  34.               this.autoClose();
  35.  
  36.    }
  37.  
  38.    void receiver(){
  39.  
  40.    Thread t=new Thread(new Runnable(){
  41.  
  42.     public void run(){
  43.  
  44.      while(XClient.this.isRunning){
  45.  
  46.        try{
  47.  
  48.      Thread.sleep(1000);
  49.  
  50.      Object aux=ois.readObject();
  51.  
  52.      if(aux!=null && aux instanceof Command){
  53.  
  54.        XClient.this.cmd = (Command) aux;
  55.  
  56.      }
  57.  
  58.     }catch(InterruptedException intex){
  59.  
  60.      intex.printStackTrace();
  61.  
  62.     }catch(IOException ioex){
  63.  
  64.      ioex.printStackTrace();
  65.  
  66.     }catch(ClassNotFoundException classex){
  67.  
  68.      classex.printStackTrace();
  69.  
  70.     }
  71.  
  72.      }
  73.  
  74.     }
  75.  
  76.    });
  77.  
  78.    t.start();
  79.  
  80.    }
  81.  
  82.        void dealReceive(){
  83.  
  84.     Thread t=new Thread(new Runnable(){
  85.  
  86.      public void run(){
  87.  
  88.       while(XClient.this.isRunning){
  89.  
  90.       try{
  91.  
  92.        Thread.sleep(1000);
  93.  
  94.        Command c=XClient.this.cmd;
  95.  
  96.        if(c.getType().equals("Message")){
  97.  
  98.         System.out.println(c.getMsg());
  99.  
  100.        }else if(c.getType().equals("Action") && c.getMsg().equals("Close")){
  101.  
  102.         XClient.this.isRunning=false;
  103.  
  104.        }
  105.  
  106.     }catch(InterruptedException intex){
  107.  
  108.      intex.printStackTrace();
  109.  
  110.     }catch(NullPointerException nullex){
  111.  
  112.     }finally{
  113.  
  114.       XClient.this.cmd=null;
  115.  
  116.     }
  117.  
  118.     }
  119.  
  120.      }
  121.  
  122.     });
  123.  
  124.     t.start();
  125.  
  126.    }
  127.  
  128. void sender(){
  129.  
  130. Thread t=new Thread(new Runnable(){
  131.  
  132.  public void run(){
  133.  
  134.   while(XClient.this.isRunning){
  135.  
  136.    int type=0;
  137.  
  138.    try{
  139.  
  140.  String msg=JOptionPane.showInputDialog("Mensaje para el Server");
  141.  
  142.   Command c=new Command();
  143.  
  144.   c.setMsg(msg);
  145.  
  146.   type=(msg.equalsIgnoreCase("Close"))? 0:1;
  147.  
  148.   c.setType(type);
  149.  
  150.   oos.writeObject(c);
  151.  
  152.  }catch(IOException ex) {
  153.  
  154.   ex.printStackTrace();
  155.  
  156.  }
  157.  
  158.    if(type==0){
  159.  
  160.     break;
  161.  
  162.    }
  163.  
  164.   }
  165.  
  166.  }
  167.  
  168. });
  169.  
  170. t.start();
  171.  
  172.    }
  173.  
  174. void autoClose(){
  175.  
  176. Thread t=new Thread(new Runnable(){
  177.  
  178.  public void run(){
  179.  
  180.   while(true){
  181.  
  182.    try{
  183.  
  184.     Thread.sleep(200);
  185.  
  186.     if(!XClient.this.isRunning){
  187.  
  188.      XClient.this.ois.close();
  189.      XClient.this.oos.close();
  190.      XClient.this.s.close();
  191.  
  192.     }
  193.  
  194.    }catch(InterruptedException intex){
  195.  
  196.     intex.printStackTrace();
  197.  
  198.    }catch(IOException ioex){
  199.  
  200.     ioex.printStackTrace();
  201.  
  202.    }
  203.  
  204.   }
  205.  
  206.  }
  207.  
  208. });
  209.  
  210. t.start();
  211.  
  212. }
  213.  
  214. }
  215.  
  216.  

Se me olvidaba, para lo que quiero hacer despues de aprender a manipular sockets en internet creé una clase comando, que en el futuro me servirá para mandar solo strings con referencias a lo que se debe hacer y no mandar objetos pesados a traves de la conexion, esta es la clase:

Código
  1.  
  2. import java.io.Serializable;
  3.  
  4. public class Command implements Serializable{
  5.  
  6. private String[] types={"Action", "Message", "Dialog", "Input", "Warning", "Error"};
  7. private String[] actions={"Close"};
  8.  
  9. private String type="";
  10. private String msg="";
  11.  
  12.    Command(){
  13.  
  14.     this.type= types[1];
  15.  
  16.    }
  17.  
  18.    Command(String msg){
  19.  
  20.     this.type=this.types[0];
  21.     this.msg=msg;
  22.  
  23.    }
  24.  
  25.    Command(String msg, int type){
  26.  
  27.     this.type=this.types[type];
  28.     this.msg=msg;
  29.  
  30.    }
  31.  
  32. public String getMsg() {
  33.  return msg;
  34. }
  35.  
  36. void setDialog(String msg){
  37.  
  38.  this.msg=msg;
  39.  this.type=types[2];
  40.  
  41. }
  42.  
  43. void setInput(String msg){
  44.  
  45.  this.msg=msg;
  46.  this.type=types[3];
  47.  
  48. }
  49.  
  50. void setWarning(String msg){
  51.  
  52.  this.msg=msg;
  53.  this.type=types[4];
  54.  
  55. }
  56.  
  57. void setError(String msg){
  58.  
  59.  this.msg=msg;
  60.  this.type=types[5];
  61.  
  62. }
  63.  
  64. public void setMsg(String msg) {
  65.  this.msg = msg;
  66. }
  67.  
  68. public void setType(int i){
  69.  
  70.  this.type=this.types[i];
  71.  
  72. }
  73.  
  74. public String getType(){
  75.  
  76.  return this.type;
  77.  
  78. }
  79.  
  80.  
  81.  
  82. }
  83.  
  84.  
  85.  


Bueno, de antemano agradezco muchísimo vuestras respuestas, saludos
5  Programación / Bases de Datos / [MYSQL] Otra forma de hacer esta consulta? en: 11 Noviembre 2011, 21:45 pm
Hola, tengo la siguiente base de datos en mysql:

Código
  1.  
  2. CREATE DATABASE IF NOT EXISTS verduleros;
  3.  
  4. DROP TABLE IF EXISTS ventas2;
  5.  
  6. CREATE TABLE ventas2(
  7.  
  8. idventa INT NOT NULL PRIMARY KEY,
  9. vendedor VARCHAR(255) NOT NULL,
  10. producto VARCHAR(255) NOT NULL,
  11. fecha DATE NOT NULL,
  12. kilos INT NOT NULL
  13.  
  14. )engine=innodb;
  15.  
  16.  


La consulta que quiero realizar segun el planteamiento es:

"Desplegar la suma de los kilos de cada producto que ha vendido cada vendedor"

Para ello pense en la siguiente consulta:

Código
  1. SELECT v.vendedor, v.producto,
  2. SUM(v.kilos)
  3. FROM ventas2 AS v
  4. WHERE v.kilos IN
  5. (SELECT kilos FROM ventas2 WHERE vendedor=v.vendedor AND
  6. producto=v.producto)
  7. GROUP BY vendedor
  8. ;
  9.  

El problema es que la base de datos es muy grande xD, probé la lógica de esta
consulta en una tabla pequeña y funciona, pero en la base de datos que nos entregó el profe esperé alrededor de unos 20 minutos y no me mostró nada,
lo intenté en reiteradas veces, probé a reiniciar el pc y nada, la base de datos es muy grande por lo tanto no puedo hacer esto con subconsultas (y, pensandolo, si la consulta por si sola se demora, hacer por cada fila una subconsulta es descabellado xD), se los agradecería enormemente si es posible hacer esto de otra forma.

Saludos!
6  Programación / PHP / [PHP-MYSQL] Como crear un sp en php? en: 1 Noviembre 2011, 02:03 am
Hola estoy intentando crear un procedimiento almacenado desde php a mysql, que estoy haciendo mal?

Código
  1.  
  2. <html>
  3. <head>
  4. </head>
  5. <body>
  6.        <?php
  7.  
  8.        mysql_connect("localhost", "root", "sr388");
  9.  
  10.        $b=mysql_query("
  11. create procedure pedir(in strCodBicicleta varchar(255), in strCodPeticion varchar(255), in strCodUsuario varchar(255))
  12. begin
  13.  
  14. update bicicleta set estado='usando' where cod_bicicleta=strCodBicicleta;
  15.  
  16. insert into peticion(cod_peticion, usuario, fecha, hora)values(strCodPeticion, strCodUsuario, current_date, current_time);
  17.  
  18. end
  19. ");
  20.  
  21.        if($b){
  22.  
  23.            echo "funka";
  24.  
  25.        }else{
  26.  
  27.            echo "T_T";
  28.  
  29.        }
  30.  
  31.        ?>
  32. </body>
  33. </html>
  34.  
  35.  



Dejo las tablas bicicleta, peticion y usuario:

Código
  1.  
  2. create table usuario(
  3.  
  4. username varchar(255) not null primary key,
  5. permisos varchar(4) not null, -- 'ADM' o 'USER'
  6. e_mail varchar(255) not null
  7.  
  8.  
  9.  

Código
  1.  
  2. create table bicicleta(
  3.  
  4. cod_bicicleta varchar(255) not null primary key,
  5. estado varchar(6) not null -- 'usando' o 'libre'
  6.  
  7.  
  8.  

Código
  1.  
  2. create table peticion(
  3.  
  4. usuario varchar(255) not null references usuario(username),
  5. fecha date not null,
  6.  
  7.  
  8.  
  9.  

De antemano, gracias

PD: en la shell funka con el uso de delimiter
7  Programación / PHP / [MYSQL] Error con consulta [SOLUCIONADO] en: 31 Octubre 2011, 05:52 am
Hola tengo un problemilla con la sintaxis de una funcion, me he qebrado la cabeza todo el dia tratando de ver que es, se supone que hay un registro que tiene el dato 'BC3' que debiera tomar la consulta "select * from b_disponibles" (la cual es una vista), el caso es que al mostrar me muestra 0

me conecto a la base de datos de tal forma:

He probado mostrar si la conexion funka, me muestra que si

Código
  1.  
  2. mysql_connect("localhost", "root", "");
  3.  
  4. mysql_query("use providencia");
  5.  
  6.  

La funcion que me retorna el resultset es la siguiente:

Código
  1.  
  2. function getAvailableBicicles(){
  3.  
  4.                $r = mysql_query("select * from b_disponibles");
  5.  
  6.                return $r;
  7.  
  8. }
  9.  
  10.  

Luego trato de hacer lo tipico con el resultset:

Código
  1.  
  2. $row2=getAvailableBicicles();
  3.  
  4.            while($fila = mysql_fetch_array($row2)){
  5.  
  6.                $val = $fila['cod_bicicleta'];
  7.  
  8.            echo $val," <br>";
  9.  
  10.            }
  11.  
  12.  

El nombre de la columna esta bien escrito, he probado con fetch_assoc, fetch_row y nada, me muestra 0 siendo que en la tabla no hay ningun registro con ese valor  :P

Dejo la tabla bicicletas:

Código
  1.  
  2. create table bicicleta(
  3.  
  4. cod_bicicleta varchar(255) not null primary key,
  5. estado varchar(6) not null -- 'usando' o 'libre'
  6.  
  7.  
  8.  

La vista bicicletas libres:

Código
  1.  
  2. create view b_disponibles as
  3. select * from bicicleta where estado ='libre';
  4.  
  5.  

Finalmente los inserts:

Código
  1.  
  2. insert into bicicleta(cod_bicicleta, estado)values('bc1', 'usando');
  3. insert into bicicleta(cod_bicicleta, estado)values('bc2', 'usando');
  4. insert into bicicleta(cod_bicicleta, estado)values('bc3', 'libre');
  5.  
  6.  

Antes de la creacion de las tablas esta la creacion de bases de datos y su uso xD (por si acaso)

Código
  1.  
  2. drop database if exists providencia;
  3. create database providencia;
  4. use providencia;
  5.  
  6.  

De antemano, gracias por sus respuestas.

PD: En la shell de mysql funka  :-\
8  Programación / PHP / Header, como se usa en: 11 Octubre 2011, 23:43 pm
Buenas, he visto que para redireccionar a una pag despues de cierto tiempo usan:

header("Location: pagina.php");

El caso es que no me funka cuando trabajo en la misma pagina, ¿esta mal trabajar con un solo archivo php?

De antemano, gracias, saludos!
9  Programación / Java / [GregorianCalendar] ¿Como saber cual es el primer día del mes? en: 23 Agosto 2011, 01:41 am
Hola, estoy haciendo una aplicación para manejar horarios, la gui la hice de tal forma que al pasarle desde donde hasta donde son los días del mes de x año me genera una ventana con los 42 JLabels con su día asignado, ahora bien, lo que necesito es cómo saber que día empieza x mes, para esto creé una subclase de GregorianCalendar, a la cual llamé ZCalendar, los métodos más importantes que me interesería saber si están bien hechos son getFirtsDayOfMonth() y getLastDayOfMonth(), lo que pasa es que a veces se me corre un día el calendario si pudieran decirme que estoy haciendo mal estaría bastante agradecido.

Código
  1. package horario;
  2.  
  3. import java.util.HashMap;
  4. import java.util.Calendar;
  5. import java.util.GregorianCalendar;
  6. /**
  7.  * Clase para obtener los datos necesarios para construir la interfaz grafica <code> Meses </code>
  8.  *
  9.  * @param año Los datos del objeto se crearan a pertir del año dado
  10.  * @param mes Los datos del objeto se crearan a pertir del mes dado
  11.  * @author Zero
  12.  */
  13. public class ZCalendar extends GregorianCalendar{
  14.  
  15.    Calendar g=GregorianCalendar.getInstance();
  16.  
  17.    int[] dias={g.MONDAY, g.TUESDAY, g.WEDNESDAY,g.THURSDAY,g.FRIDAY,g.SATURDAY,g.SUNDAY};
  18.  
  19.    /**
  20.      * Arreglo utilizado para saber que día termina cada mes del año
  21.      */
  22.    int[] last={31, 28, 31,30,31,30,31,31,30,31,30,31};
  23.  
  24.    /**
  25.      * Indica el año con que se construye este objeto
  26.      */
  27.    int y=0;
  28.  
  29.    /**
  30.      * Usado para conocer que indice tendra cada mes del año en el arreglo <code>last[]</code>
  31.      */
  32.    HashMap<Integer, String> mez=null;
  33.  
  34.    /**
  35.      * Indica el mes con que se construye este objeto
  36.      */
  37.    int m=0;
  38.  
  39.    /**
  40.      * Indica el primer día del mes
  41.      */
  42.    int first=0;
  43.  
  44.    ZCalendar(int año, int mes){
  45.  
  46.        this.set(ZCalendar.YEAR, año);
  47.        this.set(ZCalendar.MONTH, mes);
  48.  
  49.        m=mes;
  50.  
  51.        mez=new HashMap<Integer, String>();
  52.  
  53.        y=año;
  54.  
  55.        int w=0;
  56.  
  57.        mez.put(w, "Enero"); w++;
  58.        mez.put(w, "Febrero"); w++;
  59.        mez.put(w, "Marzo"); w++;
  60.        mez.put(w, "Abril"); w++;
  61.        mez.put(w, "Mayo"); w++;
  62.        mez.put(w, "Junio"); w++;
  63.        mez.put(w, "Julio"); w++;
  64.        mez.put(w, "Agosto"); w++;
  65.        mez.put(w, "Septiembre"); w++;
  66.        mez.put(w, "Octubre"); w++;
  67.        mez.put(w, "Noviembre"); w++;
  68.        mez.put(w, "Diciembre"); w++;
  69.  
  70.  
  71.  
  72.  
  73.    }
  74.  
  75.    /**
  76.      * Devuelve la posicion del <code>ZLabel</code> desde donde empezarán los días del mes
  77.      */
  78.    int getFirstDayOfMonth(){
  79.  
  80.        int d=0;
  81.  
  82.        this.set(this.DAY_OF_MONTH, this.DAY_OF_MONTH - this.DAY_OF_MONTH);
  83.  
  84.        d=this.get(this.DAY_OF_WEEK);
  85.  
  86.        d++;
  87.  
  88.        first=d;
  89.  
  90.        return d;
  91.  
  92.    }
  93.  
  94.    /**
  95.      * Devuelve la posicion del <code>ZLabel</code> en donde terminarán los días del mes
  96.      */
  97. int getLastDayOfTheMonth(){
  98.  
  99.    int x=0;
  100.  
  101.    if(m==1){
  102.  
  103.        return inFeb();
  104.  
  105.    }
  106.  
  107.    if(last[m]==30){
  108.  
  109.        return in30();
  110.  
  111.    }
  112.  
  113.    if(last[m]==31){
  114.  
  115.        return in31();
  116.  
  117.    }
  118.  
  119.    return x;
  120.  
  121.    }
  122.  
  123. private int in30(){
  124.  
  125.    switch(first){
  126.  
  127.        case 0:
  128.        return 29;
  129.        case 1:
  130.        return 30;
  131.        case 2:
  132.        return 31;
  133.        case 3:
  134.        return 32;
  135.        case 4:
  136.        return 33;
  137.        case 5:
  138.        return 34;
  139.        case 6:
  140.        return 35;
  141.        case 7:
  142.        return 36;
  143.  
  144.    }
  145.  
  146.    return 10;
  147.  
  148. }
  149.  
  150. private int in31(){
  151.  
  152.    switch(first){
  153.  
  154.        case 0:
  155.        return 30;
  156.        case 1:
  157.        return 31;
  158.        case 2:
  159.        return 32;
  160.        case 3:
  161.        return 33;
  162.        case 4:
  163.        return 34;
  164.        case 5:
  165.        return 35;
  166.        case 6:
  167.        return 36;
  168.        case 7:
  169.        return 37;
  170.  
  171.  
  172.    }
  173.  
  174.    return 10;
  175.  
  176. }
  177.  
  178. private int inFeb(){
  179.  
  180.    if(isBis(y)){
  181.  
  182.        switch(first){
  183.  
  184.            case 0:
  185.            return 28;
  186.            case 1:
  187.            return 29;
  188.            case 2:
  189.            return 30;
  190.            case 3:
  191.            return 31;
  192.            case 4:
  193.            return 32;
  194.            case 5:
  195.            return 33;
  196.            case 6:
  197.            return 34;
  198.            case 7:
  199.            return 35;
  200.  
  201.        }
  202.  
  203.    }else{
  204.  
  205.        switch(first){
  206.  
  207.            case 0:
  208.            return 27;
  209.            case 1:
  210.            return 28;
  211.            case 2:
  212.            return 29;
  213.            case 3:
  214.            return 30;
  215.            case 4:
  216.            return 31;
  217.            case 5:
  218.            return 32;
  219.            case 6:
  220.            return 33;
  221.            case 7:
  222.            return 34;
  223.  
  224.  
  225.        }
  226.  
  227.    }
  228.  
  229.    return 10;
  230.  
  231. }
  232.  
  233. /**
  234.      * Devuelve <code>true</code> si <code>x</code> es multiplo de 4
  235.  *
  236.  * @param x Representa el año que se desea saber si es bisiesto
  237.      */
  238. boolean isBis(int x){
  239.  
  240.        if(x%4==0){
  241.        return true;
  242.        }else{
  243.        return false;
  244.        }
  245.  
  246.    }
  247.  
  248. /**
  249.      * Devuelve el nombre del mes correspondiente
  250.  *
  251.  * @return m El nombre del mes con el que se construye este objeto
  252.      */
  253. String getMonthName(){
  254.  
  255.    return mez.get(this.m);
  256.  
  257. }
  258.  
  259. /**
  260.      * Devuelve el año correspondiente
  261.  *
  262.  * @return m El año con el que se construye este objeto
  263.      */
  264. String getYearName(){
  265.  
  266.    return y+"";
  267.  
  268. }
  269.  
  270. }
  271.  
  272.  

Saludos
10  Programación / Java / [VBS] ¿Como hacer esto en java? [InternetExplorer.application] en: 30 Julio 2011, 01:09 am
Hola, bueno verán, quiero mostrar un code en vbs, lo explicaré paso a paso y me gustaría saber si es posible hacer lo mismo en java

Código
  1. set ie=createobject("internetexplorer.application")
  2. 'se crea un objeto para manipular el internetexplorer
  3.  
  4. ie.navigate("http://www.google.com")
  5. 'como podran imaginar se navega en la url dada
  6.  
  7. s=inputbox("Ingresa tu busqueda")
  8. ' se abre un cuadro de dialogo para ingresar un valor del usuario
  9.  
  10. ie.visible=true
  11. 'se hace visible la ventana del explorer
  12.  
  13. do
  14. 'ok este bucle sirve para que, si el internetexplorer se está cargando, esperar
  15. 'nada más
  16.  
  17. if ie.busy then
  18.  
  19. wscript.sleep 5000
  20.  
  21. else
  22.  
  23. exit do
  24.  
  25. end if
  26.  
  27. loop
  28.  
  29. set b=ie.document.getelementbyid("lst-ib")
  30. 'se obtiene la barra de texto de google
  31.  
  32. b.value=s
  33. 'se escribe lo que el usuario ingresó en la barra
  34.  
  35. set b2=ie.document.getelementbyid("btnG")
  36. 'se obtiene el boton "buscar con google"
  37.  
  38. b2.click()
  39. 'se hace click en el boton "buscar con google"
  40.  
  41.  

Existe alguna forma de hacer lo mismo con java?

Que librerías me recomiendan investigar?

De antemano, gracias  :D

Saludos  ;)
Páginas: [1] 2 3
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines