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);
}
}
Suscribirse a:
Entradas (Atom)