Sei sulla pagina 1di 3

package operacionesss;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import java.awt.Color;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;

public class operacionesssssss extends JFrame {

private JPanel contentPane;


private JTextField N1;
private JTextField N2;
private JTextField Res;

/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
operacionesssssss frame = new
operacionesssssss();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}

/**
* Create the frame.
*/
public operacionesssssss() {
setTitle("Operaciones");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBackground(Color.LIGHT_GRAY);
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);

JLabel lblPrimerNmero = new JLabel("Primer N\u00FAmero: ");


lblPrimerNmero.setFont(new Font("Tahoma", Font.PLAIN, 16));
lblPrimerNmero.setBounds(32, 32, 120, 14);
contentPane.add(lblPrimerNmero);

JLabel lblSegundoNmero = new JLabel("Segundo N\u00FAmero: ");


lblSegundoNmero.setFont(new Font("Tahoma", Font.PLAIN, 16));
lblSegundoNmero.setBounds(32, 59, 135, 14);
contentPane.add(lblSegundoNmero);

JLabel lblResultado = new JLabel("Resultado: ");


lblResultado.setFont(new Font("Tahoma", Font.PLAIN, 16));
lblResultado.setBounds(32, 128, 80, 14);
contentPane.add(lblResultado);

N1 = new JTextField();
N1.setHorizontalAlignment(SwingConstants.RIGHT);
N1.setFont(new Font("Tahoma", Font.PLAIN, 16));
N1.setBounds(183, 31, 86, 20);
contentPane.add(N1);
N1.setColumns(10);

N2 = new JTextField();
N2.setHorizontalAlignment(SwingConstants.RIGHT);
N2.setFont(new Font("Tahoma", Font.PLAIN, 16));
N2.setBounds(183, 56, 86, 20);
contentPane.add(N2);
N2.setColumns(10);

Res = new JTextField();


Res.setBackground(Color.WHITE);
Res.setEditable(false);
Res.setFont(new Font("Tahoma", Font.PLAIN, 16));
Res.setHorizontalAlignment(SwingConstants.RIGHT);
Res.setBounds(183, 125, 86, 20);
contentPane.add(Res);
Res.setColumns(10);

JButton button = new JButton("+");


button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
double num1= Double.parseDouble(N1.getText());
double num2= Double.parseDouble(N2.getText());
Res.setText(""+(num1+num2));

}
});
button.setBounds(32, 84, 41, 23);
contentPane.add(button);

JComboBox Oper = new JComboBox();


Oper.setFont(new Font("Tahoma", Font.PLAIN, 16));
Oper.setModel(new DefaultComboBoxModel(new String[] {"",
"Suma", "Resta", "Multiplicaci\u00F3n", "Divisi\u00F3n"}));
Oper.setBounds(103, 84, 135, 20);
contentPane.add(Oper);

JButton btnCalcular = new JButton("Calcular");


btnCalcular.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
double num1 = Double.parseDouble(N1.getText());
double num2 = Double.parseDouble(N2.getText());
if(Oper.getSelectedItem()=="Suma")
Res.setText(""+(num1+num2));
if(Oper.getSelectedItem()=="Resta")
Res.setText(""+(num1-num2));
if(Oper.getSelectedItem()=="Multiplicacin")
Res.setText(""+(num1*num2));
if(Oper.getSelectedItem()=="Divisin")
Res.setText(""+(num1/num2));

}
});
btnCalcular.setFont(new Font("Tahoma", Font.PLAIN, 16));
btnCalcular.setBounds(258, 82, 89, 23);
contentPane.add(btnCalcular);

JButton btnNuevoCalculo = new JButton("Nuevo Calculo");


btnNuevoCalculo.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
N1.setText("");
N2.setText("");
Res.setText("");
}
});
btnNuevoCalculo.setFont(new Font("Tahoma", Font.PLAIN, 16));
btnNuevoCalculo.setBounds(23, 173, 144, 23);
contentPane.add(btnNuevoCalculo);

JButton btnSalir = new JButton("Salir");


btnSalir.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
btnSalir.setFont(new Font("Tahoma", Font.PLAIN, 16));
btnSalir.setBounds(177, 173, 89, 23);
contentPane.add(btnSalir);
}
}

Potrebbero piacerti anche