Results 1 to 2 of 2
Thread: Simple Homework applet problems
- 12-08-2011, 09:50 PM #1
Member
- Join Date
- Dec 2011
- Posts
- 4
- Rep Power
- 0
Simple Homework applet problems
The program has a lot of errors I am brand new to this i need to know what is wrong
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();
}
}
-
Re: Simple Homework applet problems
You need to let folks know what errors are happening and where rather than simply dumping your code in the forum. If your code has many compilation errors you're also going about your coding wrong -- you should not add any new code while a compilation error exists until the error has been fixed.
Most importantly you'll want to read the Java tutorials to see how a program should be written. This is like math where all knowledge is built incrementally on a solid foundation. Without the foundation we won't be able to help you.
Edit, this is a double post of an already active post in the forum. Please read the forum rules and don't do this. This thread is being locked. Do not do this again.
Similar Threads
-
I'm having problems with my simple prompting program.
By ziongio in forum New To JavaReplies: 4Last Post: 01-21-2011, 10:43 PM -
Two simple array problems.
By DMiller in forum New To JavaReplies: 4Last Post: 11-06-2009, 11:50 AM -
I need simple java applet
By silvia in forum Java AppletsReplies: 4Last Post: 01-27-2008, 07:50 AM -
problems when I try to run an applet
By boy22 in forum Java AppletsReplies: 2Last Post: 08-11-2007, 03:47 PM -
problems with applet
By paty in forum Java AppletsReplies: 1Last Post: 08-05-2007, 04:16 AM


LinkBack URL
About LinkBacks

Bookmarks