package circulos;
import javax.swing.*;
import java.awt.*;
public class circulo extends java.applet.Applet {
int mouseX,mouseY;
boolean mouseClicked=false;
public void init(){
setBackground(Color.BLACK);
}
public boolean mouseDown(Event e,int x,int y){
mouseX=x;
mouseY=y;
mouseClicked=true;
repaint();
return true;
}
public void paint(Graphics g){
g.setColor(Color.WHITE);
if(mouseClicked){
g.fillOval(mouseX-5, mouseY-5, 10, 10);
mouseClicked=false;
}
}
public void update(Graphics g){
paint(g);
}
}
lunes, 23 de noviembre de 2009
bola de colores
import java.awt.*;
import javax.swing.*;
import java.awt.Event;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
public class demo extends JComponent{
private final static int ANCHO = 512;
private final static int ALTO = 384;
private final static int DIAMETRO = 20;
Color[] colores={Color.BLACK,Color.BLUE,Color.CYAN,Color.GRAY,Color.GREEN,Color.RED,Color.YELLOW,Color.PINK};
private float x, y;
private float vx, vy;
public demo() {
setPreferredSize(new Dimension(ANCHO, ALTO));
x = 50;
y = 70;
vx = 300;
vy = 400;
}
private void fisica(float dt) {
x += vx * dt;
y += vy * dt;
if (vx < 0 && x <= 0 || vx > 0 && x + DIAMETRO >= ANCHO)
vx = -vx;
if (vy < 0 && y < 0 || vy > 0 && y + DIAMETRO >= ALTO)
vy = -vy;
}
public void paint(Graphics g) {
g.setColor(colores[(int)(Math.random()*colores.length)]);
g.fillRect(0, 0, ANCHO, ALTO);
g.setColor(colores[(int)(Math.random()*colores.length)]);
g.fillRect(Math.round(x), Math.round(y), DIAMETRO, DIAMETRO);
}
private void dibuja() throws Exception {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
paintImmediately(0, 0, ANCHO, ALTO);
}
});
}
public void cicloPrincipalJuego() throws Exception {
long tiempoViejo = System.nanoTime();
while (true) {
long tiempoNuevo = System.nanoTime();
float dt = (tiempoNuevo - tiempoViejo) / 1000000000f;
tiempoViejo = tiempoNuevo;
fisica(dt);
dibuja();
}
}
}
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.*;
public class principal {
public static void main(String[] args) throws Exception {
JFrame jf = new JFrame("Demo1");
jf.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
jf.setResizable(false);
demo demo1 = new demo();
jf.getContentPane().add(demo1);
jf.pack();
jf.setVisible(true);
demo1.cicloPrincipalJuego();
}
}
import javax.swing.*;
import java.awt.Event;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
public class demo extends JComponent{
private final static int ANCHO = 512;
private final static int ALTO = 384;
private final static int DIAMETRO = 20;
Color[] colores={Color.BLACK,Color.BLUE,Color.CYAN,Color.GRAY,Color.GREEN,Color.RED,Color.YELLOW,Color.PINK};
private float x, y;
private float vx, vy;
public demo() {
setPreferredSize(new Dimension(ANCHO, ALTO));
x = 50;
y = 70;
vx = 300;
vy = 400;
}
private void fisica(float dt) {
x += vx * dt;
y += vy * dt;
if (vx < 0 && x <= 0 || vx > 0 && x + DIAMETRO >= ANCHO)
vx = -vx;
if (vy < 0 && y < 0 || vy > 0 && y + DIAMETRO >= ALTO)
vy = -vy;
}
public void paint(Graphics g) {
g.setColor(colores[(int)(Math.random()*colores.length)]);
g.fillRect(0, 0, ANCHO, ALTO);
g.setColor(colores[(int)(Math.random()*colores.length)]);
g.fillRect(Math.round(x), Math.round(y), DIAMETRO, DIAMETRO);
}
private void dibuja() throws Exception {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
paintImmediately(0, 0, ANCHO, ALTO);
}
});
}
public void cicloPrincipalJuego() throws Exception {
long tiempoViejo = System.nanoTime();
while (true) {
long tiempoNuevo = System.nanoTime();
float dt = (tiempoNuevo - tiempoViejo) / 1000000000f;
tiempoViejo = tiempoNuevo;
fisica(dt);
dibuja();
}
}
}
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.*;
public class principal {
public static void main(String[] args) throws Exception {
JFrame jf = new JFrame("Demo1");
jf.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
jf.setResizable(false);
demo demo1 = new demo();
jf.getContentPane().add(demo1);
jf.pack();
jf.setVisible(true);
demo1.cicloPrincipalJuego();
}
}
domingo, 1 de noviembre de 2009
public class mail1(MECHA)
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.MimeMessage;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.Message;
import javax.mail.internet.InternetAddress;
public class mail1 {
public mail1()throws Throwable{
Properties prop = new Properties();
//caracteristicas de la conexion
prop.setProperty("mail.smtp.host", "smtp.gmail.com");
//establecer el smtp
prop.setProperty("mail.smtp.starttls.enable","true");
//conexion sobre tunel ttls
prop.setProperty("mail.smtp.port", "587");
//puerto de salida
prop.setProperty("mail.smtp.user", "warning.mexa@gmail.com");
//nombre de la cuenta
prop.setProperty("mail.smtp.auth", "true");
//decimos que el servidor necesita una autentificacion
Session sesion= Session.getDefaultInstance(prop);
//creamos una sesion con los datos
MimeMessage mensaje = new MimeMessage(sesion);
//crear mensaje
mensaje.setFrom(new InternetAddress("warning.mexa@gmail.com"));
//emisor del correo
mensaje.addRecipient(Message.RecipientType.TO, new InternetAddress("argentos_ryu@hotmail.co.jp"));
//destinatario
mensaje.setSubject("prueba1");
mensaje.setText("prueba de mail 1");
//asunto y texto
Transport t= sesion.getTransport("smtp");
//pedimos los datos de la sesion
t.connect("warning.mexa@gmail.com","tuapapunchi");
//conectamos
t.sendMessage(mensaje, mensaje.getAllRecipients());
//mandamos el mensaje
t.close();
//cerramos la sesion;
}
}
import javax.mail.*;
import javax.mail.internet.MimeMessage;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.Message;
import javax.mail.internet.InternetAddress;
public class mail1 {
public mail1()throws Throwable{
Properties prop = new Properties();
//caracteristicas de la conexion
prop.setProperty("mail.smtp.host", "smtp.gmail.com");
//establecer el smtp
prop.setProperty("mail.smtp.starttls.enable","true");
//conexion sobre tunel ttls
prop.setProperty("mail.smtp.port", "587");
//puerto de salida
prop.setProperty("mail.smtp.user", "warning.mexa@gmail.com");
//nombre de la cuenta
prop.setProperty("mail.smtp.auth", "true");
//decimos que el servidor necesita una autentificacion
Session sesion= Session.getDefaultInstance(prop);
//creamos una sesion con los datos
MimeMessage mensaje = new MimeMessage(sesion);
//crear mensaje
mensaje.setFrom(new InternetAddress("warning.mexa@gmail.com"));
//emisor del correo
mensaje.addRecipient(Message.RecipientType.TO, new InternetAddress("argentos_ryu@hotmail.co.jp"));
//destinatario
mensaje.setSubject("prueba1");
mensaje.setText("prueba de mail 1");
//asunto y texto
Transport t= sesion.getTransport("smtp");
//pedimos los datos de la sesion
t.connect("warning.mexa@gmail.com","tuapapunchi");
//conectamos
t.sendMessage(mensaje, mensaje.getAllRecipients());
//mandamos el mensaje
t.close();
//cerramos la sesion;
}
}
Suscribirse a:
Entradas (Atom)