0
I need help in java calculator please i submit my assignment tomorrow 2+2=4 its work 2+2 then press + how to show result last
how to show result last two variables on button + and
16 ответов
0
ok
0
package javaapplication15;
import java.awt.Button;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.Panel;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
class Gui22 extends WindowAdapter implements ActionListener{
Frame f;
Button b1,b2,b3,b4;
TextField tf;
double n1,n2,n3,re,add=0;
Panel p;
Gui22(){
f=new Frame("Calculator");
f.setLayout(new GridLayout(2,0));
f.setSize(300,300);
f.show();
p =new Panel();
p.setLayout(new GridLayout(2,2));
b1=new Button("1");
b2=new Button("2");
b3=new Button("+");
b4=new Button("=");
tf=new TextField(" ");
f.add(tf);
p.add(b1);
p.add(b2);
p.add(b3);
p.add(b4);
f.add(p);
f.addWindowListener(this);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
}
public void windowClosing(WindowEvent we){
System.exit(0);
}
public void actionPerformed(ActionEvent ae) {
if(ae.getSource()==b1){
tf.setText(tf.getText()+b1.getLabel());
}if(ae.getSource()==b2){
tf.setText(tf.getText()+b2.getLabel());
}if(ae.getSource()==b3){
n1=Double.parseDouble(String.valueOf(tf.getText()));
tf.setText("");
add=1;
}
if(ae.getSource()==b4){
n2=Double.parseDouble(String.valueOf(tf.getText()));
if(add>0){
re=n1+n2;
tf.setText(" "+re);
n1=0;
n2=0;
}
}
}
public class JavaApplication15 {
public static void main(String[] args) {
Gui22 gu=new Gui22();
}
}
0
1+2=3 answer is correct
0
but when you use normal window calculator 2+2+ no use equal button then show answer 4
0
bro i try
0
no bro its not work
0
when i press 1 then print on screen (null1)
0
yes bro
0
bro can you send me your whatsapp no i can talk easily please
0
bro i don't know about insert
0
bro your facebook i d