• Post Reply Bookmark Topic Watch Topic
  • New Topic

help help  RSS feed

 
Manal Ahmad
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is my code which i reached ti it so it still some thing to add but i dont know how to add it
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class Keypad extends JPanel implements ActionListener {
//JButton[] buttons= new JButton[10] ;
JTextField input;
JTextField result;
double num1;
double num2;
double sum;
//=====================
public Keypad(JTextField input) {
this.input = input;
JButton button;

setLayout( new GridLayout(6,3) );
for(int i=1; i<=9; i++) {
button = new JButton(i+"");
button.addActionListener(this);
add(button);

}// for

button = new JButton("C");
button.addActionListener(this);
add(button);


button = new JButton("0");
button.addActionListener(this);
add(button);

button = new JButton(".");
button.addActionListener(this);
add(button);

button = new JButton("+");
button.addActionListener(this);
add(button);

button = new JButton("-");
button.addActionListener(this);
add(button);

button = new JButton("*");
button.addActionListener(this);
add(button);

button = new JButton("/");
button.addActionListener(this);
add(button);

button = new JButton("!");
button.addActionListener(this);
add(button);

button = new JButton("=");
button.addActionListener(this);
add(button);

}
//=====================================
public void actionPerformed(ActionEvent e) {
String keyLabel = ((JButton)e.getSource()).getText();
if(keyLabel.equals("C"))
input.setText("");
else if(keyLabel.equals("!"))
{

int n = Integer.parseInt(input.getText());
result.setText(factorial(n)+" ");

}
else
input.setText( input.getText() + keyLabel);


}

public void operation (double num1,double num2){
input.setText(input.getText()+ "+");
result.setText("num1" +" "num 2" ");
}
}



//======================================
public static int factorial(int n)
{
if (n == 0)
return 1 ;
else
return n * factorial(n-1);
}
}
the question say
1) Implement the calculator functions for adding, subtracting, multiplying and dividing.

pleaaaaaaaase help me to solve it
 
Joe Ess
Bartender
Posts: 9443
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Layne pointed out in your previous post, posting the same question a lot of times causes confusion, so please refrain from posting essentially the same question over and over in the future. We understand that you have a deadline for your homework assignment, but it is in your best interest that you do your own work. Your first step could be to either post code which compiles or ask us how to solve the compilation error.
[ May 10, 2005: Message edited by: Joe Ess ]
 
M Beck
Ranch Hand
Posts: 323
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
help you with what? the code you posted should give you a fair start already; there's a good example in the "factorial" part of it, which you should be able to extend to the other functions required. what are you having trouble understanding, are there any specific problems we could help you overcome?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!