Hi!, can anyone help me on Applet, Please!!!


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Hi!, can anyone help me on Applet, Please!!!

  1. #1
    Join Date
    Aug 2004
    Location
    Philippines
    Posts
    17

    Unhappy Hi!, can anyone help me on Applet, Please!!!

    Hello!,
    If anyone can read this please help me on this, Please!
    I have an Applet Code and the only problem is that the total of two number will not display and If anyone can read this please! help me.
    the Applet Code is here:


    import java.applet.Applet;
    import java.awt.*;
    import java.awt.event.*;



    public class Compute extends Applet implements ActionListener
    {
    TextField txtunit,txtrate,txttotal;
    Button cmdAdd, cmdMultiply, cmdSubtract, cmdDivide;
    Label ato,babe,cam;
    double Total;
    Font newFont = new Font("Verdana",Font.BOLD,12);
    public void init()
    {
    this.setForeground(SystemColor.control);
    this.setBackground(SystemColor.control);
    ato = new Label("Enter a Number:");
    ato.setFont(newFont);
    ato.setForeground(Color.red);
    txtunit = new TextField(7);
    txtunit.setBackground(Color.blue);
    txtunit.setForeground(Color.yellow);
    add(ato);
    add(txtunit);
    babe = new Label("Enter a Number:");
    babe.setFont(newFont);
    babe.setForeground(Color.blue);
    txtrate = new TextField(7);
    txtrate.setBackground(Color.yellow);
    txtrate.setForeground(Color.red);
    add(babe);
    add(txtrate);
    cam = new Label("Total");
    cam.setFont(newFont);
    cam.setForeground(Color.red);
    txttotal = new TextField(7);
    txttotal.setBackground(Color.blue);
    txttotal.setForeground(Color.yellow);
    add(cam);
    add(txttotal);
    cmdAdd = new Button("Add");
    cmdMultiply = new Button("Multiply");
    cmdSubtract = new Button("Subtract");
    cmdDivide = new Button("Divide");
    cmdAdd.setForeground(Color.blue);
    cmdMultiply.setForeground(Color.blue);
    cmdSubtract.setForeground(Color.blue);
    cmdDivide.setForeground(Color.blue);
    add(cmdAdd);
    add(cmdSubtract);
    add(cmdMultiply);
    add(cmdDivide);
    cmdAdd.addActionListener(this);
    cmdMultiply.addActionListener(this);
    cmdSubtract.addActionListener(this);
    cmdDivide.addActionListener(this);
    }
    public void actionPerformed(ActionEvent AlcioAbaquita)
    {
    if(AlcioAbaquita.getSource() == cmdMultiply)
    {
    Total = Double.parseDouble(txtunit.getText()) * Double.parseDouble(txtrate.getText());
    txttotal.setText(String.valueOf(Total));
    }
    else if(AlcioAbaquita.getSource() == cmdAdd)
    {
    Total = Double.parseDouble(txtunit.getText()) + Double.parseDouble(txtrate.getText());
    txttotal.setText(String.valueOf(Total));
    }
    else if(AlcioAbaquita.getSource() == cmdDivide)
    {
    Total = Double.parseDouble(txtunit.getText()) / Double.parseDouble(txtrate.getText());
    txttotal.setText(String.valueOf(Total));
    }
    else if(AlcioAbaquita.getSource() == cmdSubtract)
    {
    Total = Double.parseDouble(txtunit.getText()) - Double.parseDouble(txtrate.getText());
    txttotal.setText(String.valueOf(Total));
    }
    }
    }

  2. #2
    Join Date
    Jul 2005
    Location
    the Netherlands
    Posts
    128
    Hi t_b_a_t_e,

    I couldn't see anything in your code so I compiled it and ran the applet. It works just fine! Every operation (including adding) works.
    If you load your applet through an internet browser, you could try deleting your temp-files in your internet browser; maybe there's an old version of your class-file cached somewhere.
    Try it, and if it doesn't work, just let post again.

    Good luck.

Similar Threads

  1. JavaMail applet problem
    By Tataroz T. in forum Java
    Replies: 1
    Last Post: 10-20-2005, 07:19 AM
  2. Replies: 3
    Last Post: 08-23-2001, 12:01 PM
  3. applet and thread problems
    By aneesha in forum Java
    Replies: 0
    Last Post: 05-06-2000, 11:38 PM
  4. Applet and thread problems
    By Aneesha in forum Java
    Replies: 0
    Last Post: 05-06-2000, 11:36 PM
  5. Replies: 0
    Last Post: 03-28-2000, 02:52 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center