ClubEnsayos.com - Ensayos de Calidad, Tareas y Monografias
Buscar

Biografias


Enviado por   •  19 de Noviembre de 2012  •  1.835 Palabras (8 Páginas)  •  324 Visitas

Página 1 de 8

Ejercicios:

1. Crear un programa para realizar la suma de dos números. (JFSumar)

package l14a_medina;

public class JFSumar extends javax.swing.JFrame {

public JFSumar() {

initComponents();

Generated Code

private void SumarActionPerformed(java.awt.event.ActionEvent evt) {

Double num1,num2,resp;

num1 = Double.parseDouble(Texto1.getText());

num2 = Double.parseDouble(Texto2.getText());

resp = num1 + num2;

Rpta.setText("" + resp);

}

private void Texto2ActionPerformed(java.awt.event.ActionEvent evt) {

}

private void Texto1ActionPerformed(java.awt.event.ActionEvent evt) {

}

private void RptaActionPerformed(java.awt.event.ActionEvent evt) {

}

public static void main(String args[]) {

Look and feel setting code (optional)

java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {

new JFSumar().setVisible(true);

}

});

}

private javax.swing.JLabel Dato1;

private javax.swing.JLabel Dato2;

private javax.swing.JLabel Respuesta;

private javax.swing.JTextField Rpta;

private javax.swing.JButton Sumar;

private javax.swing.JTextField Texto1;

private javax.swing.JTextField Texto2;

2. Escribir un programa para crear una calculadora, con las operaciones básicas. (JFCalculadora)

• Modificar el programa para asegurar que el programa funcione, no divida entre cero ni ingrese datos de tipo String, para ello usar try…catch.

• Utilizar Radio Button.

package l14a_medina;

import java.util.InputMismatchException;

import java.util.Scanner;

public class JFCalculadora extends javax.swing.JFrame {

public JFCalculadora() {

initComponents();

}

Generated Code

private void Dato2ActionPerformed(java.awt.event.ActionEvent evt) {

}

private void SumarActionPerformed(java.awt.event.ActionEvent evt) {

Double num1,num2,resp;

num1 = Double.parseDouble(Dato1.getText());

num2 = Double.parseDouble(Dato2.getText());

resp = num1 + num2;

Respuesta.setText("" + resp);

}

private void RestarActionPerformed(java.awt.event.ActionEvent evt) {

Double num1,num2,resp;

num1 = Double.parseDouble(Dato1.getText());

num2 = Double.parseDouble(Dato2.getText());

resp = num1 - num2;

Respuesta.setText("" + resp);

}

private void MultiplicarActionPerformed(java.awt.event.ActionEvent evt) {

Double num1,num2,resp;

num1 = Double.parseDouble(Dato1.getText());

num2 = Double.parseDouble(Dato2.getText());

resp = num1*num2;

Respuesta.setText("" + resp);

}

private void DividirActionPerformed(java.awt.event.ActionEvent evt) {

Double num1,num2,resp;

boolean continuarCiclo = true;

Scanner sc = new Scanner (System.in);

do{

try{

...

Descargar como (para miembros actualizados)  txt (6.9 Kb)  
Leer 7 páginas más »
Disponible sólo en Clubensayos.com