Results 1 to 3 of 3

Thread: Claculator in Java..?

  1. #1
    Join Date
    Jul 2007
    Posts
    11

    Default Claculator in Java..?

    I am building the calculator using java programming. I have taken 10 button array now the problem is that when i am clicking on the buttons the number should be appeared in the textfield but it not doing so... the follwing is my code :--
    import java.awt.*;
    import java.awt.event.*;
    class MyCalci extends Frame implements ActionListener
    {
    TextField t;
    Button b[]=new Button[10];
    Panel p;
    MyCalci(String s)
    {
    super(s);
    p=new Panel();
    t=new TextField(10);
    setLayout(new GridLayout(3,2));
    for(int i=0;i<b.length;i++)
    {
    b[i]=new Button(Integer.toString(i));
    p.add(b[i]);
    }
    for(int i=0;i<b.length;i++)
    {
    b[i].addActionListener(this); }
    p.add(t);
    add(p);
    setSize(300,300);
    setLocation(120,120);
    setVisible(true);}
    public void actionPerformed(ActionEvent e)
    {
    for(int i=0;i<b.length;i++)
    {
    if(e.getSource()==b[i]){
    t.setText(b[i]);}
    }
    }public static void main(String[] args) {
    MyCalci mc=new MyCalci("My");}
    }
    I am Sorry for the previous mistake done...
    Thanx,
    Neha.
    Powered by Yahoo! Answers

  2. #2
    Join Date
    Feb 2008
    Posts
    3

    Default

    cant believe u actually wrote that. what does it do actually???
    Powered by Yahoo!

  3. #3
    Join Date
    Jun 2007
    Posts
    4

    Default

    Refer to java-a complete reference by naughton & schildt

    Refer to Java in a nutshell by Flanagan
    Powered by Yahoo! Answers

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •