LOS VIDEOS ESTAN EN http://www.youtube.com/user/rvnrodrigo
mport javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
import java.util.*;
import java.text.DecimalFormat;
public class cuadro extends Applet
{
public void paint(Graphics g)
{
g.setColor(Color.red);
g.drawRect(20,30, 40, 20);
g.setColor(Color.blue);
g.drawString("ESTO ESTA AZUL", 50,90);
}
}
LOS VIDEOS ESTAN EN http://www.youtube.com/user/rvnrodrigo
PROMEDIO CON TRY CATCH
package promedio;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
import java.text.DecimalFormat;
public class EJEMPLO_PROMEDIO extends JFrame implements ActionListener
{
JLabel l1,l2,l3;
JTextField t1,t2,t3;
JButton b1,b2,b3;
public EJEMPLO_PROMEDIO()//CONSTRU
{
l1=new JLabel("CAL UNO ");
l2=new JLabel("CAL DOS");
l3=new JLabel("RESULTADO: ");
t1=new JTextField(20);
t2=new JTextField(20);
t3=new JTextField(20);
b1=new JButton("PROMEDIAR");
b2=new JButton("LIMPIAR");
b3=new JButton("CERRAR");
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
add(l1);
add(t1);
add(l2);
add(t2);
add(l3);
add(t3);
add(b1);
add(b2);
add(b3);
setLayout(new FlowLayout());
} //constructor
public void actionPerformed(ActionEvent e)
{
DecimalFormat n=new DecimalFormat("######.##");
double a,b,r;
if(e.getSource()==b1)
{
try
{
a=Double.parseDouble(t1.getText());
b=Double.parseDouble(t2.getText());
if(a>=0 && a<=10 && b>=0 && b<=10)
{
r=(a+b)/2;
t3.setText(String.valueOf(n.format(r)));
}
else
{
JOptionPane.showMessageDialog(null, "NUMEROS NO VALIDOS");
t1.setText("");
t2.setText("");
t3.setText("");
t1.requestFocus();
}//else
}//try
catch(NumberFormatException ev)
{
JOptionPane.showMessageDialog(null, "NO SON NUMEROS");
t1.setText("");
t2.setText("");
t3.setText("");
t1.requestFocus();
}
}//b1
if(e.getSource()==b2)
{
t1.setText("");
t2.setText("");
t3.setText("");
t1.requestFocus();
}//b2
if(e.getSource()==b3)
{
this.dispose();
}
}//action
public static void main(String args[])
{
EJEMPLO_PROMEDIO v1=new EJEMPLO_PROMEDIO();
v1.setSize(400,200);
v1.setTitle("PROMEDIO DE CALIFICACIONES.");
v1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
v1.setVisible(true);
}//main
}//clase
PROMEDIO CON TRY CATCH
package promedio;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
import java.text.DecimalFormat;
public class EJEMPLO_PROMEDIO extends JFrame implements ActionListener
{
JLabel l1,l2,l3;
JTextField t1,t2,t3;
JButton b1,b2,b3;
public EJEMPLO_PROMEDIO()//CONSTRU
{
l1=new JLabel("CAL UNO ");
l2=new JLabel("CAL DOS");
l3=new JLabel("RESULTADO: ");
t1=new JTextField(20);
t2=new JTextField(20);
t3=new JTextField(20);
b1=new JButton("PROMEDIAR");
b2=new JButton("LIMPIAR");
b3=new JButton("CERRAR");
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
add(l1);
add(t1);
add(l2);
add(t2);
add(l3);
add(t3);
add(b1);
add(b2);
add(b3);
setLayout(new FlowLayout());
} //constructor
public void actionPerformed(ActionEvent e)
{
DecimalFormat n=new DecimalFormat("######.##");
double a,b,r;
if(e.getSource()==b1)
{
try
{
a=Double.parseDouble(t1.getText());
b=Double.parseDouble(t2.getText());
if(a>=0 && a<=10 && b>=0 && b<=10)
{
r=(a+b)/2;
t3.setText(String.valueOf(n.format(r)));
}
else
{
JOptionPane.showMessageDialog(null, "NUMEROS NO VALIDOS");
t1.setText("");
t2.setText("");
t3.setText("");
t1.requestFocus();
}//else
}//try
catch(NumberFormatException ev)
{
JOptionPane.showMessageDialog(null, "NO SON NUMEROS");
t1.setText("");
t2.setText("");
t3.setText("");
t1.requestFocus();
}
}//b1
if(e.getSource()==b2)
{
t1.setText("");
t2.setText("");
t3.setText("");
t1.requestFocus();
}//b2
if(e.getSource()==b3)
{
this.dispose();
}
}//action
public static void main(String args[])
{
EJEMPLO_PROMEDIO v1=new EJEMPLO_PROMEDIO();
v1.setSize(400,200);
v1.setTitle("PROMEDIO DE CALIFICACIONES.");
v1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
v1.setVisible(true);
}//main
}//clase
LOS VIDEOS ESTAN EN http://www.youtube.com/user/rvnrodrigo
COMPLEMENTO DE MENU SOBRE MENU
CLASE RESTANDO
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
import java.util.*;
import java.text.DecimalFormat;
class RESTANDO extends SUMANDO
{
DecimalFormat n = new DecimalFormat("#########.###");
public void resta2()
{
try
{
pedir2();
r=a-b;
JOptionPane.showMessageDialog(null, "LA RESTA ES: "+n.format(r));
}catch(NumberFormatException e)
{
JOptionPane.showMessageDialog(null, "NO SON NUMEROS");
}
}//public
public void resta3()
{
try
{
pedir3();
r=a-b-c;
JOptionPane.showMessageDialog(null, "LA RESTA ES: "+n.format(r));
}catch(NumberFormatException e)
{
JOptionPane.showMessageDialog(null, "NO SON NUMEROS");
}
}//public
public void f_menu_restando()
{
int opc;
do
{
opc=Integer.parseInt(JOptionPane.showInputDialog("1.-RESTA DE DOS\n2.-RESTA DE TRES\n3.-SALIR"));
switch(opc)
{
case 1:
resta2();
break;
case 2:
resta3();
break;
case 3:
salir();
break;
default:
JOptionPane.showMessageDialog(null, "OPCION NO VALIDA");
break;
}
}while(opc!=3);//while
} //funcion menu
}//RESTANDO
COMPLEMENTO DE MENU SOBRE MENU
CLASE RESTANDO
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
import java.util.*;
import java.text.DecimalFormat;
class RESTANDO extends SUMANDO
{
DecimalFormat n = new DecimalFormat("#########.###");
public void resta2()
{
try
{
pedir2();
r=a-b;
JOptionPane.showMessageDialog(null, "LA RESTA ES: "+n.format(r));
}catch(NumberFormatException e)
{
JOptionPane.showMessageDialog(null, "NO SON NUMEROS");
}
}//public
public void resta3()
{
try
{
pedir3();
r=a-b-c;
JOptionPane.showMessageDialog(null, "LA RESTA ES: "+n.format(r));
}catch(NumberFormatException e)
{
JOptionPane.showMessageDialog(null, "NO SON NUMEROS");
}
}//public
public void f_menu_restando()
{
int opc;
do
{
opc=Integer.parseInt(JOptionPane.showInputDialog("1.-RESTA DE DOS\n2.-RESTA DE TRES\n3.-SALIR"));
switch(opc)
{
case 1:
resta2();
break;
case 2:
resta3();
break;
case 3:
salir();
break;
default:
JOptionPane.showMessageDialog(null, "OPCION NO VALIDA");
break;
}
}while(opc!=3);//while
} //funcion menu
}//RESTANDO
LOS VIDEOS ESTAN EN http://www.youtube.com/user/rvnrodrigo
DO_WHILE
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
import java.util.*;
class operaciones
{
double a,b,r;
public void suma()
{
a= Double.parseDouble(JOptionPane.showInputDialog("DAME A: "));
b= Double.parseDouble(JOptionPane.showInputDialog("DAME B: "));
r=a+b;
JOptionPane.showMessageDialog(null, "LA SUMA ES: "+r);
}
public void resta()
{
a= Double.parseDouble(JOptionPane.showInputDialog("DAME A: "));
b= Double.parseDouble(JOptionPane.showInputDialog("DAME B: "));
r=a-b;
JOptionPane.showMessageDialog(null, "LA RESTA ES: "+r);
}
}
MENU COMPLETO
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
import java.util.*;
class MENU_COMPLETO extends operaciones
{
int opc;
public void f_menu()
{
do
{
opc=Integer.parseInt(JOptionPane.showInputDialog("1.-SUMA\n2.-RESTA\n3.-SALIR"));
switch(opc)
{
case 1:
suma();
break;
case 2:
resta();
break;
case 3:
JOptionPane.showMessageDialog(null, "ADIOS");
break;
default:
JOptionPane.showMessageDialog(null, "NO ES UN NUMERO DEL 1 AL 3");
break;
}//switch
}while(opc!=3);
}//f_menu
}
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.text.DecimalFormat;
public class principal{
public static void main(String args[])
{
MENU_COMPLETO p1=new MENU_COMPLETO();
p1.f_menu();
}
}
DO_WHILE
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
import java.util.*;
class operaciones
{
double a,b,r;
public void suma()
{
a= Double.parseDouble(JOptionPane.showInputDialog("DAME A: "));
b= Double.parseDouble(JOptionPane.showInputDialog("DAME B: "));
r=a+b;
JOptionPane.showMessageDialog(null, "LA SUMA ES: "+r);
}
public void resta()
{
a= Double.parseDouble(JOptionPane.showInputDialog("DAME A: "));
b= Double.parseDouble(JOptionPane.showInputDialog("DAME B: "));
r=a-b;
JOptionPane.showMessageDialog(null, "LA RESTA ES: "+r);
}
}
MENU COMPLETO
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
import java.util.*;
class MENU_COMPLETO extends operaciones
{
int opc;
public void f_menu()
{
do
{
opc=Integer.parseInt(JOptionPane.showInputDialog("1.-SUMA\n2.-RESTA\n3.-SALIR"));
switch(opc)
{
case 1:
suma();
break;
case 2:
resta();
break;
case 3:
JOptionPane.showMessageDialog(null, "ADIOS");
break;
default:
JOptionPane.showMessageDialog(null, "NO ES UN NUMERO DEL 1 AL 3");
break;
}//switch
}while(opc!=3);
}//f_menu
}
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.text.DecimalFormat;
public class principal{
public static void main(String args[])
{
MENU_COMPLETO p1=new MENU_COMPLETO();
p1.f_menu();
}
}
LOS VIDEOS ESTAN EN http://www.youtube.com/user/rvnrodrigo
MENU SOBRE MENU
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.text.DecimalFormat;
public class PRINCIPAL{
public static void main(String args[])
{
MENU_PRINCIPAL h1=new MENU_PRINCIPAL();
h1.f_menu_principal();
}
}
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
import java.util.*;
class pedir
{
double a,b,c,r;
public void pedir2()
{
a= Double.parseDouble(JOptionPane.showInputDialog("DAME A: "));
b= Double.parseDouble(JOptionPane.showInputDialog("DAME B: "));
}
public void pedir3()
{
a= Double.parseDouble(JOptionPane.showInputDialog("DAME A: "));
b= Double.parseDouble(JOptionPane.showInputDialog("DAME B: "));
c= Double.parseDouble(JOptionPane.showInputDialog("DAME C: "));
}
public void salir()
{
JOptionPane.showMessageDialog(null, "ADIOS");
}
}
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
import java.util.*;
class SUMANDO extends pedir
{
public void f_menu_sumando()
{
int opc;
do
{
opc=Integer.parseInt(JOptionPane.showInputDialog("1.-SUMA DE DOS\n2.-SUMA DE TRES\n3.-SALIR"));
switch(opc)
{
case 1:
suma2();
break;
case 2:
suma3();
break;
case 3:
salir();
break;
default:
JOptionPane.showMessageDialog(null, "OPCION NO VALIDA");
break;
}
}while(opc!=3);//while
} //funcion menu
public void suma2()
{
pedir2();
r=a+b;
JOptionPane.showMessageDialog(null, "LA SUMA ES: "+r);
}
public void suma3()
{
pedir3();
r=a+b+c;
JOptionPane.showMessageDialog(null, "LA SUMA DE TRES ES: "+r);
}
}//CLASE
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
import java.util.*;
class MENU_PRINCIPAL extends SUMANDO
{
int opc;
public void f_menu_principal()
{
do
{
opc=Integer.parseInt(JOptionPane.showInputDialog("1.-SUMANDO\n2.-SALIR"));
switch(opc)
{
case 1:
f_menu_sumando();
break;
case 2:
salir();
break;
default:
JOptionPane.showMessageDialog(null, "OPCION NO VALIDA");
break;
}//switch
}while(opc!=2);
}//funcion
}//clase
MENU SOBRE MENU
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.text.DecimalFormat;
public class PRINCIPAL{
public static void main(String args[])
{
MENU_PRINCIPAL h1=new MENU_PRINCIPAL();
h1.f_menu_principal();
}
}
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
import java.util.*;
class pedir
{
double a,b,c,r;
public void pedir2()
{
a= Double.parseDouble(JOptionPane.showInputDialog("DAME A: "));
b= Double.parseDouble(JOptionPane.showInputDialog("DAME B: "));
}
public void pedir3()
{
a= Double.parseDouble(JOptionPane.showInputDialog("DAME A: "));
b= Double.parseDouble(JOptionPane.showInputDialog("DAME B: "));
c= Double.parseDouble(JOptionPane.showInputDialog("DAME C: "));
}
public void salir()
{
JOptionPane.showMessageDialog(null, "ADIOS");
}
}
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
import java.util.*;
class SUMANDO extends pedir
{
public void f_menu_sumando()
{
int opc;
do
{
opc=Integer.parseInt(JOptionPane.showInputDialog("1.-SUMA DE DOS\n2.-SUMA DE TRES\n3.-SALIR"));
switch(opc)
{
case 1:
suma2();
break;
case 2:
suma3();
break;
case 3:
salir();
break;
default:
JOptionPane.showMessageDialog(null, "OPCION NO VALIDA");
break;
}
}while(opc!=3);//while
} //funcion menu
public void suma2()
{
pedir2();
r=a+b;
JOptionPane.showMessageDialog(null, "LA SUMA ES: "+r);
}
public void suma3()
{
pedir3();
r=a+b+c;
JOptionPane.showMessageDialog(null, "LA SUMA DE TRES ES: "+r);
}
}//CLASE
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
import java.util.*;
class MENU_PRINCIPAL extends SUMANDO
{
int opc;
public void f_menu_principal()
{
do
{
opc=Integer.parseInt(JOptionPane.showInputDialog("1.-SUMANDO\n2.-SALIR"));
switch(opc)
{
case 1:
f_menu_sumando();
break;
case 2:
salir();
break;
default:
JOptionPane.showMessageDialog(null, "OPCION NO VALIDA");
break;
}//switch
}while(opc!=2);
}//funcion
}//clase
Publicado por
Nada Hay Imposible para Dios Lucas 1:37
lunes, 29 de agosto de 2011
Etiquetas:
LINK COMPRA DE ACCIONES
LOS VIDEOS ESTAN EN http://www.youtube.com/user/rvnrodrigo
GRAFICAS SEGUNDO CUBO GIRADO
import com.sun.j3d.utils.applet.MainFrame;
import javax.swing.*;
import java.awt.*;
import com.sun.j3d.utils.universe.SimpleUniverse;
import com.sun.j3d.utils.geometry.ColorCube;
import javax.media.j3d.Canvas3D;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.*;
import java.applet.Applet;
public class GRAFICA_CUBO2 extends Applet
{
public GRAFICA_CUBO2()
{
setLayout(new BorderLayout());
GraphicsConfiguration config=SimpleUniverse.getPreferredConfiguration();
Canvas3D canvas=new Canvas3D(config);
add("Center",canvas);
BranchGroup escena=createSceneGraph();
SimpleUniverse su=new SimpleUniverse(canvas);
su.getViewingPlatform().setNominalViewingTransform();
su.addBranchGraph(escena);
}//fin de constructor
public BranchGroup createSceneGraph()
{
BranchGroup obj=new BranchGroup();
Transform3D rotacion=new Transform3D();
Transform3D rotacion2=new Transform3D();
rotacion.rotX(Math.PI/4.0d);
rotacion2.rotY(Math.PI/3.0d);
rotacion.mul(rotacion2);
TransformGroup objrotacion=new TransformGroup(rotacion);
obj.addChild(objrotacion);
objrotacion.addChild(new ColorCube(0.5));
obj.compile();
return obj;
}
public static void main(String args[])
{
int a,b;
a=Integer.parseInt(JOptionPane.showInputDialog("DAME ALTO: "));
b=Integer.parseInt(JOptionPane.showInputDialog("DAME ANCHO: "));
Frame frame=new MainFrame(new GRAFICA_CUBO2(),a,b);
}
}
import javax.swing.*;
import java.awt.*;
import com.sun.j3d.utils.universe.SimpleUniverse;
import com.sun.j3d.utils.geometry.ColorCube;
import javax.media.j3d.Canvas3D;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.*;
import java.applet.Applet;
public class GRAFICA_CUBO2 extends Applet
{
public GRAFICA_CUBO2()
{
setLayout(new BorderLayout());
GraphicsConfiguration config=SimpleUniverse.getPreferredConfiguration();
Canvas3D canvas=new Canvas3D(config);
add("Center",canvas);
BranchGroup escena=createSceneGraph();
SimpleUniverse su=new SimpleUniverse(canvas);
su.getViewingPlatform().setNominalViewingTransform();
su.addBranchGraph(escena);
}//fin de constructor
public BranchGroup createSceneGraph()
{
BranchGroup obj=new BranchGroup();
Transform3D rotacion=new Transform3D();
Transform3D rotacion2=new Transform3D();
rotacion.rotX(Math.PI/4.0d);
rotacion2.rotY(Math.PI/3.0d);
rotacion.mul(rotacion2);
TransformGroup objrotacion=new TransformGroup(rotacion);
obj.addChild(objrotacion);
objrotacion.addChild(new ColorCube(0.5));
obj.compile();
return obj;
}
public static void main(String args[])
{
int a,b;
a=Integer.parseInt(JOptionPane.showInputDialog("DAME ALTO: "));
b=Integer.parseInt(JOptionPane.showInputDialog("DAME ANCHO: "));
Frame frame=new MainFrame(new GRAFICA_CUBO2(),a,b);
}
}
LOS VIDEOS ESTAN EN http://www.youtube.com/user/rvnrodrigo
GRAFICAS PRIMER CUBO
import com.sun.j3d.utils.applet.MainFrame;
import javax.swing.*;
import java.awt.*;
import com.sun.j3d.utils.universe.SimpleUniverse;
import com.sun.j3d.utils.geometry.ColorCube;
import javax.media.j3d.Canvas3D;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.*;
import java.applet.Applet;
public final class CUBO extends Applet
{
public CUBO()
{
setLayout(new BorderLayout());
GraphicsConfiguration config=SimpleUniverse.getPreferredConfiguration();
Canvas3D canvas=new Canvas3D(config);
add("Center",canvas);
BranchGroup escena=createsceneGraph();
escena.compile();
SimpleUniverse simple_uni=new SimpleUniverse(canvas);
simple_uni.getViewingPlatform().setNominalViewingTransform();
simple_uni.addBranchGraph(escena);
}//fin del constructor
public BranchGroup createsceneGraph()
{
BranchGroup obj=new BranchGroup();
obj.addChild(new ColorCube(0.5));
return obj;
}
public static void main(String args[])
{
Frame frame= new MainFrame(new CUBO(),400,400);
}
}
//RECORDAR INSTALAR LA API
//http://www.oracle.com/technetwork/java/javase/tech/index-jsp-138252.html
import javax.swing.*;
import java.awt.*;
import com.sun.j3d.utils.universe.SimpleUniverse;
import com.sun.j3d.utils.geometry.ColorCube;
import javax.media.j3d.Canvas3D;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.*;
import java.applet.Applet;
public final class CUBO extends Applet
{
public CUBO()
{
setLayout(new BorderLayout());
GraphicsConfiguration config=SimpleUniverse.getPreferredConfiguration();
Canvas3D canvas=new Canvas3D(config);
add("Center",canvas);
BranchGroup escena=createsceneGraph();
escena.compile();
SimpleUniverse simple_uni=new SimpleUniverse(canvas);
simple_uni.getViewingPlatform().setNominalViewingTransform();
simple_uni.addBranchGraph(escena);
}//fin del constructor
public BranchGroup createsceneGraph()
{
BranchGroup obj=new BranchGroup();
obj.addChild(new ColorCube(0.5));
return obj;
}
public static void main(String args[])
{
Frame frame= new MainFrame(new CUBO(),400,400);
}
}
//RECORDAR INSTALAR LA API
//http://www.oracle.com/technetwork/java/javase/tech/index-jsp-138252.html
LOS VIDEOS ESTAN EN http://www.youtube.com/user/rvnrodrigo
CURSO EJEMPLO 30
import javax.swing.*;
import java.awt.*;
public class foco_principal
{
public static void main(String args[])
{
des_foco f1=new des_foco();
f1.enc();
f1.cal();
f1.apa();
}
}
class des_foco
{
public void enc()
{
System.out.print("EL FOCO SE ENCIENDE \n");
}
public void cal()
{
System.out.print("EL FOCO SE CALIENTA EN 2 MINUTOS\n");
}
public void apa()
{
System.out.print("SE APAGA EL FOCO\n");
}
}
import java.awt.*;
public class foco_principal
{
public static void main(String args[])
{
des_foco f1=new des_foco();
f1.enc();
f1.cal();
f1.apa();
}
}
class des_foco
{
public void enc()
{
System.out.print("EL FOCO SE ENCIENDE \n");
}
public void cal()
{
System.out.print("EL FOCO SE CALIENTA EN 2 MINUTOS\n");
}
public void apa()
{
System.out.print("SE APAGA EL FOCO\n");
}
}
LOS VIDEOS ESTAN EN http://www.youtube.com/user/rvnrodrigo
CURSO JAVA CICLO DO_WHILE MENU 1
import javax.swing.*;
public class menu
{
public static void main(String args[])
{
desa e1=new desa();
e1.menu();
}
}
class desa
{
double a,b,r;
int opc;
public void pedir()
{
a=Double.parseDouble(JOptionPane.showInputDialog("DAME EL PRIMER NUMERO: "));
b=Double.parseDouble(JOptionPane.showInputDialog("DAME EL SEGUNDO NUMERO: "));
}
public void suma()
{
pedir();
r=a+b;
JOptionPane.showMessageDialog(null,"LA SUMA ES: "+r);
}
public void resta()
{
pedir();
r=a-b;
JOptionPane.showMessageDialog(null,"LA SUMA ES: "+r);
}
public void menu()
{
do
{
opc=Integer.parseInt(JOptionPane.showInputDialog("1.-SUMA\n2.-RESTA\n3.-SALIR"));
switch(opc)
{
case 1:
suma();
break;
case 2:
resta();
break;
case 3:
JOptionPane.showMessageDialog(null,"ADIOS GRACIAS");
}
}while (opc > 0 && opc < 3);
}
}
public class menu
{
public static void main(String args[])
{
desa e1=new desa();
e1.menu();
}
}
class desa
{
double a,b,r;
int opc;
public void pedir()
{
a=Double.parseDouble(JOptionPane.showInputDialog("DAME EL PRIMER NUMERO: "));
b=Double.parseDouble(JOptionPane.showInputDialog("DAME EL SEGUNDO NUMERO: "));
}
public void suma()
{
pedir();
r=a+b;
JOptionPane.showMessageDialog(null,"LA SUMA ES: "+r);
}
public void resta()
{
pedir();
r=a-b;
JOptionPane.showMessageDialog(null,"LA SUMA ES: "+r);
}
public void menu()
{
do
{
opc=Integer.parseInt(JOptionPane.showInputDialog("1.-SUMA\n2.-RESTA\n3.-SALIR"));
switch(opc)
{
case 1:
suma();
break;
case 2:
resta();
break;
case 3:
JOptionPane.showMessageDialog(null,"ADIOS GRACIAS");
}
}while (opc > 0 && opc < 3);
}
}
LOS VIDEOS ESTAN EN http://www.youtube.com/user/rvnrodrigo
CURSO JAVA SCANNER WHILE Y FUNCION IMP
import javax.swing.*;
import java.awt.*;
import java.util.*;
public class SCANNER
{
public static void main(String args[])
{
int fin;
do
{
Scanner c=new Scanner(System.in);
int a,b,r;
imp("DAME EL PRIMER VALOR: ");
a=c.nextInt();
imp("DAME EL SEGUNDO VALOR: ");
b=c.nextInt();
r=a+b;
imp("LA SUMA ES: "+r);
imp("\nPARA SALIR PRESIONA ( -1 )");
fin=c.nextInt();
}while(fin!=-1);
}
public static String imp(String x)
{
System.out.print(x);
return x;
}
}
import java.awt.*;
import java.util.*;
public class SCANNER
{
public static void main(String args[])
{
int fin;
do
{
Scanner c=new Scanner(System.in);
int a,b,r;
imp("DAME EL PRIMER VALOR: ");
a=c.nextInt();
imp("DAME EL SEGUNDO VALOR: ");
b=c.nextInt();
r=a+b;
imp("LA SUMA ES: "+r);
imp("\nPARA SALIR PRESIONA ( -1 )");
fin=c.nextInt();
}while(fin!=-1);
}
public static String imp(String x)
{
System.out.print(x);
return x;
}
}
LOS VIDEOS ESTAN EN http://www.youtube.com/user/rvnrodrigo
PEDIR DATOS POR ARGUMENTOS POR JOPTIONPANE.SHOWI
import javax.swing.*;
public class pedir_caja
{
public static void main(String args[])
{
double a,b,r;
a=p();
b=p();
r=a+b;
imp("LA SUMA ES: "+r);
}
public static double p()
{
double x;
x=Double.parseDouble(JOptionPane.showInputDialog("DAME UN NUMERO: "));
return x;
}
public static void imp(String x)
{
JOptionPane.showMessageDialog(null,x);
}
}
public class pedir_caja
{
public static void main(String args[])
{
double a,b,r;
a=p();
b=p();
r=a+b;
imp("LA SUMA ES: "+r);
}
public static double p()
{
double x;
x=Double.parseDouble(JOptionPane.showInputDialog("DAME UN NUMERO: "));
return x;
}
public static void imp(String x)
{
JOptionPane.showMessageDialog(null,x);
}
}
LOS VIDEOS ESTAN EN http://www.youtube.com/user/rvnrodrigo
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
public class promedio2 extends JApplet implements ActionListener
{
JTextField t1,t2,t3,t4;
JButton b1,b2;
public void init()
{
Container c=getContentPane();
c.setLayout(new FlowLayout());
t1=new JTextField(10);
t2=new JTextField(10);
t3=new JTextField(15);
t4=new JTextField(15);
b1=new JButton("PROMEDIAR");
b2=new JButton("LIMPIAR");
c.add(t1);
c.add(t2);
c.add(t3);
c.add(t4);
c.add(b1);
c.add(b2);
b1.addActionListener(this);
b2.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
double a,b,r;
if(e.getSource()==b1)
{
a=Double.parseDouble(t1.getText());
b=Double.parseDouble(t2.getText());
if(a<0 || a>10 )
{
JOptionPane.showMessageDialog(null,"CALIFICACIÓN UNO ( NO VALIDA )");
t1.setText(" ");
t2.setText(" ");
}
if(b<0 || b>10 )
{
JOptionPane.showMessageDialog(null,"CALIFICACIÓN DOS ( NO VALIDA )");
t1.setText(" ");
t2.setText(" ");
}
if(a>=0 && a<=10 && b>=0 && b<=10)
{
r=(a+b)/2;
if(r>=0 && r<=5.9)
{
t3.setText(String.valueOf(r));
t4.setText("REPROBADO");
}//r
if(r>=6 && r<=10)
{
t3.setText(String.valueOf(r));
t4.setText("APROBADO");
}
}
}//boton
if(e.getSource()==b2)
{
t1.setText(" ");
t2.setText(" ");
t3.setText(" ");
t4.setText(" ");
}
}//ACTION
}//CLASE
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
public class promedio2 extends JApplet implements ActionListener
{
JTextField t1,t2,t3,t4;
JButton b1,b2;
public void init()
{
Container c=getContentPane();
c.setLayout(new FlowLayout());
t1=new JTextField(10);
t2=new JTextField(10);
t3=new JTextField(15);
t4=new JTextField(15);
b1=new JButton("PROMEDIAR");
b2=new JButton("LIMPIAR");
c.add(t1);
c.add(t2);
c.add(t3);
c.add(t4);
c.add(b1);
c.add(b2);
b1.addActionListener(this);
b2.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
double a,b,r;
if(e.getSource()==b1)
{
a=Double.parseDouble(t1.getText());
b=Double.parseDouble(t2.getText());
if(a<0 || a>10 )
{
JOptionPane.showMessageDialog(null,"CALIFICACIÓN UNO ( NO VALIDA )");
t1.setText(" ");
t2.setText(" ");
}
if(b<0 || b>10 )
{
JOptionPane.showMessageDialog(null,"CALIFICACIÓN DOS ( NO VALIDA )");
t1.setText(" ");
t2.setText(" ");
}
if(a>=0 && a<=10 && b>=0 && b<=10)
{
r=(a+b)/2;
if(r>=0 && r<=5.9)
{
t3.setText(String.valueOf(r));
t4.setText("REPROBADO");
}//r
if(r>=6 && r<=10)
{
t3.setText(String.valueOf(r));
t4.setText("APROBADO");
}
}
}//boton
if(e.getSource()==b2)
{
t1.setText(" ");
t2.setText(" ");
t3.setText(" ");
t4.setText(" ");
}
}//ACTION
}//CLASE
LOS VIDEOS ESTAN EN http://www.youtube.com/user/rvnrodrigo
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
public class promedio1 extends JApplet implements ActionListener
{
JTextField t1,t2,t3,t4;
JButton b1,b2;
public void init()
{
Container c=getContentPane();
c.setLayout(new FlowLayout());
t1=new JTextField(10);
t2=new JTextField(10);
t3=new JTextField(15);
t4=new JTextField(15);
b1=new JButton("PROMEDIAR");
b2=new JButton("LIMPIAR");
c.add(t1);
c.add(t2);
c.add(t3);
c.add(t4);
c.add(b1);
c.add(b2);
b1.addActionListener(this);
b2.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
double a,b,r;
if(e.getSource()==b1)
{
a=Double.parseDouble(t1.getText());
b=Double.parseDouble(t2.getText());
r=(a+b)/2;
if(r<0 || r>10)
{
t4.setText("ERROR CAL NO VALIDA");
}
else
{
if(r>=0 && r<=5)
{
t3.setText(String.valueOf(r));
t4.setText("REPROBADO");
}
if(r>=6 && r<=10)
{
t3.setText(String.valueOf(r));
t4.setText("APROBADO");
}
}//else
}//boton
if(e.getSource()==b2)
{
t1.setText(" ");
t2.setText(" ");
t3.setText(" ");
t4.setText(" ");
}
}//ACTION
}//CLASE
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
public class promedio1 extends JApplet implements ActionListener
{
JTextField t1,t2,t3,t4;
JButton b1,b2;
public void init()
{
Container c=getContentPane();
c.setLayout(new FlowLayout());
t1=new JTextField(10);
t2=new JTextField(10);
t3=new JTextField(15);
t4=new JTextField(15);
b1=new JButton("PROMEDIAR");
b2=new JButton("LIMPIAR");
c.add(t1);
c.add(t2);
c.add(t3);
c.add(t4);
c.add(b1);
c.add(b2);
b1.addActionListener(this);
b2.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
double a,b,r;
if(e.getSource()==b1)
{
a=Double.parseDouble(t1.getText());
b=Double.parseDouble(t2.getText());
r=(a+b)/2;
if(r<0 || r>10)
{
t4.setText("ERROR CAL NO VALIDA");
}
else
{
if(r>=0 && r<=5)
{
t3.setText(String.valueOf(r));
t4.setText("REPROBADO");
}
if(r>=6 && r<=10)
{
t3.setText(String.valueOf(r));
t4.setText("APROBADO");
}
}//else
}//boton
if(e.getSource()==b2)
{
t1.setText(" ");
t2.setText(" ");
t3.setText(" ");
t4.setText(" ");
}
}//ACTION
}//CLASE
LOS VIDEOS ESTAN EN http://www.youtube.com/user/rvnrodrigo
import javax.swing.*;
import java.awt.*;
import java.applet.Applet;
import java.awt.event.*;
public class sumar_jcheckbox extends JApplet implements ItemListener
{
JTextField t1,t2,t3;
JCheckBox suma,resta,multi,divi;
public void init()
{
Container c=getContentPane();
c.setLayout(new FlowLayout());
t1=new JTextField(30);
t2=new JTextField(30);
t3=new JTextField(40);
suma=new JCheckBox("SUMAR");
resta=new JCheckBox("RESTA");
multi=new JCheckBox("MULTI");
divi=new JCheckBox("DIVI");
c.add(t1);
c.add(t2);
c.add(t3);
c.add(suma);
c.add(resta);
c.add(multi);
c.add(divi);
suma.addItemListener(this);
resta.addItemListener(this);
multi.addItemListener(this);
divi.addItemListener(this);
}
public void itemStateChanged(ItemEvent e)
{
double a,b,r;
if(e.getItemSelectable()==suma)
{
a=Double.parseDouble(t1.getText());
b=Double.parseDouble(t2.getText());
r=a+b;
t3.setText(String.valueOf(r));
}
if(e.getItemSelectable()==resta)
{
a=Double.parseDouble(t1.getText());
b=Double.parseDouble(t2.getText());
r=a-b;
t3.setText(String.valueOf(r));
}
if(e.getItemSelectable()==multi)
{
a=Double.parseDouble(t1.getText());
b=Double.parseDouble(t2.getText());
r=a*b;
t3.setText(String.valueOf(r));
}
if(e.getItemSelectable()==divi)
{
a=Double.parseDouble(t1.getText());
b=Double.parseDouble(t2.getText());
r=a/b;
t3.setText(String.valueOf(r));
}
}
}
import javax.swing.*;
import java.awt.*;
import java.applet.Applet;
import java.awt.event.*;
public class sumar_jcheckbox extends JApplet implements ItemListener
{
JTextField t1,t2,t3;
JCheckBox suma,resta,multi,divi;
public void init()
{
Container c=getContentPane();
c.setLayout(new FlowLayout());
t1=new JTextField(30);
t2=new JTextField(30);
t3=new JTextField(40);
suma=new JCheckBox("SUMAR");
resta=new JCheckBox("RESTA");
multi=new JCheckBox("MULTI");
divi=new JCheckBox("DIVI");
c.add(t1);
c.add(t2);
c.add(t3);
c.add(suma);
c.add(resta);
c.add(multi);
c.add(divi);
suma.addItemListener(this);
resta.addItemListener(this);
multi.addItemListener(this);
divi.addItemListener(this);
}
public void itemStateChanged(ItemEvent e)
{
double a,b,r;
if(e.getItemSelectable()==suma)
{
a=Double.parseDouble(t1.getText());
b=Double.parseDouble(t2.getText());
r=a+b;
t3.setText(String.valueOf(r));
}
if(e.getItemSelectable()==resta)
{
a=Double.parseDouble(t1.getText());
b=Double.parseDouble(t2.getText());
r=a-b;
t3.setText(String.valueOf(r));
}
if(e.getItemSelectable()==multi)
{
a=Double.parseDouble(t1.getText());
b=Double.parseDouble(t2.getText());
r=a*b;
t3.setText(String.valueOf(r));
}
if(e.getItemSelectable()==divi)
{
a=Double.parseDouble(t1.getText());
b=Double.parseDouble(t2.getText());
r=a/b;
t3.setText(String.valueOf(r));
}
}
}
LOS VIDEOS ESTAN EN http://www.youtube.com/user/rvnrodrigo
import javax.swing.*;
import java.awt.*;
import java.applet.Applet;
import java.awt.event.*;
public class sumar_jcheckbox extends JApplet implements ItemListener
{
JTextField t1,t2,t3;
JCheckBox suma;
public void init()
{
Container c=getContentPane();
c.setLayout(new FlowLayout());
t1=new JTextField("VALOR UNO: ",30);
t2=new JTextField("VALOR DOS",30);
t3=new JTextField("RESULTADO",30);
suma=new JCheckBox("SUMAR");
c.add(t1);
c.add(t2);
c.add(t3);
c.add(suma);
suma.addItemListener(this);
}
public void itemStateChanged(ItemEvent e)
{
double a,b,r;
if(e.getItemSelectable()==suma)
{
a=Double.parseDouble(t1.getText());
b=Double.parseDouble(t2.getText());
r=a+b;
t3.setText(String.valueOf(r));
}
}
}
import javax.swing.*;
import java.awt.*;
import java.applet.Applet;
import java.awt.event.*;
public class sumar_jcheckbox extends JApplet implements ItemListener
{
JTextField t1,t2,t3;
JCheckBox suma;
public void init()
{
Container c=getContentPane();
c.setLayout(new FlowLayout());
t1=new JTextField("VALOR UNO: ",30);
t2=new JTextField("VALOR DOS",30);
t3=new JTextField("RESULTADO",30);
suma=new JCheckBox("SUMAR");
c.add(t1);
c.add(t2);
c.add(t3);
c.add(suma);
suma.addItemListener(this);
}
public void itemStateChanged(ItemEvent e)
{
double a,b,r;
if(e.getItemSelectable()==suma)
{
a=Double.parseDouble(t1.getText());
b=Double.parseDouble(t2.getText());
r=a+b;
t3.setText(String.valueOf(r));
}
}
}
LOS VIDEOS ESTAN EN http://www.youtube.com/user/rvnrodrigo
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
public class CHEC_EJE1 extends JApplet implements ItemListener
{
JTextField t1;
JCheckBox ch1;
public void init()
{
Container c=getContentPane();
c.setLayout(new FlowLayout());
t1=new JTextField("texto uno",30);
ch1=new JCheckBox("SALUDO");
c.add(t1);
c.add(ch1);
ch1.addItemListener(this);
}
public void itemStateChanged(ItemEvent e)
{
if(e.getItemSelectable()==ch1)
{
t1.setText("BIENVENIDO A SWING CON JCHECKBOX");
}
}
}
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
public class CHEC_EJE1 extends JApplet implements ItemListener
{
JTextField t1;
JCheckBox ch1;
public void init()
{
Container c=getContentPane();
c.setLayout(new FlowLayout());
t1=new JTextField("texto uno",30);
ch1=new JCheckBox("SALUDO");
c.add(t1);
c.add(ch1);
ch1.addItemListener(this);
}
public void itemStateChanged(ItemEvent e)
{
if(e.getItemSelectable()==ch1)
{
t1.setText("BIENVENIDO A SWING CON JCHECKBOX");
}
}
}
LOS VIDEOS ESTAN EN http://www.youtube.com/user/rvnrodrigo
import javax.swing.*;
import java.util.*;
import java.awt.event.*;
import java.applet.Applet;
import java.awt.*;
public class TEXTO_UNO extends JApplet implements ActionListener
{
JLabel l1;
JButton b1;
JTextField t1;
public void init()
{
Container c=getContentPane();
c.setLayout(new FlowLayout());
l1=new JLabel("NOMBRE: ");
t1=new JTextField(30);
b1=new JButton("SALUDOS");
c.add(l1);
c.add(t1);
c.add(b1);
b1.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)
{
t1.setText("BIENVENIDO A SWING");
}
}
}
import javax.swing.*;
import java.util.*;
import java.awt.event.*;
import java.applet.Applet;
import java.awt.*;
public class TEXTO_UNO extends JApplet implements ActionListener
{
JLabel l1;
JButton b1;
JTextField t1;
public void init()
{
Container c=getContentPane();
c.setLayout(new FlowLayout());
l1=new JLabel("NOMBRE: ");
t1=new JTextField(30);
b1=new JButton("SALUDOS");
c.add(l1);
c.add(t1);
c.add(b1);
b1.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)
{
t1.setText("BIENVENIDO A SWING");
}
}
}
LOS VIDEOS ESTAN EN http://www.youtube.com/user/rvnrodrigo
import javax.swing.*;
import java.util.*;
import java.awt.event.*;
import java.applet.Applet;
import java.awt.*;
public class L1 extends JApplet
{
JLabel nom,dir,tel;
public void init()
{
Container c=getContentPane();
c.setLayout(new FlowLayout());
nom=new JLabel("rodrigo villanueva ");
dir=new JLabel("aragon");
tel=new JLabel("6798798");
c.add(nom);
c.add(dir);
c.add(tel);
}
}
import javax.swing.*;
import java.util.*;
import java.awt.event.*;
import java.applet.Applet;
import java.awt.*;
public class L1 extends JApplet
{
JLabel nom,dir,tel;
public void init()
{
Container c=getContentPane();
c.setLayout(new FlowLayout());
nom=new JLabel("rodrigo villanueva ");
dir=new JLabel("aragon");
tel=new JLabel("6798798");
c.add(nom);
c.add(dir);
c.add(tel);
}
}
LOS VIDEOS ESTAN EN http://www.youtube.com/user/rvnrodrigo
import javax.swing.*;
import java.util.*;
import java.awt.event.*;
import java.applet.Applet;
import java.awt.*;
public class L1 extends JApplet
{
JLabel e1;
public void init()
{
Container c=getContentPane();
c.setLayout(new FlowLayout());
e1=new JLabel("ESTA ES MI PRIMER ETIQUETA");
c.add(e1);
}
}
import javax.swing.*;
import java.util.*;
import java.awt.event.*;
import java.applet.Applet;
import java.awt.*;
public class L1 extends JApplet
{
JLabel e1;
public void init()
{
Container c=getContentPane();
c.setLayout(new FlowLayout());
e1=new JLabel("ESTA ES MI PRIMER ETIQUETA");
c.add(e1);
}
}
LOS VIDEOS ESTAN EN http://www.youtube.com/user/rvnrodrigo
import javax.swing.*;
import java.util.*;
public class PEDIR
{
public static void main(String args[])
{
double a,b,c,r;
a=pj();
b=pj();
c=pj();
r=raiz(a,b,c);
imp("LA RAIZ ES: "+r);
imj("LA RAIZ ES: "+r);
}
public static void imp(String x)
{
System.out.print(x);
}
public static void imj(String x)
{
JOptionPane.showMessageDialog(null, x);
}
public static double p()
{
double x;
Scanner m=new Scanner(System.in);
imp("DAME UN NUMERO: ");
x=m.nextDouble();
return x;
}
public static double pj()
{
double x;
x=Double.parseDouble(JOptionPane.showInputDialog("DAME UN VALOR: "));
return x;
}
public static double raiz(double a,double b,double c )
{
return Math.sqrt(a+b+c);
}
}//clase
import javax.swing.*;
import java.util.*;
public class PEDIR
{
public static void main(String args[])
{
double a,b,c,r;
a=pj();
b=pj();
c=pj();
r=raiz(a,b,c);
imp("LA RAIZ ES: "+r);
imj("LA RAIZ ES: "+r);
}
public static void imp(String x)
{
System.out.print(x);
}
public static void imj(String x)
{
JOptionPane.showMessageDialog(null, x);
}
public static double p()
{
double x;
Scanner m=new Scanner(System.in);
imp("DAME UN NUMERO: ");
x=m.nextDouble();
return x;
}
public static double pj()
{
double x;
x=Double.parseDouble(JOptionPane.showInputDialog("DAME UN VALOR: "));
return x;
}
public static double raiz(double a,double b,double c )
{
return Math.sqrt(a+b+c);
}
}//clase
LOS VIDEOS ESTAN EN http://www.youtube.com/user/rvnrodrigo
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
double x,y,z,re;
x=Double.parseDouble(a.getText());
y=Double.parseDouble(b.getText());
z=Double.parseDouble(c.getText());
re=x+y+z;
r.setText(String.valueOf(re));
}
double x,y,z,re;
x=Double.parseDouble(a.getText());
y=Double.parseDouble(b.getText());
z=Double.parseDouble(c.getText());
re=x+y+z;
r.setText(String.valueOf(re));
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
a.setText("");
b.setText("");
c.setText("");
r.setText("");
}
// TODO add your handling code here:
a.setText("");
b.setText("");
c.setText("");
r.setText("");
}
LOS VIDEOS ESTAN EN http://www.youtube.com/user/rvnrodrigo
import javax.swing.*;
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class SUMA extends JApplet implements ActionListener
{
JTextField t1,t2,t3;
JLabel l1,l2,l3;
JButton b1;
public void init()
{
Container c=getContentPane();
c.setLayout(new FlowLayout());
l1=new JLabel("DAME EL PRIMER VALOR: ");
t1=new JTextField(20);
l2=new JLabel("DAME EL SEGUNDO VALOR: ");
t2=new JTextField(20);
l3=new JLabel("EL RESULTADO ES: ");
t3=new JTextField(20);
b1=new JButton("SUMAR");
c.add(t1);
c.add(t2);
c.add(t3);
c.add(b1);
b1.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)
{
double a,b,r;
a=Double.parseDouble(t1.getText());
b=Double.parseDouble(t2.getText());
r=a+b;
t3.setText(String.valueOf(r));
}
}
}
import javax.swing.*;
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class SUMA extends JApplet implements ActionListener
{
JTextField t1,t2,t3;
JLabel l1,l2,l3;
JButton b1;
public void init()
{
Container c=getContentPane();
c.setLayout(new FlowLayout());
l1=new JLabel("DAME EL PRIMER VALOR: ");
t1=new JTextField(20);
l2=new JLabel("DAME EL SEGUNDO VALOR: ");
t2=new JTextField(20);
l3=new JLabel("EL RESULTADO ES: ");
t3=new JTextField(20);
b1=new JButton("SUMAR");
c.add(t1);
c.add(t2);
c.add(t3);
c.add(b1);
b1.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)
{
double a,b,r;
a=Double.parseDouble(t1.getText());
b=Double.parseDouble(t2.getText());
r=a+b;
t3.setText(String.valueOf(r));
}
}
}
LOS VIDEOS ESTAN EN http://www.youtube.com/user/rvnrodrigo
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.applet.Applet;
public class PEDIR_TEXTO extends JApplet implements ActionListener
{
JTextField t1;
JLabel l1;
JButton b1;
public void init()
{
Container c=getContentPane();
c.setLayout(new FlowLayout());
l1=new JLabel("BIENVENIDOS A UN PROGRAMA CON UN BOTON: ");
t1=new JTextField(30);
b1=new JButton("SALUDO");
b1.addActionListener(this);
c.add(l1);
c.add(t1);
c.add(b1);
}//init
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)
{
t1.setText("RODRIGO VILLANUEVA NIETO");
}
}
}//PRINCIPAL
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.applet.Applet;
public class PEDIR_TEXTO extends JApplet implements ActionListener
{
JTextField t1;
JLabel l1;
JButton b1;
public void init()
{
Container c=getContentPane();
c.setLayout(new FlowLayout());
l1=new JLabel("BIENVENIDOS A UN PROGRAMA CON UN BOTON: ");
t1=new JTextField(30);
b1=new JButton("SALUDO");
b1.addActionListener(this);
c.add(l1);
c.add(t1);
c.add(b1);
}//init
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)
{
t1.setText("RODRIGO VILLANUEVA NIETO");
}
}
}//PRINCIPAL
LOS VIDEOS ESTAN EN http://www.youtube.com/user/rvnrodrigo
import javax.swing.*;
public class PEDIR3
{
public static void main(String args[])
{
desarrollo c1=new desarrollo();
c1.menu();
}
}
class desarrollo
{
public static void imp(String x)
{
JOptionPane.showMessageDialog(null,x);
}
public static double pd()
{
double x;
x=Double.parseDouble(JOptionPane.showInputDialog("DAME UN NUMERO: "));
return x;
}
public static double suma(double a,double b)
{
return a+b;
}
public static double resta(double a,double b)
{
return a-b;
}
public static double multi(double a,double b)
{
return a*b;
}
public static double divi(double a,double b)
{
return a/b;
}
public static double raiz(double a,double b)
{
return Math.sqrt(a+b);
}
public static double coseno(double a,double b)
{
return Math.cos(a+b);
}
public static double seno(double a,double b)
{
return Math.sin(a+b);
}
public static double tangente(double a,double b)
{
return Math.tan(a+b);
}
public static void menu()
{
int opc;
double a,b,r;
do
{
opc=Integer.parseInt(JOptionPane.showInputDialog("SELECCIONA UNA OPCION \n1.-SUMA\n2.-RESTA\n3.-MULTI\n4.-DIVI\n5RAIZ\n6.-COSENO7.-SENO\n8.-TANGETNTE\n9.-SALIR"));
switch(opc)
{
case 1:
a=pd();
b=pd();
r=suma(a,b);
imp("LA SUMA ES: "+r);
break;
case 2:
a=pd();
b=pd();
r=resta(a,b);
imp("LA RESTA ES: "+r);
break;
case 3:
a=pd();
b=pd();
r=multi(a,b);
imp("LA MULTIPLICACION ES: "+r);
break;
}//switch
}while(opc!=9);
}//desarrollo
import javax.swing.*;
public class PEDIR3
{
public static void main(String args[])
{
desarrollo c1=new desarrollo();
c1.menu();
}
}
class desarrollo
{
public static void imp(String x)
{
JOptionPane.showMessageDialog(null,x);
}
public static double pd()
{
double x;
x=Double.parseDouble(JOptionPane.showInputDialog("DAME UN NUMERO: "));
return x;
}
public static double suma(double a,double b)
{
return a+b;
}
public static double resta(double a,double b)
{
return a-b;
}
public static double multi(double a,double b)
{
return a*b;
}
public static double divi(double a,double b)
{
return a/b;
}
public static double raiz(double a,double b)
{
return Math.sqrt(a+b);
}
public static double coseno(double a,double b)
{
return Math.cos(a+b);
}
public static double seno(double a,double b)
{
return Math.sin(a+b);
}
public static double tangente(double a,double b)
{
return Math.tan(a+b);
}
public static void menu()
{
int opc;
double a,b,r;
do
{
opc=Integer.parseInt(JOptionPane.showInputDialog("SELECCIONA UNA OPCION \n1.-SUMA\n2.-RESTA\n3.-MULTI\n4.-DIVI\n5RAIZ\n6.-COSENO7.-SENO\n8.-TANGETNTE\n9.-SALIR"));
switch(opc)
{
case 1:
a=pd();
b=pd();
r=suma(a,b);
imp("LA SUMA ES: "+r);
break;
case 2:
a=pd();
b=pd();
r=resta(a,b);
imp("LA RESTA ES: "+r);
break;
case 3:
a=pd();
b=pd();
r=multi(a,b);
imp("LA MULTIPLICACION ES: "+r);
break;
}//switch
}while(opc!=9);
}//desarrollo
LOS VIDEOS ESTAN EN http://www.youtube.com/user/rvnrodrigo
import javax.swing.*;
import java.util.*;
public class FUNCION
{
public static void main(String args[])
{
double a,b,c,r;
a=p();
b=p();
c=p();
r=a+b+c;
imp("LA SUMA ES: "+r);
}
public static void imp(String x)
{
System.out.print(x);
}
public static double p()
{
Scanner m=new Scanner(System.in);
double x;
imp("DAME UN VALOR: ");
x=m.nextDouble();
return x;
}
}
import javax.swing.*;
import java.util.*;
public class FUNCION
{
public static void main(String args[])
{
double a,b,c,r;
a=p();
b=p();
c=p();
r=a+b+c;
imp("LA SUMA ES: "+r);
}
public static void imp(String x)
{
System.out.print(x);
}
public static double p()
{
Scanner m=new Scanner(System.in);
double x;
imp("DAME UN VALOR: ");
x=m.nextDouble();
return x;
}
}
LOS VIDEOS ESTAN EN http://www.youtube.com/user/rvnrodrigo
import javax.swing.*;
public class pedir_caja
{
public static void main(String args[])
{
double a,b,r;
a=p();
b=p();
r=a+b;
imp("LA SUMA ES: "+r);
}
public static double p()
{
double x;
x=Double.parseDouble(JOptionPane.showInputDialog("DAME UN NUMERO: "));
return x;
}
public static void imp(String x)
{
JOptionPane.showMessageDialog(null,x);
}
}
import javax.swing.*;
public class pedir_caja
{
public static void main(String args[])
{
double a,b,r;
a=p();
b=p();
r=a+b;
imp("LA SUMA ES: "+r);
}
public static double p()
{
double x;
x=Double.parseDouble(JOptionPane.showInputDialog("DAME UN NUMERO: "));
return x;
}
public static void imp(String x)
{
JOptionPane.showMessageDialog(null,x);
}
}
LOS VIDEOS ESTAN EN http://www.youtube.com/user/rvnrodrigo
import javax.swing.*;
public class IMPRIMIR
{
public static void main(String args[])
{
imp("ING RODRIGO VILLANUEVA NIETO");
jm("ING RODRIGO VILLANUEVA NIETO");
}
public static void imp(String x)
{
System.out.print(x);
}
public static void jm(String x)
{
JOptionPane.showMessageDialog(null, x);
}
}
import javax.swing.*;
public class IMPRIMIR
{
public static void main(String args[])
{
imp("ING RODRIGO VILLANUEVA NIETO");
jm("ING RODRIGO VILLANUEVA NIETO");
}
public static void imp(String x)
{
System.out.print(x);
}
public static void jm(String x)
{
JOptionPane.showMessageDialog(null, x);
}
}
LOS VIDEOS ESTAN EN http://www.youtube.com/user/rvnrodrigo
import javax.swing.*;
import java.util.*;
public class SUMA
{
public static void main(String args[])
{
double a,b,c,re,com;
Scanner p=new Scanner(System.in);
imp("DAME A: ");
a=p.nextDouble();
imp("DAME B: ");
b=p.nextDouble();
imp("DAME C: ");
c=p.nextDouble();
re=suma(a,b);
com=raiz(a,b,c)-suma(a,b);
imp("LA SUMA ES: "+re);
imp("RESULTADO ES: "+com);
}
public static double raiz(double a,double b,double c)
{
return Math.sqrt((a+b)/c);
}
public static double suma(double a, double b)
{
double r;
r=(a+b)/2;
return r;
}
public static void imp(String x)
{
System.out.print(x);
}
}
import javax.swing.*;
import java.util.*;
public class SUMA
{
public static void main(String args[])
{
double a,b,c,re,com;
Scanner p=new Scanner(System.in);
imp("DAME A: ");
a=p.nextDouble();
imp("DAME B: ");
b=p.nextDouble();
imp("DAME C: ");
c=p.nextDouble();
re=suma(a,b);
com=raiz(a,b,c)-suma(a,b);
imp("LA SUMA ES: "+re);
imp("RESULTADO ES: "+com);
}
public static double raiz(double a,double b,double c)
{
return Math.sqrt((a+b)/c);
}
public static double suma(double a, double b)
{
double r;
r=(a+b)/2;
return r;
}
public static void imp(String x)
{
System.out.print(x);
}
}
LOS VIDEOS ESTAN EN http://www.youtube.com/user/rvnrodrigo
import javax.swing.*;
import java.io.*;
public class pedir_uno
{
public static void main(String args[]) throws Exception
{
BufferedReader p=new BufferedReader(new InputStreamReader(System.in));
double a,b,r;
System.out.print("DAME A: ");
a=Double.parseDouble(p.readLine());
System.out.print("DAME B: ");
b=Double.parseDouble(p.readLine());
r=a+b;
System.out.print("LA SUMA ES: "+r);
}
}
import javax.swing.*;
import java.io.*;
public class pedir_uno
{
public static void main(String args[]) throws Exception
{
BufferedReader p=new BufferedReader(new InputStreamReader(System.in));
double a,b,r;
System.out.print("DAME A: ");
a=Double.parseDouble(p.readLine());
System.out.print("DAME B: ");
b=Double.parseDouble(p.readLine());
r=a+b;
System.out.print("LA SUMA ES: "+r);
}
}
LOS VIDEOS ESTAN EN http://www.youtube.com/user/rvnrodrigo
import javax.swing.*;
import java.awt.*;
public class basica
{
public static void main(String args[])
{
cal p1=new cal();//cree el objeto p1
p1.menu();
datos_personales c1=new datos_personales();
c1.datos();
c1.area_triangulo();
}
}
class cal
{
double a,b,s,r,m,d;
int opc;
public void menu()
{
opc=Integer.parseInt(JOptionPane.showInputDialog("1.-suma\n2.-resta\n3.-multi\n4.-divi"));
if(opc==1)
{
a=Double.parseDouble(JOptionPane.showInputDialog("DAME A: "));
b=Double.parseDouble(JOptionPane.showInputDialog("DAME B: "));
s=a+b;
JOptionPane.showMessageDialog(null, "LA SUMA ES: "+s);
}
if(opc==2)
{
resta();
}
if(opc==3)
{
multi();
}
if(opc==4)
{
divi();
}
if(opc<1 || opc>4)
{
JOptionPane.showMessageDialog(null,"QUE PARTE ENTENDISTE DEL 1 AL 4");
}
}
public void suma()
{
a=Double.parseDouble(JOptionPane.showInputDialog("DAME A: "));
b=Double.parseDouble(JOptionPane.showInputDialog("DAME B: "));
s=a+b;
JOptionPane.showMessageDialog(null, "LA SUMA ES: "+s);
}
public void resta()
{
a=Double.parseDouble(JOptionPane.showInputDialog("DAME A: "));
b=Double.parseDouble(JOptionPane.showInputDialog("DAME B: "));
r=a-b;
JOptionPane.showMessageDialog(null, "LA RESTA ES: "+r);
}
public void multi()
{
a=Double.parseDouble(JOptionPane.showInputDialog("DAME A: "));
b=Double.parseDouble(JOptionPane.showInputDialog("DAME B: "));
m=a*b;
JOptionPane.showMessageDialog(null, "LA MULTIPLICACION: "+m);
}
public void divi()
{
a=Double.parseDouble(JOptionPane.showInputDialog("DAME A: "));
b=Double.parseDouble(JOptionPane.showInputDialog("DAME B: "));
d=a/b;
JOptionPane.showMessageDialog(null, "LA DIVISION ES: "+d);
}
public void raiz()
{
a=Double.parseDouble(JOptionPane.showInputDialog("DAME A: "));
b=Double.parseDouble(JOptionPane.showInputDialog("DAME B: "));
s=Math.sqrt(a+b)-Math.sqrt(a*a)+Math.tan(a*b);
JOptionPane.showMessageDialog(null, "LA RAIZ ES: "+s);
}
public void todo()
{
suma();
resta();
multi();
divi();
raiz();
}
}
import javax.swing.*;
import java.awt.*;
public class basica
{
public static void main(String args[])
{
cal p1=new cal();//cree el objeto p1
p1.menu();
datos_personales c1=new datos_personales();
c1.datos();
c1.area_triangulo();
}
}
class cal
{
double a,b,s,r,m,d;
int opc;
public void menu()
{
opc=Integer.parseInt(JOptionPane.showInputDialog("1.-suma\n2.-resta\n3.-multi\n4.-divi"));
if(opc==1)
{
a=Double.parseDouble(JOptionPane.showInputDialog("DAME A: "));
b=Double.parseDouble(JOptionPane.showInputDialog("DAME B: "));
s=a+b;
JOptionPane.showMessageDialog(null, "LA SUMA ES: "+s);
}
if(opc==2)
{
resta();
}
if(opc==3)
{
multi();
}
if(opc==4)
{
divi();
}
if(opc<1 || opc>4)
{
JOptionPane.showMessageDialog(null,"QUE PARTE ENTENDISTE DEL 1 AL 4");
}
}
public void suma()
{
a=Double.parseDouble(JOptionPane.showInputDialog("DAME A: "));
b=Double.parseDouble(JOptionPane.showInputDialog("DAME B: "));
s=a+b;
JOptionPane.showMessageDialog(null, "LA SUMA ES: "+s);
}
public void resta()
{
a=Double.parseDouble(JOptionPane.showInputDialog("DAME A: "));
b=Double.parseDouble(JOptionPane.showInputDialog("DAME B: "));
r=a-b;
JOptionPane.showMessageDialog(null, "LA RESTA ES: "+r);
}
public void multi()
{
a=Double.parseDouble(JOptionPane.showInputDialog("DAME A: "));
b=Double.parseDouble(JOptionPane.showInputDialog("DAME B: "));
m=a*b;
JOptionPane.showMessageDialog(null, "LA MULTIPLICACION: "+m);
}
public void divi()
{
a=Double.parseDouble(JOptionPane.showInputDialog("DAME A: "));
b=Double.parseDouble(JOptionPane.showInputDialog("DAME B: "));
d=a/b;
JOptionPane.showMessageDialog(null, "LA DIVISION ES: "+d);
}
public void raiz()
{
a=Double.parseDouble(JOptionPane.showInputDialog("DAME A: "));
b=Double.parseDouble(JOptionPane.showInputDialog("DAME B: "));
s=Math.sqrt(a+b)-Math.sqrt(a*a)+Math.tan(a*b);
JOptionPane.showMessageDialog(null, "LA RAIZ ES: "+s);
}
public void todo()
{
suma();
resta();
multi();
divi();
raiz();
}
}
LOS VIDEOS ESTAN EN http://www.youtube.com/user/rvnrodrigo
import javax.swing.*;
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class PRUEBA extends JApplet implements ActionListener
{
JTextField t1,t2;
JButton b1,b2;
public void init()
{
Container c=getContentPane();
c.setLayout(new FlowLayout());
t1=new JTextField(20);
t2=new JTextField(20);
b1=new JButton("NOMBRE");
b2=new JButton("DIRECCION");
b1.addActionListener(this);
b2.addActionListener(this);
c.add(t1);
c.add(t2);
c.add(b1);
c.add(b2);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)
{
t1.setText("RODRIGO VILLANUEVA");
}
if(e.getSource()==b2)
{
t2.setText("ARAGON");
}
}
}
import javax.swing.*;
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class PRUEBA extends JApplet implements ActionListener
{
JTextField t1,t2;
JButton b1,b2;
public void init()
{
Container c=getContentPane();
c.setLayout(new FlowLayout());
t1=new JTextField(20);
t2=new JTextField(20);
b1=new JButton("NOMBRE");
b2=new JButton("DIRECCION");
b1.addActionListener(this);
b2.addActionListener(this);
c.add(t1);
c.add(t2);
c.add(b1);
c.add(b2);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)
{
t1.setText("RODRIGO VILLANUEVA");
}
if(e.getSource()==b2)
{
t2.setText("ARAGON");
}
}
}
LOS VIDEOS ESTAN EN http://www.youtube.com/user/rvnrodrigo
import javax.swing.*;
public class EJEMPLO1
{
public static void main(String args[])
{
funciones p1=new funciones();
p1.pro1();
p1.pro2();
}
}
class funciones
{
double a,b,r;
public void pro1()
{
a=Double.parseDouble(JOptionPane.showInputDialog("dame a: "));
b=Double.parseDouble(JOptionPane.showInputDialog("dame b: "));
if(a>b)
{
r=a+b;
JOptionPane.showMessageDialog(null,"EL RESULTADO ES: "+r);
System.out.print("RESULTADO: "+r);
}//parte verdadera.
else
{
r=a-b;
JOptionPane.showMessageDialog(null,"EL RESULTADO ES: "+r);
System.out.print("RESULTADO: "+r);
}
}//funcion pro1
public void pro2()
{
a=Double.parseDouble(JOptionPane.showInputDialog("dame a: "));
b=Double.parseDouble(JOptionPane.showInputDialog("dame b: "));
if(a+b>=50)
{
r=Math.sqrt((a*a)+(b*b)/5);
JOptionPane.showMessageDialog(null,"resultado es: "+r);
System.out.print("resultado es: "+r);
}//if
else
{
r=Math.cos((a*a)+(b*b));
JOptionPane.showMessageDialog(null,"resultado es: "+r);
System.out.print("resultado es: "+r);
}
}//funcion 2
}//clase funciones
import javax.swing.*;
public class EJEMPLO1
{
public static void main(String args[])
{
funciones p1=new funciones();
p1.pro1();
p1.pro2();
}
}
class funciones
{
double a,b,r;
public void pro1()
{
a=Double.parseDouble(JOptionPane.showInputDialog("dame a: "));
b=Double.parseDouble(JOptionPane.showInputDialog("dame b: "));
if(a>b)
{
r=a+b;
JOptionPane.showMessageDialog(null,"EL RESULTADO ES: "+r);
System.out.print("RESULTADO: "+r);
}//parte verdadera.
else
{
r=a-b;
JOptionPane.showMessageDialog(null,"EL RESULTADO ES: "+r);
System.out.print("RESULTADO: "+r);
}
}//funcion pro1
public void pro2()
{
a=Double.parseDouble(JOptionPane.showInputDialog("dame a: "));
b=Double.parseDouble(JOptionPane.showInputDialog("dame b: "));
if(a+b>=50)
{
r=Math.sqrt((a*a)+(b*b)/5);
JOptionPane.showMessageDialog(null,"resultado es: "+r);
System.out.print("resultado es: "+r);
}//if
else
{
r=Math.cos((a*a)+(b*b));
JOptionPane.showMessageDialog(null,"resultado es: "+r);
System.out.print("resultado es: "+r);
}
}//funcion 2
}//clase funciones
NUEVO EJEMPLO
import javax.swing.*;
import java.awt.event.*;
import java.applet.Applet;
import java.awt.*;
public class panel1 extends JApplet
{
public void init()
{
Container c=getContentPane();
JPanel panel=new JPanel();
panel.setLayout(new GridLayout(11,16));
for(int a=1;a<=10;a++)
{
for(int b=1;b<=15;b++)
{
panel.add(new JTextField("cuadro de texto"+ a+" "+b));
}
}
JScrollPane scrol=new JScrollPane(panel,ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
c.add(scrol);
}
}
import javax.swing.*;
import java.awt.event.*;
import java.applet.Applet;
import java.awt.*;
public class panel1 extends JApplet
{
public void init()
{
Container c=getContentPane();
JPanel panel=new JPanel();
panel.setLayout(new GridLayout(11,16));
for(int a=1;a<=10;a++)
{
for(int b=1;b<=15;b++)
{
panel.add(new JTextField("cuadro de texto"+ a+" "+b));
}
}
JScrollPane scrol=new JScrollPane(panel,ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
c.add(scrol);
}
}
NUEVO EJEMPLO
import javax.swing.*;
public class SALUDO1
{
public static void main(String args[])
{
System.out.print("RODRIGO VILLANUEVA NIETO");
JOptionPane.showMessageDialog(null,"RODRIGO \n VILLANUEVA \n NIETO");
JOptionPane.showMessageDialog(null,"ESTE ES EL SEGUNDO MENSAJE");
}
}
VIDEO
import javax.swing.*;
public class SALUDO1
{
public static void main(String args[])
{
System.out.print("RODRIGO VILLANUEVA NIETO");
JOptionPane.showMessageDialog(null,"RODRIGO \n VILLANUEVA \n NIETO");
JOptionPane.showMessageDialog(null,"ESTE ES EL SEGUNDO MENSAJE");
}
}
VIDEO
NUEVO EJEMPLO
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class CALCULADORA2 extends JApplet implements ActionListener
{
JTextField t1,t2,t3;
JButton suma,resta,multi,divi;
public void init()
{
Container c=getContentPane();
c.setLayout(new FlowLayout());
t1=new JTextField(30);
t2=new JTextField(30);
t3=new JTextField(30);
suma=new JButton("SUMAR");
resta=new JButton("RESTA");
multi=new JButton("MULTIPLICAR");
divi=new JButton("DIVIDIR");
suma.addActionListener(this);
resta.addActionListener(this);
multi.addActionListener(this);
divi.addActionListener(this);
c.add(t1);
c.add(t2);
c.add(t3);
c.add(suma);
c.add(resta);
c.add(multi);
c.add(divi);
}//metodo init
public void actionPerformed(ActionEvent e)
{
double a,b,s,r,m,d;
if(e.getSource()==suma)
{
a=Double.parseDouble(t1.getText());
b=Double.parseDouble(t2.getText());
s=a+b;
t3.setText(String.valueOf(s));
}
if(e.getSource()==resta)
{
a=Double.parseDouble(t1.getText());
b=Double.parseDouble(t2.getText());
r=a-b;
t3.setText(String.valueOf(r));
}
if(e.getSource()==multi)
{
a=Double.parseDouble(t1.getText());
b=Double.parseDouble(t2.getText());
m=a*b;
t3.setText(String.valueOf(m));
}
if(e.getSource()==divi)
{
a=Double.parseDouble(t1.getText());
b=Double.parseDouble(t2.getText());
d=a/b;
t3.setText(String.valueOf(d));
}
}
}
EL VIDEO ESTA EN http://www.youtube.com/user/rvnrodrigo
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class CALCULADORA2 extends JApplet implements ActionListener
{
JTextField t1,t2,t3;
JButton suma,resta,multi,divi;
public void init()
{
Container c=getContentPane();
c.setLayout(new FlowLayout());
t1=new JTextField(30);
t2=new JTextField(30);
t3=new JTextField(30);
suma=new JButton("SUMAR");
resta=new JButton("RESTA");
multi=new JButton("MULTIPLICAR");
divi=new JButton("DIVIDIR");
suma.addActionListener(this);
resta.addActionListener(this);
multi.addActionListener(this);
divi.addActionListener(this);
c.add(t1);
c.add(t2);
c.add(t3);
c.add(suma);
c.add(resta);
c.add(multi);
c.add(divi);
}//metodo init
public void actionPerformed(ActionEvent e)
{
double a,b,s,r,m,d;
if(e.getSource()==suma)
{
a=Double.parseDouble(t1.getText());
b=Double.parseDouble(t2.getText());
s=a+b;
t3.setText(String.valueOf(s));
}
if(e.getSource()==resta)
{
a=Double.parseDouble(t1.getText());
b=Double.parseDouble(t2.getText());
r=a-b;
t3.setText(String.valueOf(r));
}
if(e.getSource()==multi)
{
a=Double.parseDouble(t1.getText());
b=Double.parseDouble(t2.getText());
m=a*b;
t3.setText(String.valueOf(m));
}
if(e.getSource()==divi)
{
a=Double.parseDouble(t1.getText());
b=Double.parseDouble(t2.getText());
d=a/b;
t3.setText(String.valueOf(d));
}
}
}
EL VIDEO ESTA EN http://www.youtube.com/user/rvnrodrigo
NUEVO EJEMPLO
import javax.swing.*;
public class DATOS_PERSONALES
{
public static void main(String args[])
{
desarrollo_datos rodrigo=new desarrollo_datos();
rodrigo.nombre();
rodrigo.direccion();
}
}
class desarrollo_datos
{
String nom,ap,am,dir,tel,curp;//variables globales
public void nombre()
{
nom=JOptionPane.showInputDialog("DAME TU NOMBRE: ");
ap=JOptionPane.showInputDialog("DAME TU APELLIDO PATERNO: ");
am=JOptionPane.showInputDialog("DAME TU APELLIDO MATERNO: ");
JOptionPane.showMessageDialog(null, "TU NOMBRE ES: "+nom);
JOptionPane.showMessageDialog(null, "TU APELLIDO PATERNO ES: : "+ap);
JOptionPane.showMessageDialog(null, "TU APELLIDO MATERNO ES:: "+am);
System.out.print("TU NOMBRE ES: "+nom+"\n");
System.out.print("TU APELLIDO PATERNO ES: "+ap+"\n");
System.out.print("TU APELLIDO MATERNO ES: "+am+"\n");
}
public void direccion()
{
dir=JOptionPane.showInputDialog("DAME TU DIRECCION: ");
tel=JOptionPane.showInputDialog("DAME TU TELEFONO ");
curp=JOptionPane.showInputDialog("DAME TU CURP: ");
JOptionPane.showMessageDialog(null, "TU DIRECCION ES: "+dir);
JOptionPane.showMessageDialog(null, "TU TELEFONO ES: : "+tel);
JOptionPane.showMessageDialog(null, "TU CURP ES:: "+curp);
System.out.print("TU DIRECCION ES: "+dir+"\n");
System.out.print("TU TELEFONO ES: "+tel+"\n");
System.out.print("TU CURP ES: "+curp+"\n");
}
}//clase desarrollo
import javax.swing.*;
public class DATOS_PERSONALES
{
public static void main(String args[])
{
desarrollo_datos rodrigo=new desarrollo_datos();
rodrigo.nombre();
rodrigo.direccion();
}
}
class desarrollo_datos
{
String nom,ap,am,dir,tel,curp;//variables globales
public void nombre()
{
nom=JOptionPane.showInputDialog("DAME TU NOMBRE: ");
ap=JOptionPane.showInputDialog("DAME TU APELLIDO PATERNO: ");
am=JOptionPane.showInputDialog("DAME TU APELLIDO MATERNO: ");
JOptionPane.showMessageDialog(null, "TU NOMBRE ES: "+nom);
JOptionPane.showMessageDialog(null, "TU APELLIDO PATERNO ES: : "+ap);
JOptionPane.showMessageDialog(null, "TU APELLIDO MATERNO ES:: "+am);
System.out.print("TU NOMBRE ES: "+nom+"\n");
System.out.print("TU APELLIDO PATERNO ES: "+ap+"\n");
System.out.print("TU APELLIDO MATERNO ES: "+am+"\n");
}
public void direccion()
{
dir=JOptionPane.showInputDialog("DAME TU DIRECCION: ");
tel=JOptionPane.showInputDialog("DAME TU TELEFONO ");
curp=JOptionPane.showInputDialog("DAME TU CURP: ");
JOptionPane.showMessageDialog(null, "TU DIRECCION ES: "+dir);
JOptionPane.showMessageDialog(null, "TU TELEFONO ES: : "+tel);
JOptionPane.showMessageDialog(null, "TU CURP ES:: "+curp);
System.out.print("TU DIRECCION ES: "+dir+"\n");
System.out.print("TU TELEFONO ES: "+tel+"\n");
System.out.print("TU CURP ES: "+curp+"\n");
}
}//clase desarrollo
NUEVO EJEMPLO
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class BOTON1 extends JApplet
{
JTextField t1;
JButton b1;
public void init()
{
Container c=getContentPane();
c.setLayout(new FlowLayout());
t1=new JTextField(30);
b1=new JButton("PRESIONA AQUI");
c.add(t1);
c.add(b1);
b1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
t1.setText("BIENVENIDOS A JAVA ");
}
});
}//init
}//clase
LOS VIDEOS ESTAN EN http://www.youtube.com/user/rvnrodrigo
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class BOTON1 extends JApplet
{
JTextField t1;
JButton b1;
public void init()
{
Container c=getContentPane();
c.setLayout(new FlowLayout());
t1=new JTextField(30);
b1=new JButton("PRESIONA AQUI");
c.add(t1);
c.add(b1);
b1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
t1.setText("BIENVENIDOS A JAVA ");
}
});
}//init
}//clase
LOS VIDEOS ESTAN EN http://www.youtube.com/user/rvnrodrigo
NUEVO EJEMPLO
import javax.swing.*;
import java.awt.*;
public class calcular
{
public static void main(String args[])
{
double a,b,s,r,m,d;//variables de tipo doble para decimales
a=Double.parseDouble(JOptionPane.showInputDialog("DAME A: "));
//EL Double.parseDouble convierte a numero el texto
b=Double.parseDouble(JOptionPane.showInputDialog("DAME B: "));
s=a+b;
r=a-b;
m=a*b;
d=a/b;
//imprimimos resultados
JOptionPane.showMessageDialog(null,"LA SUMA ES: "+s);
JOptionPane.showMessageDialog(null,"LA RESTA ES: "+r);
JOptionPane.showMessageDialog(null,"LA MULTIPLICACION ES: "+m);
JOptionPane.showMessageDialog(null,"LA DIVISIÓN ES: "+d);
// O EN CONSOLA ES LO MISMO
System.out.print("LA SUMA ES: "+s);
//listo terminamos
//otra manera de correrlo
}
}
RECUERDA MUCHOS VIDEO ESTAN EN MI SITIO.
http://www.youtube.com/user/rvnrodrigo
import javax.swing.*;
import java.awt.*;
public class calcular
{
public static void main(String args[])
{
double a,b,s,r,m,d;//variables de tipo doble para decimales
a=Double.parseDouble(JOptionPane.showInputDialog("DAME A: "));
//EL Double.parseDouble convierte a numero el texto
b=Double.parseDouble(JOptionPane.showInputDialog("DAME B: "));
s=a+b;
r=a-b;
m=a*b;
d=a/b;
//imprimimos resultados
JOptionPane.showMessageDialog(null,"LA SUMA ES: "+s);
JOptionPane.showMessageDialog(null,"LA RESTA ES: "+r);
JOptionPane.showMessageDialog(null,"LA MULTIPLICACION ES: "+m);
JOptionPane.showMessageDialog(null,"LA DIVISIÓN ES: "+d);
// O EN CONSOLA ES LO MISMO
System.out.print("LA SUMA ES: "+s);
//listo terminamos
//otra manera de correrlo
}
}
RECUERDA MUCHOS VIDEO ESTAN EN MI SITIO.
http://www.youtube.com/user/rvnrodrigo
NUEVO EJEMPLO
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class cuadro1 extends JApplet
{
JTextField t1;
public void init()
{
Container c= getContentPane();
c.setLayout(new FlowLayout());
t1=new JTextField(25);
t1.setText("BIENVENIDOS A JAVA");
c.add(t1);
}
}
VER VIDEO
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class cuadro1 extends JApplet
{
JTextField t1;
public void init()
{
Container c= getContentPane();
c.setLayout(new FlowLayout());
t1=new JTextField(25);
t1.setText("BIENVENIDOS A JAVA");
c.add(t1);
}
}
VER VIDEO
NUEVO EJEMPLO
import javax.swing.*;
import java.awt.*;
public class ETIQUETAS1 extends JApplet
{
public ETIQUETAS1()
{
Container c=getContentPane();
c.setLayout(new FlowLayout());
JLabel e1=new JLabel("HOLA DESDE SWING");
c.add(e1);
}
}
VER VIDEO http://www.youtube.com/watch?v=V_0UbW7qLgM
import javax.swing.*;
import java.awt.*;
public class ETIQUETAS1 extends JApplet
{
public ETIQUETAS1()
{
Container c=getContentPane();
c.setLayout(new FlowLayout());
JLabel e1=new JLabel("HOLA DESDE SWING");
c.add(e1);
}
}
VER VIDEO http://www.youtube.com/watch?v=V_0UbW7qLgM
Suscribirse a:
Entradas (Atom)