public class lala extends JFrame{
//Creating Instance Variables
private JButton b0;
private JButton b1;
private JButton b2;
private JButton b3;
private JButton b4;
private JButton b5;
private JButton b6;
private JButton b7;
private JButton b8;
private JButton b9;
private JButton clear;
private JButton del;
private JButton add;
private JButton subtract;
private JButton divide;
private JButton multiply;
private JButton dot;
private JButton enter;
private JTextField field;
private JPanel panel;
private double temp;
private double temp1;
public lala(){
//Making objects for Components
b0 = new JButton("0");
b1 = new JButton("1");
b2 = new JButton("2");
b3 = new JButton("3");
b4 = new JButton("4");
b5 = new JButton("5");
b6 = new JButton("6");
b7 = new JButton("7");
b8 = new JButton("8");
b9 = new JButton("9");
del = new JButton("del");
clear = new JButton("C");
panel = new JPanel();
field = new JTextField();
add = new JButton("+");
subtract = new JButton("-");
multiply = new JButton("*");
divide = new JButton("/");
dot = new JButton(".");
enter = new JButton("Enter");
//Setting color to Panel
panel.setBackground(Color.GRAY);
//Setting Layout To Editors Choice
panel.setLayout(null);
//Editing Fields
field.setOpaque(false);
field.setFont(new Font("serif",Font.ITALIC,40));
//Setting the Components Positions
enter.setBounds(184,217,106,43);
subtract.setBounds(247,170,43,43);
add.setBounds(184,170,60,43);
divide.setBounds(248,122,43,44);
multiply.setBounds(184,122,60,43);
dot.setBounds(0,0,0,0);
del.setBounds(184,76,60,43);
field.setBounds(3,3,289,70);
clear.setBounds(248,76,43,43);
b0.setBounds(3,218,136,41);
b1.setBounds(3,170,43,43);
b2.setBounds(49,170,43,43);
b3.setBounds(95,170,43,43);
b4.setBounds(3,123,43,43);
b5.setBounds(49,123,43,43);
b6.setBounds(95,123,43,43);
b7.setBounds(3,76,43,43);
b8.setBounds(49,76,43,43);
b9.setBounds(95,76,43,43);
//Adding Listeners to Buttons
enter.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
temp = Integer.parseInt(field.getText());
temp1 = Integer.parseInt(field.getText());
field.setText(Double.toString(temp1*temp));
}
});
dot.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
field.setText(field.getText()+".");
}
});
multiply.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
field.setText("*");
}
});
divide.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
field.setText(field.getText()+"/");
}
});
subtract.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
field.setText("-");
}
});
add.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
field.setText("+");
}
});
del.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
field.setText("");
}
});
clear.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
field.setText(null);
}
});
b0.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
field.setText(field.getText()+"0");
}
});
b1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
field.setText(field.getText()+"1");
}
});
b2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
field.setText(field.getText()+"2");
}
});
b3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
field.setText(field.getText()+"3");
}
});
b4.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
field.setText(field.getText()+"4");
}
});
b5.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
field.setText(field.getText()+"5");
}
});
b6.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
field.setText(field.getText()+"6");
}
});
b7.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
field.setText(field.getText()+"7");
}
});
b8.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
field.setText(field.getText()+"8");
}
});
b9.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
field.setText(field.getText()+"9");
}
});
//Adding Components to Panel
panel.add(enter);
panel.add(add);
panel.add(subtract);
panel.add(multiply);
panel.add(divide);
panel.add(dot);
panel.add(del);
panel.add(clear);
panel.add(field);
panel.add(b0);
panel.add(b1);
panel.add(b2);
panel.add(b3);
panel.add(b4);
panel.add(b5);
panel.add(b6);
panel.add(b7);
panel.add(b8);
panel.add(b9);
//Adding Panel to JFrame
add(panel);
}
}