anirtak143
New Member
- Messages
- 213
- Reaction score
- 0
- Points
- 0
hey guys. i need help here.. ^^ kindly fix this class for me.. ^^ its just a small java program, but it wont compile and i dont know why.. kindly fix it please. ^^
thanks. heres the code..
thanks. heres the code..
Code:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Project2 implements ActionListener{
private JFrame MainFrame;
private JTextField TF1;
private JLabel Label1, Label2;
private JPanel Panel1, Panel2, Panel3, Panel4, Panel5;
private JButton AddButton, SubtractButton, MultiplyButton, DivideButton, ModuloButton,EqualsButton;
private double D1 = 0, D2;
private char OpDone = 'e';
private String UserInput;
public static void main(String[] args)
{ new Project2();
}
public Project2{
MainFrame = new JFrame("Kevin Mabul's Calculator");
Panel1 = new JPanel();
Panel2 = new JPanel();
Panel3 = new JPanel();
Panel4 = new JPanel();
Panel5 = new JPanel();
Label1 = new JLabel("Patience is a virtue");
Label2 = new JLabel("Java is a versatile language");
AddButton = new JButton("+");
AddButton.addActionListener(this);
SubtractButton = new JButton("-");
SubtractButton.addActionListener(this);
MultiplyButton = new JButton("x");
MultiplyButton.addActionListener(this);
DivideButton = new JButton("/");
DivideButton.addActionListener(this);
ModuloButton = new JButton("%");
ModuloButton.addActionListener(this);
EqualsButton = new JButton("=");
EqualsButton.addActionListener(this);
TF1 = new JTextField("0",15);
TF1.selectAll();
TF1.requestFocus();
Panel1.setBackground(Color.YELLOW);
Panel2.setBackground(Color.GREEN);
Panel3.setBackground(Color.GREEN);
Panel4.setBackground(Color.YELLOW);
Panel1.add(Label1);
Panel2.add(Label2);
Panel3.add(TF1);
Panel5.add(Panel1);
Panel5.add(Panel2);
Panel5.add(Panel3);
Panel5.add(Panel4);
Panel4.add(AddButton);
Panel4.add(SubtractButton);
Panel4.add(MultiplyButton);
Panel4.add(DivideButton);
Panel4.add(ModuloButton);
Panel4.add(EqualsButton);
Panel5.setLayout(new GridLayout(4,1);
MainFrame.setContentPane(Panel5);
MainFrame.pack();
MainFrame.show();
MainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e){
{
UserInput = TF1.getText();
double D2 = Double.parseDouble(UserInput);
{
if(OpDone =='a')
D1 = D1 + D2;
if(OpDone =='s')
D1 = D1 - D2;
if(OpDone =='m')
D1 = D1 * D2;
if(OpDone =='d')
D1 = D1 / D2;
if(OpDone =='r')
D1 = D1 % D2;
if(OpDone =='e')
D1 = D2;
}
if(e.getActionCommand().equals("+"))
OpDone = 'a';
if(e.getActionCommand().equals("-"))
OpDone = 's';
if(e.getActionCommand().equals("x"))
OpDone = 'm';
if(e.getActionCommand().equals("/"))
OpDone = 'd';
if(e.getActionCommand().equals("%"))
OpDone = 'r';
if(e.getActionCommand().equals("="))
OpDone = 'e';
}
UserInput = Double.toString(D1);
TF1.setText(UserInput);
TF1.selectAll();
TF1.requestFocus();
}
}