import
import
import
import
import
java.awt.Color;
java.awt.Container;
java.awt.Font;
java.awt.event.ActionEvent;
java.awt.event.ActionListener;
import
import
import
import
javax.swing.JButton;
javax.swing.JFrame;
javax.swing.JLabel;
javax.swing.JTextField;
public class OperIGU extends JFrame implements ActionListener{
JTextField c1, c2, c3;
JButton b1,b2,b3,b4,b5;
public OperIGU(){
inicio();
}
public void inicio(){
Container conten = getContentPane();
setBounds(0, 0,450, 200);
setLayout(null);
setLocationRelativeTo(null);
setTitle("OPERACIONES IGU");
JLabel e1 = new JLabel("1er numero: ");
e1.setBounds(10, 10, 100, 20);
e1.setFont(new Font("Arial", 1, 14));
conten.add(e1);
JLabel e2 = new JLabel("2er numero: ");
e2.setBounds(10, 40, 100, 20);
e2.setFont(new Font("Arial", 1, 14));
conten.add(e2);
JLabel e3 = new JLabel("Resultado: ");
e3.setBounds(10, 120, 100, 20);
e3.setFont(new Font("Arial", 1, 14));
conten.add(e3);
c1 = new JTextField();
c1.setBounds(120, 10,100, 20);
c1.setFont(new Font("Arial",1 , 14));
c1.setHorizontalAlignment(JTextField.RIGHT);
conten.add(c1);
c2 = new JTextField();
c2.setBounds(120, 40,100, 20);
c2.setFont(new Font("Arial",1 , 14));
c2.setHorizontalAlignment(JTextField.RIGHT);
conten.add(c2);
c3 = new JTextField();
c3.setBounds(120, 120,150, 20);
c3.setFont(new Font("Arial",1 , 14));
c3.setHorizontalAlignment(JTextField.RIGHT);
c3.setBackground(Color.WHITE);
c3.setEditable(false);
conten.add(c3);
b1 = new JButton("+");
b1.setBounds(10, 80, 50, 20);
b1.setFont(new Font("Arial", 1, 14));
conten.add(b1);
b1.addActionListener(this);
b2 = new JButton("-");
b2.setBounds(100, 80, 50, 20);
b2.setFont(new Font("Arial", 1,
conten.add(b2);
b2.addActionListener(this);
b3 = new JButton("*");
b3.setBounds(190, 80, 50, 20);
b3.setFont(new Font("Arial", 1,
conten.add(b3);
b3.addActionListener(this);
b4 = new JButton("/");
b4.setBounds(280, 80, 50, 20);
b4.setFont(new Font("Arial", 1,
conten.add(b4);
b4.addActionListener(this);
b5 = new JButton("Clear");
b5.setBounds(250, 25, 80, 30);
b5.setFont(new Font("Arial", 1,
conten.add(b5);
b5.addActionListener(this);
14));
14));
14));
14));
}
public static void main(String[] args) {
OperIGU vent = new OperIGU();
vent.setVisible(true);
vent.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e) {
Object fuente = e.getSource();
if(fuente == b1){
double num1 = Double.parseDouble(c1.getText());
double num2 = Double.parseDouble(c2.getText());
c3.setText(""+(num1 + num2));
}
if(fuente == b2){
double num1 = Double.parseDouble(c1.getText());
double num2 = Double.parseDouble(c2.getText());
c3.setText(""+(num1 - num2));
}
if(fuente == b3){
double num1 = Double.parseDouble(c1.getText());
double num2 = Double.parseDouble(c2.getText());
c3.setText(""+(num1 * num2));
}
if(fuente == b4){
double num1 = Double.parseDouble(c1.getText());
double num2 = Double.parseDouble(c2.getText());
c3.setText(""+(num1 / num2));
}
if(fuente == b5){
c1.setText(null);
c2.setText(null);
c3.setText(null);
}
}