Hey I'm working with Java and cant seem to get my calculater working, Im trying to use my actionListener to make it all work.. Please help:)
import java.awt.FlowLayout;
import javax.swing.AbstractButton;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.text.JTextComponent;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class SimpleCalculator extends JFrame implements ActionListener{
JPanel p1=new JPanel(new FlowLayout(FlowLayout.LEFT,2,2));
private JTextField jtfNum1=new JTextField(4);
private JTextField jtfNum2=new JTextField(4);
private JTextField jtResult=new JTextField(4);
JPanel p2=new JPanel(new FlowLayout(FlowLayout.LEFT,2,2));
JButton jbtadd=new JButton("Add");
JButton jbtsubtract=new JButton("Subtract");
JButton jbtmultiply=new JButton("Multiply");
JButton jbtdivide=new JButton("Divide");
public static void main(String[] args) {
SimpleCalculator frame= new SimpleCalculator();
frame.setTitle("Exercise16_4");
frame.setSize(325,150);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
public SimpleCalculator(){
p1.add (new JLabel("Number 1"));
p1.add(jtfNum1);
p1.add(new JLabel("Number 2"));
p1.add(jtfNum2);
p1.add(new JLabel("Result"));
p1.add(jtResult);
jtResult.setEditable(false);
p2.add(jbtadd);
p2.add(jbtsubtract);
p2.add(jbtmultiply);
p2.add(jbtdivide);
jbtadd.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
//messsagePanel.moveLeft();
}
});
jbtsubtract.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
//messsagePanel.moveLeft();
}
});
jbtmultiply.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
//messsagePanel.moveLeft();
}
});
jbtdivide.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
//messsagePanel.moveLeft();
}
});
setLayout(new FlowLayout(FlowLayout.LEFT,10 ,20));
add (p1);
add(p2);
}
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
}
}