jueves, 29 de octubre de 2009

getSistemaOperativo(): String - v2

public static String getSistemaOperativo(){
return System.getProperty("os.name");
}

getSistemaOperativo()

import java.util.Properties;
import java.util.Vector;

public class busquedas {

public String getSistemaOperativo(){

String res="";

Properties p= System.getProperties();
Vector v= new Vector();

String s=p.toString();
String[] ss=s.split("=");

for(String elem:ss)
v.add(elem);
s=v.toString();
ss=s.split(" ");

v.clear();

for(String elem:ss)
v.add(elem);

for(int i=0;i
if(v.get(i).equals("Windows"))
res="Windows";
if(v.get(i).equals("Linux"))
res="Linux";
if(v.get(i).equals("Ubuntu"))
res="Ubuntu";
if(v.get(i).equals("Mac"))
res="Mac";

}

return res;

}

}

//queda probarlo en sistemas operativos distintos a windows

martes, 27 de octubre de 2009

exec(String cmd): void

//ejecuta el comando pasado como cmd en la consola del sistema

public static void exec(String cmd) {
try {
Runtime.getRuntime().exec(cmd);
} catch (IOException e) {
System.out.println("Failed");
}
}

equals(Object o): boolean

//sirve para cualquier clase con el metodo hashcode(): int definido
//no probado

public boolean equals(Object o){
boolean res=false;
res=this.hashCode()==this.getClass().cast(o).hashCode();
return res;
}

lunes, 26 de octubre de 2009

creaInteger(String num): Integer

public static Integer creaInteger(String num){
/* Devuelve el Integer que se le pase como String
* Pensado para numeros positivos con signo (ej.: +25)
* PROBADO
*/
if(num.startsWith("+"))
num=num.replace('+','0');
return new Integer(num);
}

--Índice--

A

B

Bola de colores

C
creaInteger(String num): Integer



D

E
equals(Object o): boolean
exec(String cmd): void

F

G
getSistemaOperativo()
getSistemaOperativo(): String - v2

H

I
Imagenes de fondo

J

K

L

M
envio de correos(mecha)

N

Ñ

O

P
puntos chorras

Q

R

S

T
trabajarFicheros

U

V

W

X

Y

Z

Imagen fondo (clase extends JPanel)

package pruebasconimagenes;

import javax.swing.*;
import java.awt.*;
import java.applet.*;

public class PnlFondo extends javax.swing.JPanel{

public PnlFondo(){
//initComponents();

this.setSize(100,100);
Icon imgBoton = new ImageIcon(getClass().getResource("/pruebasconimagenes/bombay.jpg"));

}

public void paintComponent(Graphics g){

Dimension tamaño= getSize();
ImageIcon imagenFondo= new ImageIcon(getClass().getResource("/pruebasconimagenes/bombay.jpg"));
g.drawImage(imagenFondo.getImage(),0,0,imagenFondo.getImage().getWidth(this),imagenFondo.getImage().getHeight(this),null);
setOpaque(false);

super.paintComponent(g);

}

}

package pruebasconimagenes;

import java.applet.*;
import java.awt.*;

public class FrmPrincipal extends javax.swing.JFrame {

public FrmPrincipal(){

PnlFondo pnlFondo= new PnlFondo();
this.add(pnlFondo, BorderLayout.CENTER);
this.pack();

}

}


package pruebasconimagenes;

public class claseprincipal {

public static void main(String[]args){

FrmPrincipal uno=new FrmPrincipal();
uno.setVisible(true);

}

}

TrabajarFicheros (clase)

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.Vector;

public class TrabajarFicheros {
public static Vector ficherosCarpeta(String ruta){
Vector res=new Vector();
String[] aux=new File(ruta).list();
for(String elem:aux)
res.add(elem);
return res;
}

public static void creaCarpeta(String ruta,String nombre){
File dir = new File(ruta+nombre);
dir.mkdir();
}

public static void creaFichero(String ruta, String contenido)throws Throwable {
FileWriter fichero = null;
PrintWriter pw = null;
try {
fichero = new FileWriter(ruta);
pw = new PrintWriter(fichero);
pw.println(contenido);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (null != fichero)
fichero.close();
} catch (Exception e2) {
e2.printStackTrace();
}
}
}

public static Vector leeFichero(String ruta) {
File archivo = null;
FileReader fr = null;
BufferedReader br = null;
Vector res=new Vector();

try {
archivo = new File(ruta);
fr = new FileReader(archivo);
br = new BufferedReader(fr);
String linea;
while ((linea = br.readLine()) != null){
res.add(linea);
System.out.println(linea);
}
}
catch (Exception e) {
e.printStackTrace();
}
finally {
try {
if (null != fr) {
fr.close();
}
}
catch (Exception e2) {
e2.printStackTrace();
}
}
return res;
}

public static void borraFichero(String ruta) {
File fichero = new File(ruta);
fichero.delete();
}

public static void editaFichero(String ruta, String contenido) {
FileWriter fichero = null;
PrintWriter pw = null;
try {
fichero = new FileWriter(ruta);
pw = new PrintWriter(fichero);
pw.println(contenido);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (null != fichero)
fichero.close();
} catch (Exception e2) {
e2.printStackTrace();
}
}
}
}