| | |
applet array
![]() |
•
•
Join Date: Nov 2007
Posts: 1
Reputation:
Solved Threads: 0
how to creat an applet array of 4 to get integers from the user and display the total marks of those nos. i tried but loops are not working. here is my program.
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class test extends Applet implements ActionListener
{
Label l1,l2;
TextField t1,t2;
Button b1;
public void init()
{
GridLayout x=new GridLayout(3,2,5,5);
setLayout(x);
//row1
l1=new Label("Enter a Number:");
add(l1);
t1=new TextField();
add(t1);
//row2
l2=new Label("Total");
add(l2);
t2=new TextField();
add(t2);
b1=new Button("ADD Numbers");
add(b1);
b1.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
int tot,i,n;
int num[];
num = new int[4];
tot=0;i=0;n=0;
while (i<num.length)
{
if (e.getSource()==b1)
{
n=Integer.parseInt(t1.getText());
num[i]=n;
tot=tot+n;
t2.setText(String.valueOf(tot));
t1.setText(" ");
i++;
}
}
}
}
/*if (e.getSource()==b1)
{
do
{
i=i+1;
tot=tot+num[i];
t2.setText(String.valueOf(tot));
//t1.setText(" ");
}while (i<num.length);
*/
//}
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class test extends Applet implements ActionListener
{
Label l1,l2;
TextField t1,t2;
Button b1;
public void init()
{
GridLayout x=new GridLayout(3,2,5,5);
setLayout(x);
//row1
l1=new Label("Enter a Number:");
add(l1);
t1=new TextField();
add(t1);
//row2
l2=new Label("Total");
add(l2);
t2=new TextField();
add(t2);
b1=new Button("ADD Numbers");
add(b1);
b1.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
int tot,i,n;
int num[];
num = new int[4];
tot=0;i=0;n=0;
while (i<num.length)
{
if (e.getSource()==b1)
{
n=Integer.parseInt(t1.getText());
num[i]=n;
tot=tot+n;
t2.setText(String.valueOf(tot));
t1.setText(" ");
i++;
}
}
}
}
/*if (e.getSource()==b1)
{
do
{
i=i+1;
tot=tot+num[i];
t2.setText(String.valueOf(tot));
//t1.setText(" ");
}while (i<num.length);
*/
//}
Last edited by bluebird123; Nov 4th, 2007 at 2:36 am.
![]() |
Similar Threads
- Applet / Array help (Java)
- help!! My applet can't run... Urgent!! (Java)
Other Threads in the Java Forum
- Previous Thread: How can i display the score and grade.......?
- Next Thread: Is it possible to use A7Soft JExamXML with Crimson.
| Thread Tools | Search this Thread |
android api applet application apps array arrays automation awt bidirectional binary birt bluetooth businessintelligence busy_handler(null) card class classes client code collision columns component constructor crashcourse database designadrawingapplicationusingjavajslider draw eclipse error errors eventlistener exception expand fractal game givemetehcodez graphics gui guidancer html ide image inetaddress integer intellij j2me java javadoc javafx javamicroeditionuseofmotionsensor javaprojects jme jni jpanel jtree julia linux list loop machine map method methods mobile mobiledevelopmentcreatejar myaggfun netbeans newbie oracle physics plazmic print problem program project radio recursion scanner server set sharepoint smart sms smsspam sort sortedmaps sql string subclass support swing textfield threads tree trolltech unlimited utility webservices windows





