Está en la página 1de 14

Programas de 2 pascial Diduja una casa

package dibujos; import java.awt.Color; import java.awt.event.ActionEven t; public class ventana extends javax.swing.JFrame{ public ventana(){ this.setSize(500,400); this.setLayout(null);

dibujar.setLocation(150,30 0);

g.drawLine(300, 300, 300, 150); g.drawOval(100, 150, 50, 50);

dibujar.setSize(100,25); this.add(dibujar); g.drawRect(250, 150, 50, 50); g.drawRect(301, 150, 160, 150); java.awt.event.ActionListe ner b; b=new java.awt.event.ActionListe ner() { g.drawRect(320, 170, 122, 130); g.drawRect(320, 190, 122, 22); g.drawRect(320, 212, 122, 22); public void actionPerformed(ActionEv ent e) { g.drawRect(320, 234, 122, 22); g.drawRect(320, 278, 122, 22); java.awt.Graphics g; g=getGraphics(); //g.drawOval(100, 30, 50, 50); g.setColor(Color.ORANG E); g.fillRect(170, 230, 60, 70); } }; g.fillOval(400, 30, 70,70); dibujar.addActionListener( b); g.setColor(Color.WHITE); g.drawLine(200, 50, 300, 150); g.drawLine(200, 50, 100, 150); g.drawLine(100, 150, 300, 150); g.drawLine(100, 150, 100, 300); g.drawLine(100, 300, 300, 300); this.setVisible(true); } Calculadora de suma resta multiplicacin divisin
public class calculadora { public class Ventana extends javax.swing.JFrame{

this.setDefaultCloseOpera tion(2);

this.setLocation(500,100);

this.setTitle("DIBUJAMDO OBJETOS"); javax.swing.JPanel fondo; fondo= new javax.swing.JPanel(); fondo.setSize(900, 800);

g.setColor(Color.YELLOW );

fondo.setBackground(Col or.BLUE); this.add(fondo); javax.swing.JButton dibujar; dibujar=new javax.swing.JButton("DIB UJAR");

public Ventana(){//CONTRUCTIOR

//codigo `para caja de texto x=Integer.parseInt(c1.getText()); final javax.swing.JTextField c1;

this.setSize(400,400);//tomao de la ventana

c1=new javax.swing.JTextField(); c1.setLocation(130, 50);

y=Integer.parseInt(c2.getText()); z=x+y;

this.setDefaultCloseOperation(2) ; this.setLayout(null);

c1.setSize(75,30); c3.setText(String.valueOf(z)); this.add(c1); final javax.swing.JTextField c2;

this.setLocation(70,100); c2=new javax.swing.JTextField(); this.setTitle("calculadora"); c2.setLocation(130, 100); //this.setVisible(true); c2.setSize(75,35); //codigo para etiqueta this.add(c2); javax.swing.JLabel etqtulo; final javax.swing.JTextField c3; etqtulo=new javax.swing.JLabel("calculadora" ); etqtulo.setLocation(100,10); c3.setSize(75,45); etqtulo.setSize(100,50); this.add(c3); this.add(etqtulo); //codigo para boton +/*javax.swing.JLabel etq1; etq1=new javax.swing.JLabel("num1"); etq1.setLocation(15,50); etq1.setSize(200,50); boton1.setLocation(10, 200); this.add(etq1); boton1.setSize(100,55); javax.swing.JLabel etq2; this.add(boton1); etq2=new javax.swing.JLabel("nun2"); etq2.setLocation(15,100); etq2.setSize(200,50); this.add(etq2); java.awt.event.ActionListener s; x=Integer.parseInt(c1.getText()); s=new java.awt.event.ActionListener() { y=Integer.parseInt(c2.getText()); z=x-y; javax.swing.JLabel etq3; etq3=new javax.swing.JLabel("resultado"); etq3.setLocation(15,150); etq3.setSize(200,50); this.add(etq3); public void actionPerformed(ActionEvent e) { // throw new UnsupportedOperationException ("Not supported yet."); int x,y,z; }; boton2.addActionListener(r); // throw new UnsupportedOperationException ("Not supported yet."); int x,y,z; r=new java.awt.event.ActionListener() { javax.swing.JButton boton1; boton1=new javax.swing.JButton("SUMA"); java.awt.event.ActionListener r; this.add(boton2); boton2.setSize(100,55); c3=new javax.swing.JTextField(); c3.setLocation(130, 150); boton2=new javax.swing.JButton("RESTA"); boton2.setLocation(10, 280); javax.swing.JButton boton2; boton1.addActionListener(s); }; }

public void actionPerformed(ActionEvent e) {

c3.setText(String.valueOf(z));

calculadora
javax.swing.JButton boton3; boton3=new javax.swing.JButton("MUTIPLIC ASION"); boton3.setLocation(150, 200); boton3.setSize(100,55);

boton4=new javax.swing.JButton("DIVI CION"); boton4.setLocation(150, 280);

d=new java.awt.event.ActionListe ner() {

} boton4.setSize(100,55); this.add(boton4); javax.swing.JButton boton5; boton5=new javax.swing.JButton("LIM PIAR"); boton5.setLocation(280, 260); boton5.setSize(100,55); this.add(boton5); public void actionPerformed(ActionEv ent e) { // throw new UnsupportedOperationExc eption("Not supported yet."); int x,y,z; this.setVisible(true); }

this.add(boton3); java.awt.event.ActionListe ner m; m=new java.awt.event.ActionListe ner() { public void actionPerformed(ActionEv ent e) { // throw new UnsupportedOperationExc eption("Not supported yet."); int x,y,z; x=Integer.parseInt(c1.getT ext()); java.awt.event.ActionListe ner d; d=new java.awt.event.ActionListe ner() {

y=Integer.parseInt(c2.getT ext()); z=x*y;

x=Integer.parseInt(c1.getT ext());

y=Integer.parseInt(c2.getT ext()); z=x/y;

c3.setText(String.valueOf( z)); } }; boton3.addActionListener( m); }; javax.swing.JButton boton4;

c3.setText(String.valueOf( z));

boton4.addAncestorListen er(d);

Calcula el salario
public class ventana3 extends javax.swing.JFrame { public ventana3(){ javax.swing.JLabel etiqueta1; etiqueta1 =new javax.swing.JLabel("**CAL CULAR SALARIO**"); etiqueta1.setLocation(60,1 5); etiqueta1.setSize(500,50); java.awt.Font q; q=new java.awt.Font("Matura MT Script Capitals",1,20); etiqueta1.setFont(q); etiqueta1.setForeground( Color.darkGray); this.add(etiqueta1); javax.swing.JLabel etiqueta2; etiqueta2 =new javax.swing.JLabel("HRS. TRABAJADAS"); etiqueta2.setLocation(20,1 00); etiqueta2.setSize(400,40); java.awt.Font g; g=new java.awt.Font("Matura MT Script Capitals",1,5); etiqueta2.setFont(q); etiqueta2.setForeground( Color.RED); this.add(etiqueta2); javax.swing.JLabel etiqueta3; etiqueta3 =new javax.swing.JLabel("SALA RIO X HORA"); etiqueta3.setLocation(20,1 80); etiqueta3.setSize(300,40); java.awt.Font s;

s=new java.awt.Font("Matura MT Script Capitals",1,5); etiqueta3.setFont(q); etiqueta3.setForeground( Color.RED); this.add(etiqueta3); final javax.swing.JTextField c1; c1= new javax.swing.JTextField(); c1.setLocation(350,100); c1.setSize(120,40); this.add(c1); final javax.swing.JTextField c2; c2= new javax.swing.JTextField(); c2.setLocation(350,180); c2.setSize(120,40); this.add(c2); final javax.swing.JTextArea a; a=new javax.swing.JTextArea(); a.setLocation(20,260); a.setSize(300,280); this.add(a); javax.swing.JButton btn; btn=new javax.swing.JButton("CAL CULAR"); btn.setLocation(380,260); btn.setSize(180,30); btn.setBackground(Color. BLUE); java.awt.Font f; f=new java.awt.Font("Matura MT Script Capitals",1,15); btn.setFont(f); this.add(btn);

private String o; public void actionPerformed(ActionEv ent e){ int hrs,pago,dia,sem,quin,me s,ao,r,s,t; hrs=Integer.parseInt(c1.ge tText()); pago=Integer.parseInt(c2. getText()); dia=hrs*pago; r=hrs*pago; sem=dia*6; s=hrs*pago; quin=sem*2; t=hrs*pago; a.setText(String.valueOf(" salario*dia="+r)); a.setText(String.valueOf(" salario*sem="+s)); a.setText(String.valueOf(" salario*quin="+t)); } }; btn.addActionListener(p); javax.swing.JButton btn1; btn1=new javax.swing.JButton("LIM PIAR"); btn1.setLocation(380,350) ; btn1.setSize(180,30); btn1.setBackground(Color .BLUE); java.awt.Font h; h=new java.awt.Font("Matura MT Script Capitals",1,15); btn1.setFont(h); this.add(btn1);

java.awt.event.ActionListe ner p; p=new java.awt.event.ActionListe ner() {

java.awt.event.ActionListe ner lm; lm=new java.awt.event.ActionListe ner() {

public void actionPerformed(ActionEv ent e) { c1.setText(""); c2.setText(""); a.setText(""); } };

this.setTitle("SALARIO DEL DOCENTE"); this.setEnabled(true); this.setVisible(true);

btn1.addActionListener(lm ); javax.swing.JButton btn2; btn2=new javax.swing.JButton("EXIT "); btn2.setLocation(380,440) ; btn2.setSize(180,30); btn2.setBackground(Color .BLUE); java.awt.Font i; i=new java.awt.Font("Matura MT Script Capitals",1,15); btn2.setFont(i); this.add(btn2);

javax.swing.JPanel fondo; fondo= new javax.swing.JPanel(); fondo.setSize(900, 800); fondo.setBackground(Col or.YELLOW); this.add (fondo);

btn.setSize(140,30); java.awt.Color c7; c7=new java.awt.Color(120,80,90); btn.setBackground(c7); java.awt.Font f; f=new java.awt.Font("Matura MT Script Capitals",1,15); btn.setFont(f); this.add(btn);

java.awt.event.ActionListener e; e=new java.awt.event.ActionListener () { public void actionPerformed(ActionEvent e) { int edad = 0; edad=Integer.parseInt(c1.get Text()); if(edad>=18)

this.setVisible(true); } }

Calcula si eres menor o mayor de edad


javax.swing.JLabel etiqueta1; etiqueta1 =new javax.swing.JLabel("**INGRE SA TU EDAD**"); etiqueta1.setLocation(80,15);

javax.swing.JOptionPane.sho wMessageDialog(null,"eres mayor de edad"); else javax.swing.JOptionPane.sho wMessageDialog(null,"eres menor de edad"); } };

java.awt.event.ActionListe ner ex; ex=new java.awt.event.ActionListe ner() { public void actionPerformed(ActionEv ent e) { System.exit(0); } };

etiqueta1.setSize(500,50); java.awt.Font q; q=new java.awt.Font("Matura MT Script Capitals",1,20); etiqueta1.setFont(q); etiqueta1.setForeground(Col or.BLACK); this.add(etiqueta1); final javax.swing.JTextField c1; c1= new javax.swing.JTextField(); c1.setLocation(180,80); c1.setSize(120,40); this.add(c1);

btn.addActionListener(e);

btn2.addActionListener(ex ); this.setLayout(null); this.setLocation(60,30); this.setSize(600,600); this.setAlwaysOnTop(true) ;

javax.swing.JButton btn1; btn1=new javax.swing.JButton("LIMPIA R"); btn1.setLocation(300,150); btn1.setSize(160,30); java.awt.Color c; c=new java.awt.Color(120,80,90); btn1.setBackground(c); java.awt.Font a; a=new java.awt.Font("Matura MT Script Capitals",1,15); btn1.setFont(f);

javax.swing.JButton btn; btn=new javax.swing.JButton("ENVIA R"); btn.setLocation(40,150);

this.add(btn1);

java.awt.event.ActionListener l; l=new java.awt.event.ActionListener () { public void actionPerformed(ActionEvent e) { c1.setText(""); } };

javax.swing.JPanel fondo; fondo= new javax.swing.JPanel(); fondo.setSize(900, 800); java.awt.Color c4; c4= new java.awt.Color(150, 150, 140); fondo.setBackground(c4); this.add (fondo);

etiqueta3.setSize(500,50); java.awt.Font c; c=new java.awt.Font("Matura MT Script Capitals",1,20); etiqueta3.setFont(q); etiqueta3.setForeground(Col or.BLACK); this.add(etiqueta3); javax.swing.JLabel etiqueta4; etiqueta4 =new javax.swing.JLabel("INGLES 3"); etiqueta4.setLocation(20,200 ); etiqueta4.setSize(500,50); java.awt.Font i; i=new java.awt.Font("Matura MT Script Capitals",1,20); etiqueta4.setFont(q); etiqueta4.setForeground(Col or.BLACK); this.add(etiqueta4); javax.swing.JLabel etiqueta5; etiqueta5 =new javax.swing.JLabel("BIOLOG IA"); etiqueta5.setLocation(20,260 ); etiqueta5.setSize(500,50); java.awt.Font b; b=new java.awt.Font("Matura MT Script Capitals",1,20); etiqueta5.setFont(q); etiqueta5.setForeground(Col or.BLACK); this.add(etiqueta5); javax.swing.JLabel etiqueta6; etiqueta6 =new javax.swing.JLabel("DESA.S OFTWARE"); etiqueta6.setLocation(20,320 ); etiqueta6.setSize(500,50); java.awt.Font d; d=new java.awt.Font("Matura MT Script Capitals",1,20); etiqueta6.setFont(q);

this.setVisible(true); } }

btn1.addActionListener(l);

Calcula tu calificacin
javax.swing.JButton btn2; btn2=new javax.swing.JButton("EXIT"); btn2.setLocation(180,200); btn2.setSize(120,30); java.awt.Color m; m=new java.awt.Color(120,80,90); btn2.setBackground(m); java.awt.Font j; j=new java.awt.Font("Matura MT Script Capitals",1,15); btn2.setFont(j); this.add(btn2); javax.swing.JLabel etiqueta1; etiqueta1 =new javax.swing.JLabel("**CALI.D EL 1 PARCIAL**"); etiqueta1.setLocation(60,15); etiqueta1.setSize(500,50); java.awt.Font q; q=new java.awt.Font("Matura MT Script Capitals",1,20); etiqueta1.setFont(q); etiqueta1.setForeground(Col or.RED); this.add(etiqueta1);

java.awt.event.ActionListener ex; ex=new java.awt.event.ActionListener () { public void actionPerformed(ActionEvent e) { System.exit(0); } };

javax.swing.JLabel etiqueta2; etiqueta2 =new javax.swing.JLabel("GEOME TRIA"); etiqueta2.setLocation(20,80); etiqueta2.setSize(500,50); java.awt.Font g; g=new java.awt.Font("Matura MT Script Capitals",1,20); etiqueta2.setFont(q); etiqueta2.setForeground(Col or.BLACK); this.add(etiqueta2);

btn2.addActionListener(ex);

this.setLayout(null); this.setLocation(50,50); this.setSize(500,400); this.setAlwaysOnTop(true); this.setTitle("EDAD"); this.setEnabled(true);

javax.swing.JLabel etiqueta3; etiqueta3 =new javax.swing.JLabel("CTSYV") ; etiqueta3.setLocation(20,140 );

this.add(c5); etiqueta6.setForeground(Col or.BLACK); this.add(etiqueta6); javax.swing.JLabel etiqueta7; etiqueta7 =new javax.swing.JLabel("BASES DE DATOS"); etiqueta7.setLocation(20,380 ); etiqueta7.setSize(500,50); java.awt.Font bd; bd=new java.awt.Font("Matura MT Script Capitals",1,20); etiqueta7.setFont(q); etiqueta7.setForeground(Col or.BLACK); this.add(etiqueta7); final javax.swing.JTextField c1; c1= new javax.swing.JTextField(); c1.setLocation(300,85); c1.setSize(120,30); this.add(c1); final javax.swing.JTextField c2; c2= new javax.swing.JTextField(); c2.setLocation(300,145); c2.setSize(120,30); this.add(c2); final javax.swing.JTextField c3; c3= new javax.swing.JTextField(); c3.setLocation(300,205); c3.setSize(120,30); this.add(c3); final javax.swing.JTextField c4; c4= new javax.swing.JTextField(); c4.setLocation(300,265); c4.setSize(120,30); this.add(c4); final javax.swing.JTextField c5; c5= new javax.swing.JTextField(); c5.setLocation(300,330); c5.setSize(120,30); btn.addActionListener(p); final javax.swing.JTextField c6; c6= new javax.swing.JTextField(); c6.setLocation(300,390); c6.setSize(120,30); this.add(c6); javax.swing.JButton btn; btn=new javax.swing.JButton("PROM EDIO"); btn.setLocation(10,460); btn.setSize(170,30); btn.setBackground(Color.red) ; java.awt.Font f; f=new java.awt.Font("Matura MT Script Capitals",1,15); btn.setFont(f); this.add(btn); javax.swing.JButton btn1; btn1=new javax.swing.JButton("LIMPIA R"); btn1.setLocation(190,460); btn1.setSize(160,30); btn1.setBackground(Color.re d); java.awt.Font l; l=new java.awt.Font("Matura MT Script Capitals",1,15); btn1.setFont(l); this.add(btn1);

java.awt.event.ActionListener lm; lm=new java.awt.event.ActionListener () { public void actionPerformed(ActionEvent e) { c1.setText(""); c2.setText(""); c3.setText(""); c4.setText(""); c5.setText(""); c6.setText(""); } };

java.awt.event.ActionListener p; p=new java.awt.event.ActionListener () { public void actionPerformed(ActionEvent e){ int u,v,w,x,y,z,o; u=Integer.parseInt(c1.getTex t()); v=Integer.parseInt(c2.getText ()); w=Integer.parseInt(c3.getTex t()); x=Integer.parseInt(c4.getText ()); y=Integer.parseInt(c5.getText ()); z=Integer.parseInt(c6.getText ()); o=u+v+w+x+y+z;

btn1.addActionListener(lm); javax.swing.JButton btn2; btn2=new javax.swing.JButton("EXIT"); btn2.setLocation(360,460); btn2.setSize(110,30); btn2.setBackground(Color.re d); java.awt.Font e; e=new java.awt.Font("Matura MT Script Capitals",1,15); btn2.setFont(e); this.add(btn2);

javax.swing.JOptionPane.sho wMessageDialog(null,"EL PROMEDIO ES:"+o); } };

java.awt.event.ActionListener ex; ex=new java.awt.event.ActionListener () {

public void actionPerformed(ActionEvent e) { System.exit(0); } };

// CODIGO PARA EL BOTON javax.swing.JButton botoncito; botoncito=new javax.swing.JButton("MOST RAR DATOS"); botoncito.setLocation(480,40 0);

//CODIGO PARA UNA ETIQUETA javax.swing.JLabel etiquetita; etiquetita =new javax.swing.JLabel("DIRECC ION"); etiquetita.setLocation(100,10 0); etiquetita.setSize(200,150); java.awt.Font r; r=new java.awt.Font("algerian",1,20) ; etiquetita.setFont(r); etiquetita.setForeground(Col or.magenta); // CODIGO PARA CREAR CAJA DE TEXTO javax.swing.JTextField caja1; caja1= new javax.swing.JTextField(); caja1.setLocation(500,140); caja1.setSize(250,50); java.awt.Color c3; c3=new java.awt.Color(9,17,255); caja1.setBackground(c3);

btn2.addActionListener(ex);

this.setLayout(null); this.setLocation(60,50); this.setSize(500,600); this.setAlwaysOnTop(true);

botoncito.setSize(250,30); java.awt.Color c5; c5=new java.awt.Color(120,230,10); botoncito.setBackground(c5);

this.setTitle("PROMEDIO"); this.setEnabled(true); this.setVisible(true);

javax.swing.JPanel fondo; fondo= new javax.swing.JPanel(); fondo.setSize(900, 800); fondo.setBackground(Color. CYAN); this.add (fondo);

//botoncito.setBackground(C olor.blue); java.awt.Font f; f=new java.awt.Font("jokerman",1,2 0); botoncito.setFont(f); //CODIGO PARA UNA ETIQUETA javax.swing.JLabel etiqueta; etiqueta =new javax.swing.JLabel("NOMBR E"); etiqueta.setLocation(100,70);

this.setVisible(true);

muestra los datos personales


//CODIGO PARA CREAR UNA ETIQUETA javax.swing.JLabel etiqueta1; //DECLARAR EL NOMBRE DE LA ETIQUETA etiqueta1 =new javax.swing.JLabel("**DATO S PERSONALES**"); //TEXTO DE LA ETIQUETA etiqueta1.setLocation(250,15 ); //LOCALIZACION DE LA ETIQUETA etiqueta1.setSize(500,50); //TAMAO DE LA ETIQUETA java.awt.Font q; //SELECCIONAR EL ESTILO DE LETRA q=new java.awt.Font("chiller",1,20);// EL TIPO DE LETRA etiqueta1.setFont(q); etiqueta1.setForeground(Col or.pink);

etiqueta.setSize(100,50); //COLOR A LA ETIQUETA java.awt.Font p; p=new java.awt.Font("curlz mt",1,20); etiqueta.setFont(p); etiqueta.setForeground(Color .red); // CODIGO PARA CREAR CAJA DE TEXTO javax.swing.JTextField caja; caja= new javax.swing.JTextField(); caja.setLocation(500,70); caja.setSize(250,50); java.awt.Color c6; c6=new java.awt.Color(174,79,22); caja.setBackground(c6); //CODIGO PARA CREA UNA ETIQUETA javax.swing.JLabel etiquetita2; etiquetita2 =new javax.swing.JLabel("EDAD"); etiquetita2.setLocation(100,2 20); etiquetita2.setSize(200,50); java.awt.Font l; l=new java.awt.Font("HARRINGTO N",1,20); etiquetita2.setFont(l); etiquetita2.setForeground(Co lor.yellow); // CODIGO PARA CREAR CAJA DE TEXTO javax.swing.JTextField caja2; caja2= new javax.swing.JTextField(); caja2.setLocation(500,210);

caja2.setSize(250,50); java.awt.Color O2; O2=new java.awt.Color(37,24,45); caja2.setBackground(O2);

java.awt.Color c4; c4= new java.awt.Color(100, 50, 100); fondo.setBackground(c4); this.add (fondo);

el valor de un cubo al dar click System.out.println("El cubo es:"+ cub); } public void mousePressed(MouseEvent e) {

//CODIGO PARA CREA UN AREA DE TEXTO javax.swing.JTextArea area; area = new javax.swing.JTextArea(""); area.setLocation(90,350); area.setSize(200,200); java.awt.Font k; k=new java.awt.Font("gigi",1,20); area.setFont(k); area.setForeground(Color.gr ay); java.awt.Color b5; b5=new java.awt.Color(96,167,178); area.setBackground(b5);

} public void setX(int x1){ x=x1; this.setLocation(x,y); } public void setY (int y1){ y=y1; this.setLocation(x,y); } public int getX(){ return x; }

//System.out.println(""); java.awt.Graphics g; g= getGraphics (); g.drawOval(40, 40, 50, 40);//Dibuja un ovalo } public void mouseReleased(MouseEvent e) { //System.out.println("al pasar el mouse sobre la ventana aparece una imagen"); java.awt.Graphics g; g= getGraphics (); g.drawLine(200, 50, 300, 50);//Dibuja una linea } public void mouseEntered(MouseEvent e) { //System.out.println("Al pasar el mouse sobre la ventana aparece el mensaje"); java.awt.Graphics g; g= getGraphics (); g.drawArc(190, 80, 210, 90, 45, 90); } public void mouseExited(MouseEvent e) { //System.out.println("cuando quito"); java.awt.Graphics g; g= getGraphics (); g.drawRect(50, 150, 250, 100); } }; this.addMouseListener(m); } }

Dibuja un cuadra circulo lneas


public class Ventana extends javax.swing.JFrame { public Ventana (){

//CODIGO PARA AGRAGAR OBJETOS A LA VENTANA this.add(botoncito); this.add(etiqueta); this.add(etiquetita); this.add(etiqueta1); this.add(caja); this.add(etiquetita2); this.add(caja1); this.add(caja2); this.add(area); //CODIGO PARA CONSTRUIR LA VENTANA this.setLayout(null); //acomoda los objetos this.setSize(850,600); //tamao de la ventana this.setVisible(true); //visible la ventana this.setAlwaysOnTop(true); //ventana siempre abierta this.setTitle("DATOS PERSONALES"); this.setEnabled(true); // CODIGO PARA DAR COLOR A LA VENTANA javax.swing.JPanel fondo; fondo= new javax.swing.JPanel(); fondo.setSize(900, 800);

this.setSize(400,400);//tama o ventana this.setDefaultCloseOperatio n(2); this.setLayout(null); this.setLocation(70,100); this.setTitle("Eventos de mouse"); this.setVisible(true);

java.awt.event.MouseListene r m; m=new java.awt.event.MouseListene r() { public void mouseClicked(MouseEvent e) { //System.out.println(""); int num=5,cub; cub=num*num*num; //calcula

Muestra las banderas Y muestra un semforo


public class Ventanota extends javax.swing.JFrame { public Ventanota(){

//ETIQUETA bb.setBackground(Color.WHI TE); this.add(bb); javax.swing.JLabel etiquetatitulo; etiquetatitulo=new javax.swing.JLabel("****BAN DERAS****"); etiquetatitulo.setLocation(50, 240); etiquetatitulo.setSize(200, 50); this.add(etiquetatitulo); //SEMAFORO if(bb.getBackground()==Colo r.WHITE){ bb.setBackground(Color.RE D); }else{ bb.setBackground(Color.WHI TE); } } }; bb.addActionListener(c); final javax.swing.JButton bv; bv=new javax.swing.JButton(""); bv.setLocation(250, 70); bv.setSize(150, 50); bv.setBackground(Color.GR EEN); this.add(bv);

this.setSize(500,400);//tama o ventana this.setDefaultCloseOperatio n(2); this.setLayout(null); this.setLocation(70,100); this.setTitle("Eventos de mouse");

java.awt.event.ActionListener c; c= new java.awt.event.ActionListener () { public void actionPerformed(ActionEvent e) {

final javax.swing.JButton bcc; bcc=new javax.swing.JButton(""); bcc.setLocation(50, 70); bcc.setSize(150, 50); bcc.setBackground(Color.GR EEN); this.add(bcc);

java.awt.event.ActionListener b; b= new java.awt.event.ActionListener () { public void actionPerformed(ActionEvent e) { if(bcc.getBackground()==Col or.GREEN){ bcc.setBackground(Color.BL ACK); }else{ bcc.setBackground(Color.GR EEN); } } }; bcc.addActionListener(b); final javax.swing.JButton bb; bb=new javax.swing.JButton(""); bb.setLocation(50, 120); bb.setSize(150, 50);

final javax.swing.JButton br; br=new javax.swing.JButton(""); br.setLocation(50, 170); br.setSize(150, 50); br.setBackground(Color.RED ); this.add(br);

java.awt.event.ActionListener e; e= new java.awt.event.ActionListener () { public void actionPerformed(ActionEvent e) { javax.swing.JOptionPane.sho wMessageDialog(null,"AVAN ZA"); } }; bv.addActionListener(e); final javax.swing.JButton bn; bn=new javax.swing.JButton(""); bn.setLocation(250, 130); bn.setSize(150, 50); bn.setBackground(Color.OR ANGE); this.add(bn);

java.awt.event.ActionListener d; d= new java.awt.event.ActionListener () { public void actionPerformed(ActionEvent e) { if(br.getBackground()==Color .RED){ br.setBackground(Color.YEL LOW); }else{ br.setBackground(Color.RED ); } } }; br.addActionListener(d);

java.awt.event.ActionListener f; f= new java.awt.event.ActionListener () {

public void actionPerformed(ActionEvent e) { javax.swing.JOptionPane.sho wMessageDialog(null,"DISMI NUYE LA VELOCIDAD"); } }; bn.addActionListener(f);

this.setLayout(null); this.setLocation(70,100); this.setTitle("Eventos de mouse"); this.setVisible(true); // contruir una etiqueta javax.swing.JLabel etiquetatitulo; etiquetatitulo=new javax.swing.JLabel("****EVE NTOS DEL MOUSE****"); etiquetatitulo.setLocation(100 , 10); etiquetatitulo.setSize(200, 50); this.add(etiquetatitulo); //BOTONES final javax.swing.JButton aceptar; aceptar=new javax.swing.JButton("ACEPT AR:)"); aceptar.setLocation(60, 70); aceptar.setSize(120, 50); aceptar.setBackground(Color .CYAN); this.add(aceptar); java.awt.event.ActionListener b; b= new java.awt.event.ActionListener () { public void actionPerformed(ActionEvent e) { if(bcc.getBackground()==Col or.CYAN){ bcc.setBackground(Color.MA GENTA); }else{ bcc.setBackground(Color.CY AN); } } }; bcc.addActionListener(b); } }

final javax.swing.JButton bro; bro=new javax.swing.JButton(""); bro.setLocation(250, 190); bro.setSize(150, 50); bro.setBackground(Color.RE D); this.add(bro);

java.awt.event.ActionListener g; g= new java.awt.event.ActionListener () { public void actionPerformed(ActionEvent e) { javax.swing.JOptionPane.sho wMessageDialog(null,"DETE NTE"); } }; bro.addActionListener(g);

Agenda
public class Persona { public static int total; String nombre; String apellido; String direccion; String edad; String correo; String telefono; public Persona (){ Persona.total ++; } public void mostrarnombre(){ System.out.println(nombre+ " " + apellido+" " +direccion+" " +edad); } }

java.awt.event.ActionListener a; a= new java.awt.event.ActionListener () { public void actionPerformed(ActionEvent e) { aceptar.setText("CANCELAR *,*"); } }; aceptar.addActionListener(a); final javax.swing.JButton bcc; bcc=new javax.swing.JButton("CAMBI AR COLOR"); bcc.setLocation(250, 70); bcc.setSize(150, 50); bcc.setBackground(Color.CY AN); this.add(bcc);

//ETIQUETA javax.swing.JLabel etiquetat; etiquetat=new javax.swing.JLabel("****SEM AFORO****"); etiquetat.setLocation(250, 240); etiquetat.setSize(200, 50); this.add(etiquetat);

Herencia
public class hijo extends padre { public hijo(){ } public void llorar(){ System.out.println("ME GUSTA LLORAR"); } }

botones que cambian de diferente color


this.setSize(500,400);//tama o ventana this.setDefaultCloseOperatio n(2);

Herencia
public padre(){ } String ojos="cafes",cabello="chino", colorpiel="moreno"; double altura=1.65; public void desesperarse(){ System.out.println("QUIERO GRITAR"); } public void jugar(){ System.out.println("SOY DEPORTISTA"); } public void trabajar(){ System.out.println("ME GUSTA TRABAJAR"); } }

import javax.swing.JMenuItem; public class Colores extends JFrame implements ActionListener { //atributos de colores private JMenuBar mb; private JMenu menu1,menu2; private JMenuItem mi1,mi2,mi3,mi4,mi5,mi6,mi7 ,mi8,mi9,mi10; public Colores(){ javax.swing.JLabel etiqueta; etiqueta=new javax.swing.JLabel("MUNDO COLORES"); etiqueta.setLocation(120, 5); etiqueta.setSize(300,50); this.add(etiqueta); setLayout(null); mb=new JMenuBar(); setJMenuBar(mb); menu1=new JMenu("Espaol"); mb.add(menu1); menu2=new JMenu("Ingles"); mb.add(menu2); mi1=new JMenuItem("Rojo"); mi1.addActionListener(this); menu1.add(mi1); mi2=new JMenuItem("Verde"); mi2.addActionListener(this); menu1.add(mi2); mi3=new JMenuItem("Cafe"); mi3.addActionListener(this); menu1.add(mi3); mi4=new JMenuItem("Negro"); mi4.addActionListener(this); menu1.add(mi4); mi5=new JMenuItem("Blanco"); mi5.addActionListener(this); menu1.add(mi5);

mi6=new JMenuItem("Yellow"); mi6.addActionListener(this); menu2.add(mi6); mi7=new JMenuItem("Pink"); mi7.addActionListener(this); menu2.add(mi7); mi8=new JMenuItem("Cyan"); mi8.addActionListener(this); menu2.add(mi8); mi9=new JMenuItem("Orange"); mi9.addActionListener(this); menu2.add(mi9); mi10=new JMenuItem("Purple"); mi10.addActionListener(this); menu2.add(mi10); } public void actionPerformed(ActionEvent e) { Container f=this.getContentPane(); if(e.getSource()==mi1){ f.setBackground(new Color(255,0,0)); } if(e.getSource()==mi2){ f.setBackground(new Color(0,255,0)); } if(e.getSource()==mi3){ f.setBackground(new Color(102,0,0)); } if(e.getSource()==mi4){ f.setBackground(new Color(0,0,0)); } if(e.getSource()==mi5){ f.setBackground(new Color(255,255,255)); } if(e.getSource()==mi6){ f.setBackground(new Color(255,255,0)); } if(e.getSource()==mi7){ f.setBackground(new Color(255,0,255)); } if(e.getSource()==mi8){ f.setBackground(new Color(0,255,255));

gato
Bigotes bigote_izquierda; Bigotes bigote_derecha; Ojos ojo_izquierda; Ojos ojo_derecha; Patas p1,p2,p3,p4; Cola cola; //metodos public void Maullar() { System.out.println("el gato poncho maulla"); } public void Rasgunar() { System.out.println("el gato toncho rasgua"); } public void Jugar() { System.out.println("el gato pancho juega"); } public void Pelear() { System.out.println("el gato ponchito pelea"); } }

colores
package menu; import java.awt.Color; import java.awt.Container; import java.awt.event.ActionEvent; import java.awt.event.ActionListener ; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar;

Cambia de color Bandera semaforo

Diga lneas Calcula califi Calcula el salario slario Datos personales

agenda run:
ME GUSTA TRABAJAR ME GUSTA LLORAR SOY DEPORTISTA QUIERO GRITAR

Datos personales

agenda run:
ME GUSTA TRABAJAR ME GUSTA LLORAR SOY DEPORTISTA QUIERO GRITAR

Herencia

lineas

Herencia

calculadoras

calificasiones

agenda

Datos personales

el gato poncho maulla el gato toncho rasgua el gato pancho juega el gato ponchito pelea

gato

Mondo de colores

También podría gustarte