Problem je u tome sto umesto sabiranja on pomnozi prvi broj sa dva :S, umesto da sabere dva broja.
U cemu je problem?
Code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class AddTwo extends JFrame implements ActionListener {
JTextField broj1 = new JTextField("0",5);
JLabel plus = new JLabel("+");
JTextField broj2 = new JTextField("0",5);
JButton jednako = new JButton("=");
JTextField rezultat = new JTextField("0",5);
public AddTwo(){
super("Kalkulator");
setSize(400,100);
Container pane = getContentPane();
FlowLayout pliv = new FlowLayout();
pane.setLayout(pliv);
jednako.addActionListener(this);
pane.add(broj1);
pane.add(plus);
pane.add(broj2);
pane.add(jednako);
pane.add(rezultat);
setContentPane(pane);
setVisible(true);
}
public static void main(String[] args){
AddTwo frame = new AddTwo();
}
public void actionPerformed(ActionEvent e){
try{
int x = Integer.parseInt(broj1.getText());
int y = Integer.parseInt(broj1.getText());
rezultat.setText("" + (x+y));
}catch (NumberFormatException exc){
}
}
}
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class AddTwo extends JFrame implements ActionListener {
JTextField broj1 = new JTextField("0",5);
JLabel plus = new JLabel("+");
JTextField broj2 = new JTextField("0",5);
JButton jednako = new JButton("=");
JTextField rezultat = new JTextField("0",5);
public AddTwo(){
super("Kalkulator");
setSize(400,100);
Container pane = getContentPane();
FlowLayout pliv = new FlowLayout();
pane.setLayout(pliv);
jednako.addActionListener(this);
pane.add(broj1);
pane.add(plus);
pane.add(broj2);
pane.add(jednako);
pane.add(rezultat);
setContentPane(pane);
setVisible(true);
}
public static void main(String[] args){
AddTwo frame = new AddTwo();
}
public void actionPerformed(ActionEvent e){
try{
int x = Integer.parseInt(broj1.getText());
int y = Integer.parseInt(broj1.getText());
rezultat.setText("" + (x+y));
}catch (NumberFormatException exc){
}
}
}
----------
MSI H61M-P22 (B3), Intel® Pentium® Dual-Core G840 , DDR3 4GB 1333MHz Silicon Power, Nvidia GeForce 7300 LE, WD Black SATA 160GB , DVD-
RW Pioneer SATA, Bluetooth 2.0, Remote control(use IgorPLUG), Case Moded, MS Industrial 5.1(ML-6015), Dell U2312HM, Dell L100 keyboard, A4Tech X7 748k mouse
MSI H61M-P22 (B3), Intel® Pentium® Dual-Core G840 , DDR3 4GB 1333MHz Silicon Power, Nvidia GeForce 7300 LE, WD Black SATA 160GB , DVD-
RW Pioneer SATA, Bluetooth 2.0, Remote control(use IgorPLUG), Case Moded, MS Industrial 5.1(ML-6015), Dell U2312HM, Dell L100 keyboard, A4Tech X7 748k mouse