PROGRAMAS EN APPLES
package applet; import java.awt.*; import java.applet.Applet; import java.awt.Color; import java.awt.Font; public class miapplet extends Applet { @Override public void paint(Graphics g){ g.setColor(Color.BLUE); Font f=new Font("Curlz MT",Font.BOLD,25); g.setFont(f); g.drawString("Hola", 50, 50); g.drawString("Programacion Applet", 50, 250); g.drawOval(100, 80, 100, 100); g.fillOval(20, 70, 60, 70); g.setColor(Color.BLACK); g.drawRect(275, 50, 60, 60); g.setColor(Color.red); g.fillRect(220, 85, 35, 140); } }
package applet; import java.applet.Applet; import java.awt.*; public class dibujarpoligono extends Applet { Polygon cabello; @Override public void init(){ int[]cabelloX={100,140,250,300,180,100}; int[]cabelloY={300,120,45,250,60,300}; cabello=new Polygon(cabelloX,cabelloY,5);
setBackground(Color.CYAN);//dibujamos el cabello } @Override public void paint(Graphics screen){ screen.setColor(Color.PINK); screen.fillRoundRect(146, 85, 104, 74, 30, 30);//dibujar triangulo redondo screen.fillOval(146, 90, 104, 133); screen.setColor(Color.BLACK); screen.fillPolygon(cabello); int[]ceja1X={151,168,174,171,178,193}; int[]ceja1Y={145,140,148,184,191,188}; screen.drawPolyline(ceja1X, ceja1Y,6);//dibujar la ceja izquierda int[]ceja2X={188,197,213,223}; int[]ceja2Y={146,141,142,146}; screen.drawPolyline(ceja2X, ceja2Y,4);//dibujar la ceja derecha screen.setColor(Color.red); int[]bocaX={166,183,200}; int[]bocaY={197,203,197}; screen.drawPolyline(bocaX, bocaY,3); //dibujar la boca screen.setColor(Color.BLACK); screen.fillOval(161, 148, 10, 3);//dibujar ojo izquierdo
screen.fillOval(202, 145, 12, 5);//dibujar ojo derecho
Font f=new Font("Curlz MT",Font.BOLD,25); screen.setFont(f);screen.drawString(":) Carita Feliz", 50, 50); //screen.drawString("Pingus", 150, 250); screen.setColor(Color.MAGENTA); screen.fillOval(140, 55, 25, 45);//dibujar moo izquierdo screen.fillOval(150, 65, 30, 45);//dibujar moo derecho screen.setColor(Color.PINK); screen.fillRect(184, 220, 30, 25);
screen.setColor(Color.GREEN); screen.fillOval(150, 240, 100, 100); screen.setColor(Color.BLACK); screen.fillArc(155, 240, 100, 50, 30, 50); } }
package applet; import java.awt.*; import java.applet.*; public class crearBotones extends Applet { public void init(){ add(new Button("Boton1")); add(new Button("Boton2")); add(new Button("Boton3")); add(new Label("Etiqueta1")); add(new Label("Etiqueta2")); add(new Label("Etiqueta3")); } }
package applet; import java.awt.*; import java.applet.*; public class calculosmatematicos extends Applet { double costo=250;//costo del articulo double iva=0.16;//iva double monto=450;//el cliente pago este monto double impuesto,cambio,total; @Override public void paint(Graphics g){ impuesto=costo*iva; total=costo+impuesto; cambio=monto-total; g.setColor(Color.RED); g.drawString("El articulo costo="+costo,5,70); g.drawString("Impuesto="+impuesto,5,90); g.drawString("Total="+total,5,110); g.drawString("Cambio al cliente="+cambio,5,130); g.setColor(Color.PINK); Font f=new Font("Curlz MT",Font.BOLD,25); g.setFont(f); g.drawString("Calculos Matematicos", 50, 30); setBackground(Color.BLUE); } }
package applet; import java.awt.*; import java.applet.*; public class MostrarCheckbox extends Applet { CheckboxGroup deporte=new CheckboxGroup(); Checkbox futbol=new Checkbox("Futbol americano",deporte,false);
Checkbox natacion=new Checkbox("Natacion profecional",deporte,false); Checkbox aerobics=new Checkbox("Fitness aerobics",deporte,true); public void init(){ add(futbol); add(natacion); add(aerobics); } }
package applet; import java.awt.*; import java.applet.*; public class EscogePartido extends Applet { CheckboxGroup partido=new CheckboxGroup(); Checkbox PRI=new Checkbox("PRI",partido,false); Checkbox PAN=new Checkbox("PAN",partido,false); Checkbox PRD=new Checkbox("PRD",partido,false); Checkbox Otros=new Checkbox("Otros",partido,true); public Label mensaje=new Label("Escoge el partidopor el cual vas a votar"); public void init(){ add(mensaje); add(PRI); add(PAN); add(PRD); add(Otros); } }
package applet; import java.awt.*; import java.applet.*; public class EjemploChoice extends Applet { public Choice menu=new Choice(); public Label mensaje=new Label("Elije lo que quieres comer"); public void init(){ menu.addItem("pollo"); menu.addItem("Tacos"); menu.addItem("Tortas"); menu.addItem("Guisado"); menu.addItem("Mariscos"); add(mensaje); add(menu); } }
package applet; import java.awt.*; import java.applet.*; public class CampoTexto extends Applet { public Label mensaje1=new Label("Nombre"); public Label mensaje2=new Label("Apellido"); public Label mensaje3=new Label("Direccion"); public void init(){ add(mensaje1); add(new TextField(25));//25-numero de caracteres en el campo add(mensaje2); add(new TextField(25)); add(mensaje3);
add(new TextField(35)); } }
package applet; import java.awt.*; import java.applet.Applet; public class BarrasDespl extends Applet{ Scrollbar vertical1,vertical2; Scrollbar horizontal1,horizontal2; public void init(){ vertical1=new Scrollbar(Scrollbar.VERTICAL,0,1,0,255); vertical2=new Scrollbar(Scrollbar.VERTICAL,0,1,0,255); horizontal1=new Scrollbar(Scrollbar.HORIZONTAL,0,1,0,255); horizontal2=new Scrollbar(Scrollbar.HORIZONTAL,0,1,0,255); add(vertical1); add(vertical2);
add(horizontal1); add(horizontal2); } } package applet;
import java.awt.*; import java.applet.*; public class AreaText extends Applet { public Label mensaje=new Label("Cometarios"); TextArea comentario=new TextArea("Mi querido amigo.\nYa cheque los articulos.\nPronto te mando mi opinion",10,25); public void init(){ add(mensaje); add(comentario); } }
APLICACIONES ESWING
Abrir NetBeans y crear un proyecto llamado combertir texto en el mismo proyecto llamado Aplicaciones Swing Cdigos botnes mayscula ,minsculas,limpiar,salir: jTextField2.setText(jTextField1.getText().toUpperCase()); jTextField2.setText(jTextField1.getText().toLowerCase()); jTextField1.setText("");
jTextField2.setText(""); System.exit(0);
Abrir NetBeans y crear un proyecto llamado contando vocales en el mismo proyecto llamado Aplicaciones Swing Cdigo botones mostrar ,limpiar,salir: String texto; int x; texto=jTextField1.getText(); int cuentavocales=0; for(x=0;x<texto.length();x++){ if((texto.charAt(x)=='a')|| (texto.charAt(x)=='e')|| (texto.charAt(x)=='i')|| (texto.charAt(x)=='o')|| (texto.charAt(x)=='u')|| (texto.charAt(x)=='A')|| (texto.charAt(x)=='E')|| (texto.charAt(x)=='I')|| (texto.charAt(x)=='O')|| (texto.charAt(x)=='U')){ cuentavocales ++;
jTextField2.setText("El texto"+" "+ texto+" "+"contiene"+" "+cuentavocales+" "+"vocales"); } } } jTextField1.setText(""); jTextField2.setText(""); System.exit(0);
Abrir NetBeans y crear un proyecto llamado copiar texto en el mismo proyecto llamado Aplicaciones Swing Cdigo de los botones copiar,limpiar,salir: String txt=jTextField1.getText(); if(txt.equals("")){ javax.swing.JOptionPane.showMessageDialog(null," Porfabor Introdusca la Escritura"); }else{ jTextField2.setText(txt); } jTextField1.setText(""); jTextField2.setText(""); System.exit(0);
Abrir NetBeans y crear un proyecto llamado listas en el mismo proyecto llamado Aplicaciones Swing Cdigos: private String marca_selec,equipamiento; private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) { //borramos texto jTextField1.setText(""); //seleccionamos el equipamiento jList1.clearSelection(); //capturar la marca seleccionada marca_selec="Marca:"+(String)jComboBox1.getSelectedItem()+"#"; jTextField1.setText(marca_selec); jTextField1.setText(""); System.exit(0);
Abrir NetBeans y crear un proyecto llamado saludo en el mismo proyecto llamado Aplicaciones Swing Cdigos: System.out.println("Soy color verde"); System.out.println("Soy color blanco"); System.out.println("Soy color rojo"); jTextField1.setText(""); System.exit(0); javax.swing.JOptionPane.showMessageDialog(null,"Hola" + jTextField1.getText() + "Buenos dias" + ":)"); }
Abrir NetBeans y crear un proyecto llamado marco sencillo en el mismo proyecto llamado Aplicaciones Swing y crea en java class crear el proyecto llamado mi panel Cdigo mi panel: package aplicasionesswing; import javax.swing.*; public class MarcosSensillos extends JFrame { private static final int Ancho=200,Alto=150; public MarcosSensillos(){ setTitle("Mi Primer Marco"); setSize(Ancho,Alto); setLocation(Ancho/2,Alto/2); } public static void main(String args [] ) { MarcosSensillos marcos; marcos=new MarcosSensillos(); marcos.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); marcos.setVisible(true); } }
Abrir NetBeans y crear un proyecto llamado chekbooxen el mismo proyecto llamado Aplicaciones Swing Cdigos: String mensaje="Carreras Elegidas"; if(chkinformatica.isSelected()) { mensaje=mensaje+"\nInformatica"; } if(chksistema.isSelected()) { mensaje=mensaje+"\nSistemas"; } if(chkadministracion.isSelected()) {
mensaje=mensaje+"\nAdministracion"; } if(chkcontabilidad.isSelected()) { mensaje=mensaje+"\nContabilidad"; } if(chkcriminologia.isSelected()) { mensaje=mensaje+"\nCriminologia"; } if(chktec.isSelected()) { mensaje=mensaje+"\nTec.Informatica"; } if(chktecpro.isSelected()) { mensaje=mensaje+"\nTec.Programacion" ; } if(chktecges.isSelected()) { mensaje=mensaje+"\nTec.Gestion Procesos"; } areaRes.setText(mensaje); } private void jButton2ActionPerformed(java.awt.event .ActionEvent evt) {
areaRes.setText(""); if(chkinformatica.isSelected()) { chkinformatica.setSelected(false); } if(chksistema.isSelected()) { chksistema.setSelected(false); } if(chkadministracion.isSelected()) { chkadministracion.setSelected(false); } if(chkcontabilidad.isSelected()) { chkcontabilidad.setSelected(false); } if(chkcriminologia.isSelected()) { chkcriminologia.setSelected(false); } if(chktec.isSelected()) { chktec.setSelected(false); } if(chktecpro.isSelected()) { chktecpro.setSelected(false); } if(chktecges.isSelected()) { chktecges.setSelected(false); } }
break;
case 5:lblRespu.setText("Number five"); Abrir NetBeans y crear un proyecto llamado Nmeros Ingles el mismo proyecto llamado Aplicaciones Swing Cdigos: int numero; numero=Integer.parseInt(txtnum.getText ()); switch(numero){ case 0:lblRespu.setText("Number zero"); break; case 1:lblRespu.setText("Number one"); break; case 2:lblRespu.setText("Number two"); break; case 3:lblRespu.setText("Number three"); break; case 4:lblRespu.setText("Number four"); break; case 6:lblRespu.setText("Number six"); break; case 7:lblRespu.setText("Number seven"); break; case 8:lblRespu.setText("Number eight"); break; case 9:lblRespu.setText("Number nine"); break; case 10:lblRespu.setText("Number teen"); break; case 11:lblRespu.setText("Number teen one"); break; case 12:lblRespu.setText("Number teen two"); break; case 13:lblRespu.setText("Number teen three"); break; case 14:lblRespu.setText("Number teen four");
break; case 15:lblRespu.setText("Number teen five"); break; case 16:lblRespu.setText("Number teen six"); break; case 17:lblRespu.setText("Number teen seven"); break; case 18:lblRespu.setText("Number teen eight"); break; case 19:lblRespu.setText("Number teen nine"); break; case 20:lblRespu.setText("Number twelen"); break; default:lblRespu.setText("ingrese un numero del 1 al 20"); } } txtnum.setText(""); lblRespu.setText(""); } System.exit(0);