0% found this document useful (0 votes)
43 views11 pages

Calculadora Y Barra de Menú - Java

Uploaded by

Arami González
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views11 pages

Calculadora Y Barra de Menú - Java

Uploaded by

Arami González
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Calculadora Y Barra De Menú

Ilustración 1jFrameForm repasocalculadora

Ilustración 2jFrameForm menu

/*

* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this


license

* Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this


template

*/
package repaso;

import javax.swing.JOptionPane;

/**

* @author NB

*/

public class repasocalculadora extends javax.swing.JFrame {

orden operar = new orden ();

/**

* Creates new form repasocalculadora

*/

public repasocalculadora() {

initComponents();

/**

* This method is called from within the constructor to initialize the form.

* WARNING: Do NOT modify this code. The content of this method is always

* regenerated by the Form Editor.

*/

@SuppressWarnings("unchecked")

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

private void initComponents() {

jCheckBoxMenuItem3 = new javax.swing.JCheckBoxMenuItem();

jLabel1 = new javax.swing.JLabel();

jLabel2 = new javax.swing.JLabel();

txtnum1 = new javax.swing.JTextField();


txtnum2 = new javax.swing.JTextField();

limpiar = new javax.swing.JButton();

suma = new javax.swing.JButton();

resta = new javax.swing.JButton();

divi = new javax.swing.JButton();

multi = new javax.swing.JButton();

Salir = new javax.swing.JButton();

jMenuBar1 = new javax.swing.JMenuBar();

jMenu1 = new javax.swing.JMenu();

jMenuItem1 = new javax.swing.JMenuItem();

jCheckBoxMenuItem3.setSelected(true);

jCheckBoxMenuItem3.setText("jCheckBoxMenuItem3");

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jLabel1.setText("Ingrese El primer Valor");

jLabel2.setText("Ingrese el segundo Valor");

txtnum1.setText(" ");

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

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

txtnum1ActionPerformed(evt);

});

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

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

txtnum2ActionPerformed(evt);

}
});

limpiar.setText("limpiar");

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

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

limpiarActionPerformed(evt);

});

suma.setText("+");

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

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

sumaActionPerformed(evt);

});

resta.setText("-");

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

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

restaActionPerformed(evt);

});

divi.setText("/");

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

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

diviActionPerformed(evt);

});

multi.setText("*");
multi.addActionListener(new java.awt.event.ActionListener() {

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

multiActionPerformed(evt);

});

Salir.setText("Salir");

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

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

SalirActionPerformed(evt);

});

jMenu1.setText("Menu");

jMenuItem1.setText("imagne");

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

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

jMenuItem1ActionPerformed(evt);

});

jMenu1.add(jMenuItem1);

jMenuBar1.add(jMenu1);

setJMenuBar(jMenuBar1);

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

getContentPane().setLayout(layout);

layout.setHorizontalGroup(

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

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

.addGroup(layout.createSequentialGroup()

.addGap(38, 38, 38)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADI
NG)

.addComponent(jLabel1)

.addComponent(jLabel2))

.addGap(69, 69, 69)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADI
NG, false)

.addComponent(txtnum1)

.addComponent(txtnum2)))

.addGroup(layout.createSequentialGroup()

.addGap(122, 122, 122)

.addComponent(limpiar)

.addGap(18, 18, 18)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADI
NG)

.addComponent(divi)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TR
AILING, false)

.addComponent(Salir, javax.swing.GroupLayout.Alignment.LEADING,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)

.addComponent(multi)

.addGroup(layout.createSequentialGroup()

.addComponent(suma)

.addGap(31, 31, 31)

.addComponent(resta))))))

.addContainerGap(66, Short.MAX_VALUE))

);

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

.addGroup(layout.createSequentialGroup()

.addGap(50, 50, 50)

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

.addComponent(jLabel1)

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

.addGap(26, 26, 26)

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

.addComponent(jLabel2)

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

.addGap(27, 27, 27)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,
false)

.addGroup(layout.createSequentialGroup()

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASE
LINE)

.addComponent(suma)

.addComponent(resta))

.addGap(18, 18, 18)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASE
LINE)

.addComponent(divi)

.addComponent(multi))

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

.addComponent(Salir))

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

.addContainerGap(37, Short.MAX_VALUE))

);

pack();
}// </editor-fold>

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

// TODO add your handling code here:

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

double num1 = Double.parseDouble(txtnum1.getText());

double num2 = Double.parseDouble(txtnum2.getText());

operar. suma (num1, num2);

JOptionPane.showMessageDialog(null, operar.result);

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

double num1 = Double.parseDouble(txtnum1.getText());

double num2 = Double.parseDouble(txtnum2.getText());

operar. resta (num1, num2);

JOptionPane.showMessageDialog(null, operar.result);

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

double num1 = Double.parseDouble(txtnum1.getText());

double num2 = Double.parseDouble(txtnum2.getText());

operar. divi(num1, num2);

JOptionPane.showMessageDialog(null, operar.result);

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

double num1 = Double.parseDouble(txtnum1.getText());

double num2 = Double.parseDouble(txtnum2.getText());

operar. multi(num1, num2);


JOptionPane.showMessageDialog(null, operar.result);

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

System.exit(0);

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

txtnum1.setText ("");

txtnum2.setText("");

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

ventanaa obj = new ventanaa ();

obj.setVisible (true);

dispose ();

private void txtnum1ActionPerformed(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(repasocalculadora.class.getName()).log(java.util.logging.Lev
el.SEVERE, null, ex);

} catch (InstantiationException ex) {

java.util.logging.Logger.getLogger(repasocalculadora.class.getName()).log(java.util.logging.Lev
el.SEVERE, null, ex);

} catch (IllegalAccessException ex) {

java.util.logging.Logger.getLogger(repasocalculadora.class.getName()).log(java.util.logging.Lev
el.SEVERE, null, ex);

} catch (javax.swing.UnsupportedLookAndFeelException ex) {

java.util.logging.Logger.getLogger(repasocalculadora.class.getName()).log(java.util.logging.Lev
el.SEVERE, null, ex);

//</editor-fold>

/* Create and display the form */

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

public void run() {

new repasocalculadora().setVisible(true);

});
}

// Variables declaration - do not modify

private javax.swing.JButton Salir;

private javax.swing.JButton divi;

private javax.swing.JCheckBoxMenuItem jCheckBoxMenuItem3;

private javax.swing.JLabel jLabel1;

private javax.swing.JLabel jLabel2;

private javax.swing.JMenu jMenu1;

private javax.swing.JMenuBar jMenuBar1;

private javax.swing.JMenuItem jMenuItem1;

private javax.swing.JButton limpiar;

private javax.swing.JButton multi;

private javax.swing.JButton resta;

private javax.swing.JButton suma;

private javax.swing.JTextField txtnum1;

private javax.swing.JTextField txtnum2;

// End of variables declaration

You might also like