Не работают кнопки - Java
Формулировка задачи:
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JFrame;
public class k extends JFrame {
JButton b1,b2,b3,b4,b5,b6,b7,b8,b9;
JLabel l1,l2,l3;
JTextField t1;
long a,b;
String as,bs;
kh han = new kh();
public k (String s){
super(s);
setLayout(new FlowLayout());
l1 = new JLabel("||Первое число||");
l2 = new JLabel("||Второе число||");
l3 = new JLabel("||Ответ|| ");
add(l1);add(l2);add(l3);
b1 = new JButton("1");
b2 = new JButton("2");
b3 = new JButton("3");
b4 = new JButton("4");
b5 = new JButton("5");
b6 = new JButton("6");
b7 = new JButton("7");
b8 = new JButton("8");
b9 = new JButton("9");
add(b1);add(b2);add(b3);add(b4);add(b5);add(b6);add(b7);add(b8);add(b9);
b2.addActionListener(han);
b1.addActionListener(han);
}
public class kh implements ActionListener{
public void actionPerformed(ActionEvent e) {
if (e.getSource()==b1) {a = a*10+1;as = ""+a;l1.setText(as);}
if (e.getSource()==b2) {a = a*10+2;as = ""+a;l1.setText(as);}
if (e.getSource()==b3) {a = a*10+3;as = ""+a;l1.setText(as);}
if (e.getSource()==b4) {a = a*10+4;as = ""+a;l1.setText(as);}
if (e.getSource()==b5) {a = a*10+5;as = ""+a;l1.setText(as);}
if (e.getSource()==b6) {a = a*10+6;as = ""+a;l1.setText(as);}
if (e.getSource()==b7) {a = a*10+7;as = ""+a;l1.setText(as);}
if (e.getSource()==b8) {a = a*10+8;as = ""+a;l1.setText(as);}
if (e.getSource()==b9) {a = a*10+9;as = ""+a;l1.setText(as);}
}
}
}import javax.swing.JFrame;
public class k2 {
public static void main (String [] args){
k ka = new k("Калькулятор");
ka.setVisible(true);
ka.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ka.setSize(300,300);
ka.setResizable(false);
ka.setLocationRelativeTo(null);
}
}Решение задачи: «Не работают кнопки»
textual
Листинг программы
if (e.getActionCommand().equals("1"))