Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.applet.*;
- public class MyApp extends Applet
- {
- BorderLayout esquemaOrdena;
- Panel panHerr, panCol;
- Button btnBlanco, btnNegro, btnGris, btnRojo, btnAzul, btnRosa, btnNaranja, btnVerde;
- Button btnLapiz, btnAerografo, btnOvalo, btnOvaloRell, btnRec, btnRecRell, btnLinea, btnBorrar;
- Label lblEste, lblOeste, lblCol;
- Graphics g = getGraphics();
- Point inicioLinea = new Point(0,0);
- String strHerr = "Lapiz", strCol = "Negro";
- int diaCirculo = 5, x1, x2,y1, y2, x3, x4, y3, y4, xx, yy;
- public void init()
- {
- //--- METODO DE ORDENACION ---//
- esquemaOrdena = new BorderLayout(0,0);
- setLayout(esquemaOrdena);
- lblEste = new Label();
- lblOeste = new Label();
- lblEste.setBackground(Color.gray);
- lblOeste.setBackground(Color.gray);
- add("West", lblOeste);
- add("East", lblEste);
- /*--- PANEL ---*/
- panHerr = new Panel();
- panCol = new Panel();
- panHerr.setBackground(Color.gray);
- panCol.setBackground(Color.gray);
- add("North", panHerr);
- add("South", panCol);
- /*--- HERRAMIENTAS ---*/
- setForeground(Color.blue);
- btnLapiz = new Button("Lapiz");
- btnAerografo = new Button("Aerografo");
- btnLinea = new Button("Linea");
- btnOvalo = new Button("Ovalo");
- btnOvaloRell = new Button("Ovalo Relleno");
- btnRec = new Button("Rectangulo");
- btnRecRell = new Button("Rectangulo Relleno");
- btnBorrar = new Button("Borrar");
- panHerr.add(btnLapiz);
- panHerr.add(btnAerografo);
- panHerr.add(btnLinea);
- panHerr.add(btnOvalo);
- panHerr.add(btnOvaloRell);
- panHerr.add(btnRec);
- panHerr.add(btnRecRell);
- panHerr.add(btnBorrar);
- /*--- COLORES ---*/
- lblCol =new Label("COLORES");
- lblCol.setForeground(Color.black);
- btnBlanco = new Button(" B ");
- btnBlanco.setBackground(Color.white);
- btnBlanco.setForeground(Color.white);
- btnNegro = new Button(" N ");
- btnNegro.setBackground(Color.black);
- btnNegro.setForeground(Color.black);
- btnGris = new Button(" G ");
- btnGris.setBackground(Color.gray);
- btnGris.setForeground(Color.gray);
- btnRojo = new Button(" R ");
- btnRojo.setBackground(Color.red);
- btnRojo.setForeground(Color.red);
- btnAzul = new Button(" A ");
- btnAzul.setBackground(Color.blue);
- btnAzul.setForeground(Color.blue);
- btnRosa = new Button(" P ");
- btnRosa.setBackground(Color.pink);
- btnRosa.setForeground(Color.pink);
- btnNaranja = new Button(" O ");
- btnNaranja.setBackground(Color.orange);
- btnNaranja.setForeground(Color.orange);
- btnVerde = new Button(" V ");
- btnVerde.setBackground(Color.green);
- btnVerde.setForeground(Color.green);
- panCol.add(lblCol);
- panCol.add(btnBlanco);
- panCol.add(btnNegro);
- panCol.add(btnGris);
- panCol.add(btnRojo);
- panCol.add(btnAzul);
- panCol.add(btnRosa);
- panCol.add(btnNaranja);
- panCol.add(btnVerde);
- }
- public boolean action( Event evt, Object obj)
- {
- if(evt.target instanceof Button)
- {
- /*--- HERRAMIENTAS ---*/
- if("Lapiz".equals(obj))
- {
- strHerr = "Lapiz";
- }
- if("Aerografo".equals(obj))
- {
- strHerr = "Aerografo";
- }
- if("Linea".equals(obj))
- {
- strHerr = "Linea";
- }
- if("Ovalo".equals(obj))
- {
- strHerr = "Ovalo";
- }
- if("Ovalo Relleno".equals(obj))
- {
- strHerr = "Ovalo Relleno";
- }
- if("Rectangulo".equals(obj))
- {
- strHerr = "Rectangulo";
- }
- if("Rectangulo Relleno".equals(obj))
- {
- strHerr = "Rectangulo Relleno";
- }
- if("Borrar".equals(obj))
- {
- repaint();
- }
- /*--- COLORES ---*/
- if(" B ".equals(obj))
- {
- strCol = "Blanco";
- }
- if(" N ".equals(obj))
- {
- strCol = "Negro";
- }
- if(" G ".equals(obj))
- {
- strCol = "Gris";
- }
- if(" R ".equals(obj))
- {
- strCol = "Rojo";
- }
- if(" A ".equals(obj))
- {
- strCol = "Azul";
- }
- if(" P ".equals(obj))
- {
- strCol = "Rosa";
- }
- if(" O ".equals(obj))
- {
- strCol = "Naranja";
- }
- if(" V ".equals(obj))
- {
- strCol = "Verde";
- }
- }
- return true;
- }
- /*---- EVENTO PRESIONAR MOUSE ----*/
- public boolean mouseDown(Event e, int x, int y)
- {
- x1 = x;
- y1 = y;
- inicioLinea.move(x,y);
- return true;
- }
- /*---- EVENTO ARRASTRAR MOUSE ----*/
- public boolean mouseDrag(Event e, int x, int y)
- {
- g = getGraphics();
- if(strCol == "Blanco")
- {
- g.setColor(Color.white);
- }
- if(strCol == "Negro")
- {
- g.setColor(Color.black);
- }
- if(strCol == "Gris")
- {
- g.setColor(Color.gray);
- }
- if(strCol == "Rojo")
- {
- g.setColor(Color.red);
- }
- if(strCol == "Azul")
- {
- g.setColor(Color.blue);
- }
- if(strCol == "Rosa")
- {
- g.setColor(Color.pink);
- }
- if(strCol == "Naranja")
- {
- g.setColor(Color.orange);
- }
- if(strCol == "Verde")
- {
- g.setColor(Color.green);
- }
- //--- CONDICION HERRAMIENTA ---*/
- if(strHerr == "Lapiz")
- {
- g.drawLine(inicioLinea.x, inicioLinea.y, x, y);
- }
- if(strHerr == "Aerografo")
- {
- g.fillOval(x - (diaCirculo/2), y - (diaCirculo/2), diaCirculo, diaCirculo);
- }
- inicioLinea.move(x,y);
- return true;
- }
- /*---- EVENTO LEVANTAR MOUSE ----*/
- public boolean mouseUp(Event e, int x, int y)
- {
- x2 = x;
- y2 = y;
- x3 = x1/2;
- x4 = (x2-x1)/2;
- y3 = y2/2;
- y4 = (y2-y1)/2;
- /* --- CONDICIONES DE FIGURAS ---*/
- if(strHerr == "Linea")
- {
- g.drawLine(x1, y1, x2, y2);
- }
- if(x2<x1 && y2<y1)
- {
- xx = x1;
- x1 = x2;
- x2 = xx;
- yy = y1;
- y1 = y2;
- y2 = yy;
- }
- if(x2<x1 && y2>y1)
- {
- xx = x1;
- x1 = x2;
- x2 = xx;
- }
- if(x2>x1 && y2<y1)
- {
- yy = y1;
- y1 = y2;
- y2 = yy;
- }
- if(strHerr == "Ovalo")
- {
- g.drawOval(x1, y1, x2-x1, y2-y1);
- }
- if(strHerr == "Ovalo Relleno")
- {
- g.fillOval(x1, y1, x2-x1, y2-y1);
- }
- if(strHerr == "Rectangulo")
- {
- g.drawRect(x1, y1, x2-x1, y2-y1);
- g.drawRect(x1, y1, x3, y4);
- }
- if(strHerr == "Rectangulo Relleno")
- {
- g.fillRect(x1, y1, x2-x1, y2-y1);
- }
- return true;
- }
- public static void main (String args[]) {
- new MyApp();
- }
- } // fin del metodo
Advertisement
Add Comment
Please, Sign In to add comment