Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package clase1004;
- 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 javax.swing.JOptionPane;
- import java.awt.Font;
- import java.awt.Color;
- import javax.swing.JTextField;
- import java.awt.event.MouseAdapter;
- import java.awt.event.MouseEvent;
- import javax.swing.JButton;
- import javax.swing.border.BevelBorder;
- import javax.swing.border.LineBorder;
- import javax.swing.ImageIcon;
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- public class calcuxx extends JFrame {
- private JPanel contentPane;
- private JTextField txtIngresePrimercalcuxxndo;
- private JTextField txtIngreseSegundocalcuxxndo;
- private JLabel lblResultado;
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- calcuxx frame = new calcuxx();
- frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * Create the frame.
- */
- public calcuxx() {
- setResizable(false);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setBounds(100, 100, 868, 544);
- contentPane = new JPanel();
- contentPane.setBackground(new Color(169, 169, 169));
- contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
- setContentPane(contentPane);
- contentPane.setLayout(null);
- JLabel lblBienvenidoALa = new JLabel("Bienvenido a la calculadora");
- lblBienvenidoALa.setForeground(new Color(75, 0, 130));
- lblBienvenidoALa.setFont(new Font("Viner Hand ITC", Font.PLAIN, 25));
- lblBienvenidoALa.setBounds(252, 32,7924, 89);
- contentPane.add(lblBienvenidoALa);
- txtIngresePrimercalcuxxndo = new JTextField();
- txtIngresePrimercalcuxxndo.setBorder(new LineBorder(new Color(255, 0, 255), 4));
- txtIngresePrimercalcuxxndo.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent arg0) {
- txtIngresePrimercalcuxxndo.setText("");
- }
- });
- txtIngresePrimercalcuxxndo.setText("Ingrese primer termino");
- txtIngresePrimercalcuxxndo.setBounds(58, 158, 228, 35);
- contentPane.add(txtIngresePrimercalcuxxndo);
- txtIngresePrimercalcuxxndo.setColumns(10);
- txtIngreseSegundocalcuxxndo = new JTextField();
- txtIngreseSegundocalcuxxndo.setBorder(new LineBorder(new Color(255, 0, 255), 4));
- txtIngreseSegundocalcuxxndo.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent e) {
- txtIngreseSegundocalcuxxndo.setText("");
- }
- });
- txtIngreseSegundocalcuxxndo.setText("Ingrese segundo termino");
- txtIngreseSegundocalcuxxndo.setColumns(10);
- txtIngreseSegundocalcuxxndo.setBounds(58, 221, 228, 35);
- contentPane.add(txtIngreseSegundocalcuxxndo);
- lblResultado = new JLabel("");
- lblResultado.setFont(new Font("Nyala", Font.PLAIN, 23));
- lblResultado.setBounds(564, 197, 322, 78);
- contentPane.add(lblResultado);
- JButton botonsuma = new JButton("SUMAR");
- botonsuma.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- try {
- lblResultado.setText(String.valueOf(Integer.parseInt(txtIngresePrimercalcuxxndo.getText())+Integer.parseInt(txtIngreseSegundocalcuxxndo.getText())));
- } catch (java.lang.NumberFormatException coscu) {
- // TODO: handle exception
- if(txtIngresePrimercalcuxxndo.getText().isEmpty()) {
- JOptionPane.showMessageDialog(null, "error tabacio el 1");
- txtIngresePrimercalcuxxndo.requestFocus();
- }else if(txtIngreseSegundocalcuxxndo.getText().isEmpty()) {
- JOptionPane.showMessageDialog(null, "error tabacio el 2");
- txtIngreseSegundocalcuxxndo.requestFocus();
- }else {
- if(!txtIngresePrimercalcuxxndo.getText().matches("[0-9]+")) {
- JOptionPane.showMessageDialog(null, "caracteres invalidos en el 1");
- txtIngresePrimercalcuxxndo.requestFocus();
- txtIngresePrimercalcuxxndo.setText("");
- }
- else if(!txtIngreseSegundocalcuxxndo.getText().matches("[0-9]+")) {
- JOptionPane.showMessageDialog(null, "caracteres invalidos en el 2");
- txtIngreseSegundocalcuxxndo.setText("");
- txtIngreseSegundocalcuxxndo.requestFocus();
- }
- }
- }
- }
- });
- botonsuma.setIcon(new ImageIcon("C:\\Users\\aVA\\Desktop\\Captura.PNG"));
- botonsuma.setBounds(543, 113, 80, 35);
- contentPane.add(botonsuma);
- JButton botondivision = new JButton("DIVIDIR");
- botondivision.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- try {
- lblResultado.setText(String.valueOf(Integer.parseInt(txtIngresePrimercalcuxxndo.getText())/Integer.parseInt(txtIngreseSegundocalcuxxndo.getText())));
- } catch (java.lang.NumberFormatException coscu) {
- // TODO: handle exception
- if(txtIngresePrimercalcuxxndo.getText().isEmpty()) {
- JOptionPane.showMessageDialog(null, "error tabacio el 1");
- txtIngresePrimercalcuxxndo.requestFocus();
- }else if(txtIngreseSegundocalcuxxndo.getText().isEmpty()) {
- JOptionPane.showMessageDialog(null, "error tabacio el 2");
- txtIngreseSegundocalcuxxndo.requestFocus();
- }else {
- if(!txtIngresePrimercalcuxxndo.getText().matches("[0-9]+")) {
- JOptionPane.showMessageDialog(null, "caracteres invalidos en el 1");
- txtIngresePrimercalcuxxndo.requestFocus();
- txtIngresePrimercalcuxxndo.setText("");
- }
- else if(!txtIngreseSegundocalcuxxndo.getText().matches("[0-9]+")) {
- JOptionPane.showMessageDialog(null, "caracteres invalidos en el 2");
- txtIngreseSegundocalcuxxndo.setText("");
- txtIngreseSegundocalcuxxndo.requestFocus();
- }
- }
- }
- }
- });
- botondivision.setBounds(543, 158, 80, 35);
- contentPane.add(botondivision);
- JButton botonresta = new JButton("RESTAR");
- botonresta.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- ////
- try {
- lblResultado.setText(String.valueOf(Integer.parseInt(txtIngresePrimercalcuxxndo.getText())-Integer.parseInt(txtIngreseSegundocalcuxxndo.getText())));
- } catch (java.lang.NumberFormatException coscu) {
- // TODO: handle exception
- if(txtIngresePrimercalcuxxndo.getText().isEmpty()) {
- JOptionPane.showMessageDialog(null, "error tabacio el 1");
- txtIngresePrimercalcuxxndo.requestFocus();
- }else if(txtIngreseSegundocalcuxxndo.getText().isEmpty()) {
- JOptionPane.showMessageDialog(null, "error tabacio el 2");
- txtIngreseSegundocalcuxxndo.requestFocus();
- }else {
- if(!txtIngresePrimercalcuxxndo.getText().matches("[0-9]+")) {
- JOptionPane.showMessageDialog(null, "caracteres invalidos en el 1");
- txtIngresePrimercalcuxxndo.requestFocus();
- txtIngresePrimercalcuxxndo.setText("");
- }
- else if(!txtIngreseSegundocalcuxxndo.getText().matches("[0-9]+")) {
- JOptionPane.showMessageDialog(null, "caracteres invalidos en el 2");
- txtIngreseSegundocalcuxxndo.setText("");
- txtIngreseSegundocalcuxxndo.requestFocus();
- }
- }
- }
- }
- });
- botonresta.setBounds(453, 113, 80, 35);
- contentPane.add(botonresta);
- JButton botonmult = new JButton("MULTIPLICAR");
- botonmult.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- try {
- lblResultado.setText(String.valueOf(Integer.parseInt(txtIngresePrimercalcuxxndo.getText())*Integer.parseInt(txtIngreseSegundocalcuxxndo.getText())));
- } catch (java.lang.NumberFormatException coscu) {
- // TODO: handle exception
- if(txtIngresePrimercalcuxxndo.getText().isEmpty()) {
- JOptionPane.showMessageDialog(null, "error tabacio el 1");
- txtIngresePrimercalcuxxndo.requestFocus();
- }else if(txtIngreseSegundocalcuxxndo.getText().isEmpty()) {
- JOptionPane.showMessageDialog(null, "error tabacio el 2");
- txtIngreseSegundocalcuxxndo.requestFocus();
- }else {
- if(!txtIngresePrimercalcuxxndo.getText().matches("[0-9]+")) {
- JOptionPane.showMessageDialog(null, "caracteres invalidos en el 1");
- txtIngresePrimercalcuxxndo.requestFocus();
- txtIngresePrimercalcuxxndo.setText("");
- }
- else if(!txtIngreseSegundocalcuxxndo.getText().matches("[0-9]+")) {
- JOptionPane.showMessageDialog(null, "caracteres invalidos en el 2");
- txtIngreseSegundocalcuxxndo.setText("");
- txtIngreseSegundocalcuxxndo.requestFocus();
- }
- }
- }
- }
- });
- botonmult.setBounds(453, 158, 80, 35);
- contentPane.add(botonmult);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement