One by one. Who is not too lazy to read the code . I think the idea is pretty clear (a simple calculator).
import java.awt.FlowLayout; import javax.swing.*; public class calc_97_lvl { public static JLabel jlab; calc_97_lvl() { ListenCalc LC = new ListenCalc(); JFrame jfrm = new JFrame("Калькулятор Кузнецова"); jfrm.setSize(185, 157); jfrm.setLayout(new FlowLayout()); jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jfrm.setVisible(true); JLabel jlab = new JLabel(); jlab.setText("egeherjrj!"); jlab.setSize(150, 150); JButton but1 = new JButton("+"); JButton but2 = new JButton("-"); JButton but3 = new JButton("*"); JButton but4 = new JButton("/"); JButton but5 = new JButton("."); JButton but6 = new JButton("e"); JButton but7 = new JButton("="); JButton b1 = new JButton("1"); JButton b2 = new JButton("2"); JButton b3 = new JButton("3"); JButton b4 = new JButton("4"); JButton b5 = new JButton("5"); JButton b6 = new JButton("6"); JButton b7 = new JButton("7"); JButton b8 = new JButton("8"); JButton b9 = new JButton("9"); JButton b0 = new JButton("0"); but1.addActionListener(LC); but2.addActionListener(LC); but3.addActionListener(LC); but4.addActionListener(LC); but5.addActionListener(LC); but6.addActionListener(LC); but7.addActionListener(LC); b1.addActionListener(LC); b2.addActionListener(LC); b3.addActionListener(LC); b4.addActionListener(LC); b5.addActionListener(LC); b6.addActionListener(LC); b7.addActionListener(LC); b8.addActionListener(LC); b9.addActionListener(LC); b0.addActionListener(LC); jfrm.add(jlab); jfrm.add(b1); jfrm.add(b2); jfrm.add(b3); jfrm.add(but1); jfrm.add(b4); jfrm.add(b5); jfrm.add(b6); jfrm.add(but2); jfrm.add(b7); jfrm.add(b8); jfrm.add(b9); jfrm.add(but3); jfrm.add(but5); jfrm.add(b0); jfrm.add(but6); jfrm.add(but7); } public void set_jlab(String newText) { jlab.setText(newText); } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { new calc_97_lvl(); } }); } } import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.StringTokenizer; public class ListenCalc implements ActionListener { double numberResult; public void actionPerformed(ActionEvent ae) { resultGiver(ae.getActionCommand()); } public double resultGiver(String textResult) { StringTokenizer ST = new StringTokenizer(textResult, "+-*/e", true); String s1 = ST.nextToken(); String s2 = ST.nextToken(); String s3 = ST.nextToken(); double op1 = Double.parseDouble(s1); double op2 = Double.parseDouble(s3); if (s2.equals("+")) { numberResult = op1 + op2; } else if (s2.equals("-")) { numberResult = op1 - op2; } else if (s2.equals("*")) { numberResult = op1 * op2; } else if (s2.equals("/")) { numberResult = op1 / op2; } else {} return 0; } }