Results 1 to 6 of 6
  1. #1
    ADustedEwok is offline Member
    Join Date
    Dec 2011
    Posts
    4
    Rep Power
    0

    Default Please help with actionlistener

    my code is not working i know there are a lot of errors



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

    public class grades extends Applet implements ActionListener
    {
    //name
    Label name = new Label ("Please enter your name: ");
    TextField n1 = new TextField(10);

    //Subject1
    Label sub1 = new Label ("Please enter your first Subject: ");
    TextField n2 = new TextField(10);

    Label g1 = new Label ("Please enter your first Grade: ");
    TextField n3 = new TextField(10);

    //Subject2
    Label sub2 = new Label ("Please enter your second Subject: ");
    TextField n4 = new TextField(10);

    Label g2 = new Label ("Please enter your second Grade: ");
    TextField n5 = new TextField(10);

    //Subject3
    Label sub3 = new Label ("Please enter your third subject: ");
    TextField n6 = new TextField(10);

    Label g3 = new Label ("Please enter your third Grade: ");
    TextField n7 = new TextField(10);

    //Subject4
    Label sub4 = new Label ("Please enter your fourth subject: ");
    TextField n8 = new TextField(10);

    Label g4 = new Label ("Please enter your fourth Grade: ");
    TextField n9 = new TextField(10);

    //Subject5
    Label sub5 = new Label ("Please enter your fifth subject: ");
    TextField n10 = new TextField(10);

    Label g5 = new Label ("Please enter your fifth Grade: ");
    TextField n11 = new TextField(10);


    double avg = 0;
    public void init()

    {
    n3.addActionListener(this);

    add (g1);
    add (n3);

    }
    {
    n5.addActionListener(this);

    add (g2);
    add (n5);

    }
    {
    n7.addActionListener(this);

    add (g3);
    add (n7);

    }
    {
    n9.addActionListener(this);

    add (g4);
    add (n9);

    }
    {
    n11.addActionListener(this);

    add (g5);
    add (n11);

    }
    public void paint (Graphics g)
    {
    g.drawString ("Average: "+ avg, 3, 50);
    }
    public void actionPerformed(ActionEvent e)
    {
    g1 = Double.parseDouble(n3.getText());
    g2 = Double.parseDouble(n5.getText());
    g3 = Double.parseDouble(n7.getText());
    g4 = Double.parseDouble(n9.getText());
    g5 = Double.parseDouble(n11.getText());
    avg = (g1 + g2 + g3 + g4 +g5)/5;
    repaDouble();
    }
    }

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,641
    Rep Power
    7

    Default Re: Please help with actionlistener

    my code is not working i know there are a lot of errors
    And....what are the errors? Compile time? Runtime? And please, please wrap your code in the [code][/code] tags

  3. #3
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    6

    Default Re: Please help with actionlistener

    And your question is.... ?

    Btw.: g1-g5 are Labels!
    Double.parseDouble(n3.getText()); = Double, so you can not write g1 = ..... what do you want?

  4. #4
    joeyvitoro is offline Member
    Join Date
    Oct 2011
    Posts
    90
    Rep Power
    0

    Default Re: Please help with actionlistener

    What's wrong with it? What line errors? What is the error message?

  5. #5
    ADustedEwok is offline Member
    Join Date
    Dec 2011
    Posts
    4
    Rep Power
    0

    Default Re: Please help with actionlistener

    there are a lot of errors the program is to input grades and out comes the average

  6. #6
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,641
    Rep Power
    7

    Default Re: Please help with actionlistener

    I will say again...use the code tags. If you do so, it should become evident that your code is unstructured - method calls outside the realm of a method. If you don't know what I mean, you should spend some quality time reading the basic tutorials over at Oracle and become familiar with how a java program should be structured.

Similar Threads

  1. ActionListener
    By jaylimix in forum Java Applets
    Replies: 5
    Last Post: 11-06-2011, 07:05 PM
  2. Please Help With ActionListener
    By Daman12 in forum New To Java
    Replies: 29
    Last Post: 10-26-2011, 08:43 AM
  3. N o Action by ActionListener
    By MetalR0 in forum New To Java
    Replies: 6
    Last Post: 07-17-2011, 08:29 PM
  4. ActionListener - actionPerformed
    By collwill in forum New To Java
    Replies: 2
    Last Post: 04-21-2011, 07:01 PM
  5. ActionListener NOT working
    By zed420 in forum New To Java
    Replies: 3
    Last Post: 12-20-2009, 04:40 PM

Tags for this Thread

Posting Permissions

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