Hello all. So i creating Calculator and i have a problem. First see my code :
import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; public class Salutine extends JFrame { //Numbers private JButton nulis; private JButton vienas; private JButton du; private JButton trys; private JButton keturi; private JButton penki; private JButton sesi; private JButton septyni; private JButton astuoni; private JButton devyni; private JTextField atsakymas; //Operators private JButton dalyba,daugyba,pridetis,atimtis; //Constructor public Salutine() { super("Skaiciuotuvas By xkendzu (Beta)"); setLayout(new FlowLayout()); nulis = new JButton("0"); vienas = new JButton("1"); du = new JButton("2"); trys = new JButton("3"); keturi = new JButton("4"); penki = new JButton("5"); sesi = new JButton("6"); septyni = new JButton("7"); astuoni = new JButton("8"); devyni = new JButton("9"); dalyba = new JButton("/"); daugyba = new JButton("*"); pridetis = new JButton("+"); atimtis = new JButton("-"); atsakymas = new JTextField("",20); add(nulis); add(vienas); add(du); add(trys); add(keturi); add(penki); add(sesi); add(septyni); add(astuoni); add(devyni); add(nulis); add(atsakymas); add(dalyba); add(daugyba); add(pridetis); add(atimtis); //Creating, when button pressing Skaiciai skaiciai = new Skaiciai(); nulis.addActionListener(skaiciai); vienas.addActionListener(skaiciai); du.addActionListener(skaiciai); trys.addActionListener(skaiciai); keturi.addActionListener(skaiciai); penki.addActionListener(skaiciai); sesi.addActionListener(skaiciai); septyni.addActionListener(skaiciai); astuoni.addActionListener(skaiciai); devyni.addActionListener(skaiciai); Veiksmai veiksmai = new Veiksmai(); dalyba.addActionListener(veiksmai); daugyba.addActionListener(veiksmai); pridetis.addActionListener(veiksmai); atimtis.addActionListener(veiksmai); } //Number class with method public class Skaiciai implements ActionListener { public void actionPerformed(ActionEvent e) { String nr1 = e.getActionCommand(); String nr2 = e.getActionCommand(); int nr11 = Integer.parseInt(nr1); int nr22 = Integer.parseInt(nr2); } } //Operator class with method public class Veiksmai implements ActionListener { public void actionPerformed(ActionEvent e1) { String op = e1.getActionCommand(); } } }
So when you pressed button of number, JTextField change text like 1 and when you pressed operator changed text to 1 +-/* and finally when you pressed last number change text to 1 +-/* 2 = 3.. So i need know how post variables with value in the next actionPerformed method. Maybe my code bad? Maybe I must using other method? Can you help me? Thanks..