Advertisement
gtw7375

New calculadora - Swing

Sep 15th, 2014
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.59 KB | None | 0 0
  1.    
  2.  
  3.     import javax.swing.*;
  4.  
  5. import java.awt.*;
  6. import java.awt.event.*;
  7.      
  8.     public class MultiplicaSenhor extends JFrame implements ActionListener{
  9.        
  10.         JButton limpar = new JButton("Limpar");
  11.         JButton calcular = new JButton("Calcular");
  12.         JButton soma = new JButton("+");
  13.         JButton subt = new JButton("-");
  14.         JButton mult = new JButton("*");
  15.         JButton divi = new JButton("/");
  16.        
  17.         JTextField login = new JTextField();
  18.         JTextField senha = new JTextField();
  19.         JTextField resul = new JTextField();
  20.        
  21.        
  22.            
  23.         public MultiplicaSenhor() {
  24.            
  25.             setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  26.             setSize(500,400);                                              
  27.             setTitle("Ela que me diz..");                                           // PROPRIEDADES DA JANELA
  28.             setResizable(false);
  29.             getContentPane().setLayout(null);
  30.            
  31.            
  32.            
  33.            
  34.            soma.setBounds(70, 195, 50, 20);
  35.            getContentPane().add(soma);
  36.            soma.addActionListener(new Soma());
  37.            
  38.            subt.setBounds(130, 195, 50, 20);
  39.            getContentPane().add(subt);
  40.           // subt.addActionListener(new Sub());
  41.                                                                                     //OPERADORES
  42.            mult.setBounds(190, 195, 50, 20);
  43.            getContentPane().add(mult);
  44.            mult.addActionListener(this);
  45.            
  46.            divi.setBounds(250, 195, 50, 20);
  47.            getContentPane().add(divi);
  48.            divi.addActionListener(this);
  49.            
  50.            
  51.            
  52.            
  53.            
  54.            login.setBounds(120, 145, 140, 20);
  55.            getContentPane().add(login);                                    
  56.            
  57.            senha.setBounds(120, 170, 140, 20);
  58.            getContentPane().add(senha);                                             //CAIXAS DE TEXTO
  59.            
  60.            resul.setBounds(120, 220, 140, 20);
  61.            getContentPane().add(resul);
  62.            
  63.                
  64.            
  65.            
  66.            calcular.setBounds(135, 320, 100, 20);
  67.            getContentPane().add(calcular);
  68.            calcular.addActionListener(new Somou());
  69.            calcular.setEnabled(false);
  70.                                                                                     //BOTÕES
  71.            limpar.setBounds(135, 350, 100, 20);
  72.            getContentPane().add(limpar);
  73.            limpar.addActionListener(this);
  74.            
  75.         }
  76.        
  77.        
  78.         public static void main(String[] args) {
  79.        
  80.              MultiplicaSenhor janela = new MultiplicaSenhor();
  81.             janela.setVisible(true);
  82.             janela.show();
  83.            
  84.         }
  85.        
  86.         //public void actionPerformed(ActionEvent acao) {
  87.         //soma() {
  88.        
  89.        
  90.         class Soma implements ActionListener{
  91.            
  92.                    
  93.                 public void actionPerformed(ActionEvent ev) {
  94.                      
  95.                     calcular.setEnabled(true);
  96.                 }
  97.         }
  98.                         class Somou implements ActionListener {
  99.                            
  100.                             public void actionPerformed(ActionEvent ac) {
  101.                        
  102.                            
  103.                                
  104.                                  double num1 = Double.parseDouble(login.getText());
  105.                                   double num2 = Double.parseDouble(senha.getText());  
  106.                                   double result = num1 + num2;
  107.                                   resul.setText(""+result);
  108.                                 }          
  109.                             }
  110.                    
  111.                      
  112.                        
  113.                      
  114.                  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement