Por favor me ajudem!

3 respostas
Calmont

Pessoal, boa tarde !!
Com esse codigo eu posso usar uma calculadora mais eu queria um comando para limpar e sair , como vocês poderiam me ajudar.

Muito obrigado !!!

import javax.swing.JFrame;

import javax.swing.JButton;

import javax.swing.JLabel;

import javax.swing.JTextField;

import java.awt.Dimension;

import java.awt.Point;

import java.awt.FlowLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

public class Calculadora extends JFrame
{

private JButton botao = null;

private JButton botao2 = null;

private JButton botao3 = null;

private JButton botao4 = null;

private JButton botao5 = null;

private JButton botao6 = null;

private JButton botao7 = null;
private JLabel rotulo1 = null;

private JLabel rotulo2 = null;

private JLabel rotulo3 = null;
private JTextField valor1 = null;

private JTextField valor2 = null;

private JTextField valor3 = null;

public Calculadora(){

this.setTitle("Calculadora");
this.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
this.setBounds(350,200,300,300);
this.setLayout(new FlowLayout());

this.rotulo1 = new JLabel("Primeiro Valor");
this.valor1 = new JTextField(30);
this.rotulo2 = new JLabel("Segundo Valor");
this.valor2 = new JTextField(30);
this.rotulo3 = new JLabel("Resultado final");
this.valor3 = new JTextField(30);

this.botao = new JButton("SOMAR");
this.botao2 = new JButton("SUBTRAIR");
this.botao3 = new JButton("MULTIPLICAR");
this.botao4 = new JButton("DIVIDIR ");
this.botao5 = new JButton("CALCULAR");
this.botao6 = new JButton("LIMPAR");
this.botao7 = new JButton("SAIR");
this.botao.addActionListener(new ActionListener(){
	public void actionPerformed(ActionEvent e){
		int valor = Integer.parseInt(valor1.getText()) + Integer.parseInt (valor2.getText());
		valor3.setText(Integer.toString(valor));
	}
});

this.botao2.addActionListener(new ActionListener(){
	public void actionPerformed(ActionEvent e){
		int valor = Integer.parseInt(valor1.getText()) - Integer.parseInt (valor2.getText());
		valor3.setText(Integer.toString(valor));
	}
});
this.botao3.addActionListener(new ActionListener(){
	public void actionPerformed(ActionEvent e){
		int valor = Integer.parseInt(valor1.getText()) * Integer.parseInt (valor2.getText());
		valor3.setText(Integer.toString(valor));
	}
});
this.botao4.addActionListener(new ActionListener(){
	public void actionPerformed(ActionEvent e){
		int valor = Integer.parseInt(valor1.getText()) / Integer.parseInt (valor2.getText());
		valor3.setText(Integer.toString(valor));
	}
});

this.botao5.addActionListener(new ActionListener(){
	
	public void actionPerformed(ActionEvent c){
	
	  	
	}
});




this.add(rotulo1);
this.add(valor1);
this.add(rotulo2);
this.add(valor2);
this.add(botao);
this.add(botao2);
this.add(botao3);
this.add(botao4);
this.add(botao5);
this.add(botao6);
this.add(botao7);
this.add(rotulo3);
this.add(valor3);
this.setVisible(true);

}

}

3 Respostas

Diabo_Loiro

voce sabe criar um botao ou so copiou e colou?
e ponha os codigos nas tags code dps peça ajuda

Paezani

Não seria isso:

//botão limpar

this.botao6.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e){

valor3.setText("");

}

});
Calmont

Se for apenas isso vou ficar muito inrritado !!!

Criado 29 de abril de 2009
Ultima resposta 29 de abr. de 2009
Respostas 3
Participantes 3