хотел бы создать тему, где можно будет выкладывать свой JAVA код и обсуждать ошибки компиляции, начну с первой программы - калькулятор:
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
import javax.swing.JFrame;
public class untitled10 {
JFrame frame;
JTextField t;
int x;
JButton button[] = new JButton[15];
String key[] = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9","+","-","*","/","="};
public static void main (String [] args) {
untitled10 gui= new untitled10();
gui.go();
}
public void go() {
frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
t=new JTextField(12);
frame.setSize(200,280);
frame.setResizable(false);
frame.setVisible(true);
frame.setLayout(new FlowLayout());
frame.add(t);
for (int i = 0; i<=15; i++){
button[i] = new JButton(key[i]);
frame.add(button[i]);
button[i].addActionListener(new BListener());
}
}
class BListener implements ActionListener {
int firstValue = 0;
String operation = "+";
public void actionPerformed (ActionEvent e) {
if (e.getSource()==button[1]) {
t.setText(null);
x=0;
t.setText(""+x);
}
if (e.getSource()==button[2]) {
t.setText(null);
x=1;
t.setText(""+x);
}
if (e.getSource()==button[3]) {
t.setText(null);
x=2;
t.setText(""+x);
}
if (e.getSource()==button[4]) {
t.setText(null);
x=3;
t.setText(""+x);
}
if (e.getSource()==button[5]) {
t.setText(null);
x=4;
t.setText(""+x);
}
if (e.getSource()==button[6]) {
t.setText(null);
x=5;
t.setText(""+x);
}
if (e.getSource()==button[7]) {
t.setText(null);
x=6;
t.setText(""+x);
}
if (e.getSource()==button[8]) {
t.setText(null);
x=7;
t.setText(""+x);
}
if (e.getSource()==button[9]) {
t.setText(null);
x=8;
t.setText(""+x);
}
if (e.getSource()==button[10]) {
t.setText(null);
x=9;
t.setText(""+x);
}
if (e.getSource()==button[11]) {
firstValue = Integer.valueOf(t.getText());
operation = "+";
}
if (e.getSource()==button[12]) {
firstValue = Integer.valueOf(t.getText());
operation = "-";
}
if (e.getSource()==button[13]) {
firstValue = Integer.valueOf(t.getText());
operation = "*";
}
if (e.getSource()==button[14]) {
firstValue = Integer.valueOf(t.getText());
operation = "/";
}
if (e.getSource()==button[15]) {
int secondValue = Integer.valueOf(t.getText());
if("+".equals(operation)){
t.setText((firstValue+secondValue)+"");
}
if("-".equals(operation)){
t.setText((firstValue-secondValue)+"");
}
if("*".equals(operation)){
t.setText((firstValue*secondValue)+"");
}
if("/".equals(operation)){
t.setText((firstValue/secondValue)+"");
}
}
}
}
}
в итоге не считает арифметические операции, в чем ошибка?
Социальные закладки