Notes![what is notes.io? What is notes.io?](/theme/images/whatisnotesio.png)
![]() ![]() Notes - notes.io |
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import java.text.Numberformat;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.Locale;
public class calculadora extends JFrame implements KeyListener{
//variaveis de objetos como botoes, caixa texto, etc...
private JButton botao1, botao2, botao3, botao4, botao5, botao6, botao7, botao8, botao9, botao0, botaoC, botaoCE, botaoDiv, botaoMultip, botaoMenos, botaoMais, botaoVirgula, botaoTotal, botaoPerc, botaoBackspace;
private JTextArea roloPapel;
private jLabel visor, KeyCodigo;
private JScrollPane scroll;
private double soma = 0;
private String valor = "", operador = "", valorAnterior = "";
//variaveis de inicialização do GridBagLayout
private Container container;
private GridBagLayout layout;
private GridBagConstraints constraints;
private JRadioButton botao2dig, botao4dig, botao6dig;
private ButtonGroup botaoDecimais;
private int casasDecimais = 2;
//classe de tratamento e eventos de ação ==========================
private class trataEventosAcao implements ActionListener {
public void actionPerformed ( ActionEvent event){
if (event.getSource()==botaoC) teclouC();
else if (event.getSource()==botaoCE) teclouCE();
else if (event.getSource()==botaoPerc) teclouP();
else if (event.getSource()==botaoVirgula) teclouVirgula();
else if (event.getSource()==botaoBackspace) teclouBackspace();
else if (event.getSource()==botao1) teclouNumeros("1");
else if (event.getSource()==botao2) teclouNumeros("2");
else if (event.getSource()==botao3) teclouNumeros("3");
else if (event.getSource()==botao4) teclouNumeros("4");
else if (event.getSource()==botao5) teclouNumeros("5");
else if (event.getSource()==botao6) teclouNumeros("6");
else if (event.getSource()==botao7) teclouNumeros("7");
else if (event.getSource()==botao8) teclouNumeros("8");
else if (event.getSource()==botao9) teclouNumeros("9");
else if (event.getSource()==botao0) teclouNumeros("0");
else if (event.getSource()==botaoMais) teclouMais();
else if (event.getSource()==botaoMenos) teclouMenos();
else if (event.getSource()==botaoDiv) teclouDiv();
else if (event.getSource()==botaoMultip) teclouMultip();
else if (event.getSource()==botaoTotal) teclouEnter();
//classe de tratamento de eventos Focus(nenhum componente vai recebe o focu alem do visor,
//mas deixo o codigo abaixo para efeito didatico
private class trataEventosFocus implements FocusListener{
//==quando os campos texto ganham focus
public void focusGained(FocusEvent event)
{//==========
}
//==quando os campos texto perdem o focus
public void focusLost(FocusEvent event)
{//========
}
}
//classe de tratamento de eventos Focus (nenhum componente vai recebe o focu alem do visor,
//mas deixo o codigo abaixo pra efeito didatico
private class trataEventosRadio implements itemListener{
//==quando os campos texto ganham focus
public void itemStateChanged(ItemEvent events){
if(event.getSource()==botao2dig){
//Mudou pra dois digitos decimais
casasDecimais = 2;
}
if(event.get.Source()== botao4dig){
//Mudou pra quatro digitos decimais
casasdecimais = 4;
}
if (event.getSource()== botao6dig){
//Mudou pra seis digitos decimais
casasDecimais = 6;
}
}
}
}
}
}
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team