Sie sind auf Seite 1von 14

package vista;

import matematica.Racional;

public class FraccionesJFrame extends javax.swing.JFrame {

public FraccionesJFrame() {

initComponents();

@SuppressWarnings("unchecked")

// <editor-fold defaultstate="collapsed" desc="Generated Code">

private void initComponents() {

jButton7 = new javax.swing.JButton();

jPanel1 = new javax.swing.JPanel();

jLabel1 = new javax.swing.JLabel();

jTextField1 = new javax.swing.JTextField();

jLabel2 = new javax.swing.JLabel();

jTextField2 = new javax.swing.JTextField();

jLabel3 = new javax.swing.JLabel();

jTextField3 = new javax.swing.JTextField();

jLabel4 = new javax.swing.JLabel();

jTextField4 = new javax.swing.JTextField();

jLabel5 = new javax.swing.JLabel();

jTextField5 = new javax.swing.JTextField();

jLabel6 = new javax.swing.JLabel();

jTextField6 = new javax.swing.JTextField();

jButton1 = new javax.swing.JButton();

jButton2 = new javax.swing.JButton();

jButton3 = new javax.swing.JButton();

jButton4 = new javax.swing.JButton();


jButton5 = new javax.swing.JButton();

jButton6 = new javax.swing.JButton();

jButton8 = new javax.swing.JButton();

jButton7.setText("Simplificar 2do");

jButton7.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

jButton7ActionPerformed(evt);

});

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jLabel1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

jLabel1.setText("Primer Racional");

jTextField1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

jLabel2.setText("____________");

jTextField2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

jLabel3.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

jLabel3.setText("Segundo Racional");

jTextField3.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

jLabel4.setText("____________");

jTextField4.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

jLabel5.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

jLabel5.setText("Respuesta");
jTextField5.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

jTextField5.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

jTextField5ActionPerformed(evt);

});

jLabel6.setText("____________");

jTextField6.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

jButton1.setText("Sumar");

jButton1.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

jButton1ActionPerformed(evt);

});

jButton2.setText("Multiplicar");

jButton2.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

jButton2ActionPerformed(evt);

});

jButton3.setText("Restar");

jButton3.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {


jButton3ActionPerformed(evt);

});

jButton4.setText("Dividir");

jButton4.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

jButton4ActionPerformed(evt);

});

jButton5.setText("Simplificar 1ro");

jButton5.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

jButton5ActionPerformed(evt);

});

jButton6.setText("Simplificar 2do");

jButton6.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

jButton6ActionPerformed(evt);

});

jButton8.setText("Limpiar");

jButton8.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

jButton8ActionPerformed(evt);

});
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);

jPanel1.setLayout(jPanel1Layout);

jPanel1Layout.setHorizontalGroup(

jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(jPanel1Layout.createSequentialGroup()

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(jPanel1Layout.createSequentialGroup()

.addGap(112, 112, 112)

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(jPanel1Layout.createSequentialGroup()

.addComponent(jLabel6)

.addGap(92, 92, 92)

.addComponent(jButton6, javax.swing.GroupLayout.DEFAULT_SIZE, 114,


Short.MAX_VALUE))

.addGroup(jPanel1Layout.createSequentialGroup()

.addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, 70,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addGap(94, 94, 94)

.addComponent(jButton5, javax.swing.GroupLayout.DEFAULT_SIZE, 114,


Short.MAX_VALUE))

.addGroup(jPanel1Layout.createSequentialGroup()

.addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, 70,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addGap(94, 94, 94)

.addComponent(jButton8, javax.swing.GroupLayout.DEFAULT_SIZE, 114,


Short.MAX_VALUE))

.addGroup(jPanel1Layout.createSequentialGroup()

.addComponent(jLabel5)

.addGap(101, 101, 101)


.addComponent(jButton4, javax.swing.GroupLayout.DEFAULT_SIZE, 114,
Short.MAX_VALUE))))

.addGroup(jPanel1Layout.createSequentialGroup()

.addGap(44, 44, 44)

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(jLabel1)

.addGroup(jPanel1Layout.createSequentialGroup()

.addGap(10, 10, 10)

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(jLabel2)

.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 70,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 70,


javax.swing.GroupLayout.PREFERRED_SIZE))))

.addGap(27, 27, 27)

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(jLabel3)

.addGroup(jPanel1Layout.createSequentialGroup()

.addGap(10, 10, 10)

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(jPanel1Layout.createSequentialGroup()

.addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 70,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addGap(31, 31, 31)

.addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))

.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)

.addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 70,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(jLabel4))

.addGap(30, 30, 30)

.addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))))))

.addContainerGap())

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(jPanel1Layout.createSequentialGroup()

.addGap(274, 274, 274)

.addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, 116, Short.MAX_VALUE)

.addContainerGap()))

);

jPanel1Layout.setVerticalGroup(

jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(jPanel1Layout.createSequentialGroup()

.addContainerGap()

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)

.addGroup(jPanel1Layout.createSequentialGroup()

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(jPanel1Layout.createSequentialGroup()

.addComponent(jLabel3)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton1))

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(jLabel4)

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(jPanel1Layout.createSequentialGroup()

.addGap(29, 29, 29)

.addComponent(jButton2))

.addGroup(jPanel1Layout.createSequentialGroup()

.addGap(18, 18, 18)

.addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))

.addGroup(jPanel1Layout.createSequentialGroup()

.addComponent(jLabel1)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)

.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(jLabel2)

.addGap(18, 18, 18)

.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))

.addGap(23, 23, 23)

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(jLabel5)

.addComponent(jButton4))

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)

.addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jButton5))

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(jLabel6)

.addComponent(jButton6))

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(jPanel1Layout.createSequentialGroup()

.addGap(18, 18, 18)

.addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))

.addGroup(jPanel1Layout.createSequentialGroup()

.addGap(8, 8, 8)

.addComponent(jButton8)))

.addContainerGap(14, Short.MAX_VALUE))

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(jPanel1Layout.createSequentialGroup()

.addGap(80, 80, 80)

.addComponent(jButton3)

.addContainerGap(197, Short.MAX_VALUE)))

);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());

getContentPane().setLayout(layout);

layout.setHorizontalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

);

layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

);

pack();

}// </editor-fold>

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

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

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

String ent1,ent2,ent3,ent4,sal1,sal2;

int num1,den1,num2,den2,num3,den3;

ent1 = jTextField1.getText();

ent2 = jTextField2.getText();

ent3 = jTextField3.getText();

ent4 = jTextField4.getText();

num1 = Integer.parseInt(ent1);

den1 = Integer.parseInt(ent2);

num2 = Integer.parseInt(ent3);

den2 = Integer.parseInt(ent4);

Racional primero = new Racional(num1,den1);

Racional segundo = new Racional(num2,den2);

Racional resultado = primero.sumar(segundo);

sal1 = String.valueOf(resultado.getNumerador());

sal2 = String.valueOf(resultado.getDenominador());

jTextField5.setText(sal1);
jTextField6.setText(sal2);

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

// TODO add your handling code here:

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

// TODO add your handling code here:

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

// TODO add your handling code here:

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

// TODO add your handling code here:

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

// TODO add your handling code here:

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

// TODO add your handling code here:

/**

* @param args the command line arguments

*/
public static void main(String args[]) {

/* Set the Nimbus look and feel */

//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">

/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.

* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html

*/

try {

for (javax.swing.UIManager.LookAndFeelInfo info :


javax.swing.UIManager.getInstalledLookAndFeels()) {

if ("Nimbus".equals(info.getName())) {

javax.swing.UIManager.setLookAndFeel(info.getClassName());

break;

} catch (ClassNotFoundException ex) {

java.util.logging.Logger.getLogger(FraccionesJFrame.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);

} catch (InstantiationException ex) {

java.util.logging.Logger.getLogger(FraccionesJFrame.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);

} catch (IllegalAccessException ex) {

java.util.logging.Logger.getLogger(FraccionesJFrame.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);

} catch (javax.swing.UnsupportedLookAndFeelException ex) {

java.util.logging.Logger.getLogger(FraccionesJFrame.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);

}
//</editor-fold>

/* Create and display the form */

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

public void run() {

new FraccionesJFrame().setVisible(true);

});

// Variables declaration - do not modify

private javax.swing.JButton jButton1;

private javax.swing.JButton jButton2;

private javax.swing.JButton jButton3;

private javax.swing.JButton jButton4;

private javax.swing.JButton jButton5;

private javax.swing.JButton jButton6;

private javax.swing.JButton jButton7;

private javax.swing.JButton jButton8;

private javax.swing.JLabel jLabel1;

private javax.swing.JLabel jLabel2;

private javax.swing.JLabel jLabel3;

private javax.swing.JLabel jLabel4;

private javax.swing.JLabel jLabel5;

private javax.swing.JLabel jLabel6;

private javax.swing.JPanel jPanel1;

private javax.swing.JTextField jTextField1;

private javax.swing.JTextField jTextField2;

private javax.swing.JTextField jTextField3;


private javax.swing.JTextField jTextField4;

private javax.swing.JTextField jTextField5;

private javax.swing.JTextField jTextField6;

// End of variables declaration