TrabalhosGratuitos.com - Trabalhos, Monografias, Artigos, Exames, Resumos de livros, Dissertações
Pesquisar

Caulculadora Java

Por:   •  30/11/2015  •  Trabalho acadêmico  •  4.240 Palavras (17 Páginas)  •  141 Visualizações

Página 1 de 17

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import java.util.*;

import java.lang.Math;

class Trabalho extends JFrame implements ActionListener, TextListener{

JLabel L1,L2,L3;

JButton B1,B2, B3, B4, B5, B6, B7,B8,B9,B10,B11,B12;

JTextField T1,T2,T3;

Trabalho(){

setTitle("Calculadora");

setSize(600,200);

setLocation(50,50);

getContentPane().setBackground(new Color(150,150,150));

getContentPane().setLayout(new GridLayout(3,6));

L1 = new JLabel("Num.1");

L1.setForeground(Color.black);

L1.setFont(new Font("",Font.BOLD,14));

L2 = new JLabel("Num.2");

L2.setForeground(Color.black);

L2.setFont(new Font("",Font.BOLD,14));

L3 = new JLabel("Total");

L3.setFont(new Font("",Font.BOLD,14));

B1= new JButton ("+"); B1.addActionListener(this);

B2= new JButton ("-"); B2.addActionListener(this);

B3= new JButton ("x"); B3.addActionListener(this);

B4= new JButton ("/"); B4.addActionListener(this);

B5= new JButton ("Limpar"); B5.addActionListener(this);

B6= new JButton ("√²"); B6.addActionListener(this);

B7= new JButton ("x²"); B7.addActionListener(this);

B8= new JButton ("√³"); B8.addActionListener(this);

B9= new JButton ("x³"); B9.addActionListener(this);

B10= new JButton ("sen"); B10.addActionListener(this);

B11= new JButton ("cos"); B11.addActionListener(this);

B12= new JButton ("tg"); B12.addActionListener(this);

B5.setBackground(Color.black);

B5.setForeground(Color.white);

T1 = new JTextField();

T2 = new JTextField();

T3 = new JTextField();

T3.setEditable(false);

getContentPane().add(L1);

getContentPane().add(T1);

getContentPane().add(B1);

getContentPane().add(B2);

getContentPane().add(B6);

getContentPane().add(B10);

getContentPane().add(L2);

getContentPane().add(T2);

getContentPane().add(B3);

getContentPane().add(B4);

getContentPane().add(B7);

getContentPane().add(B11);

getContentPane().add(L3);

getContentPane().add(T3);

getContentPane().add(B5);

getContentPane().add(B8);

getContentPane().add(B9);

getContentPane().add(B12);

B1.setEnabled(false);

B2.setEnabled(false);

B3.setEnabled(false);

B4.setEnabled(false);

B5.setEnabled(false);

B6.setEnabled(false);

B7.setEnabled(false);

B8.setEnabled(false);

B9.setEnabled(false);

B10.setEnabled(false);

B11.setEnabled(false);

B12.setEnabled(false);

T1.addFocusListener(new java.awt.event.FocusAdapter() {

public void focusLost(java.awt.event.FocusEvent e) {

if (T1.getText().trim().equals("") ) {

B1.setEnabled(false);

B2.setEnabled(false);

B3.setEnabled(false);

B4.setEnabled(false);

B5.setEnabled(false);

B6.setEnabled(false);

B7.setEnabled(false);

B8.setEnabled(false);

...

Baixar como (para membros premium)  txt (9.8 Kb)   pdf (51.7 Kb)   docx (15 Kb)  
Continuar por mais 16 páginas »
Disponível apenas no TrabalhosGratuitos.com