Results 1 to 5 of 5
  1. #1
    vicky1 is offline Member
    Join Date
    Apr 2010
    Posts
    3
    Rep Power
    0

    Post can anyone help me with this program iam new to java please

    I have few programs that was not working and there were many errors in that program can anyone help me with it please and change my errors also

    1.Adding text box to applet

    import java.awt.*;
    import java.applet.*;
    public class text extends Applet
    {
    public void init()
    {
    TextField text1,text2;
    text1=new TextField(8);
    text2=new TextField(8);
    add(text1);
    add(text2);
    }
    public void paint(Graphics g)
    {
    int x=0,y=0,z=0;
    String s1,s2,s3;
    g.drawString("input a no in each",10,50);
    {
    s1=text getText();
    x=Integer.parseInt(s1);
    s2=text getText();
    y=Integer.parseInt(s2);
    }
    {
    z=x+y;
    s3=String.valueOf(z)
    g.drawString("the sum is",10,75);
    g.drawString(s3,10,75);
    }
    public boolean action(Event ev,object ob)
    }
    repaint()
    return true;
    }
    }

    //<applet code="text.class" width=300 height=200></applet>



    2.Animation program

    import java.awt.*;
    import java.applet.*;
    public class ani extends Applet implements Runnable
    {
    Thread t;
    int x=0;
    int y=200;
    int j=5,i=50,k=40;
    public void start()
    {
    Thread t=new Thread(this);
    t.start();
    }
    public void run()
    {
    try
    {
    while(x<300)
    {
    x=5;
    Thread.sleep(75);
    repaint(0,180,300,50);
    if(x==296)
    x=0;
    }
    }
    catch(Exception e)
    {
    }
    }
    public void paint(Graphics g)
    {
    g.drawString("HAI",100,100);
    g.drawString("VICKY",x,y);
    }
    }

    < applet code="ani.class"width=300,height=200>< \applet>
    Last edited by vicky1; 04-01-2010 at 01:23 PM.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default

    1. You need to put your code in code tags.
    2. You need to actually say what the problem is...not just "it's not working, please fix".

  3. #3
    vicky1 is offline Member
    Join Date
    Apr 2010
    Posts
    3
    Rep Power
    0

    Default errors

    these are the errors in the 1st program

    /tmp/jc_25905/text.java:19: ';' expected
    s1=text getText();
    ^
    /tmp/jc_25905/text.java:21: ';' expected
    s2=text getText();
    ^
    /tmp/jc_25905/text.java:27: ';' expected
    g.drawString("the sum is",10,75);
    ^
    /tmp/jc_25905/text.java:30: illegal start of expression
    public boolean action(Event ev,object ob)
    ^
    /tmp/jc_25905/text.java:31: ';' expected
    }
    ^
    /tmp/jc_25905/text.java:32: invalid method declaration; return type required
    repaint()
    ^
    /tmp/jc_25905/text.java:33: ';' expected
    return true;
    ^
    /tmp/jc_25905/text.java:35: 'class' or 'interface' expected
    }
    ^
    /tmp/jc_25905/text.java:39: 'class' or 'interface' expected
    ^
    9 errors

  4. #4
    vicky1 is offline Member
    Join Date
    Apr 2010
    Posts
    3
    Rep Power
    0

    Default

    these are the errors of 2 program

    /tmp/jc_26378/animation.java:38: illegal character: \92
    \\<\applet> ^ /tmp/jc_26378/animation.java:38: illegal character: \92 \\<\applet> ^ /tmp/jc_26378/animation.java:38: illegal character: \92 \\<\applet> ^ /tmp/jc_26378/animation.java:39: 'class' or 'interface' expected ^ 4 errors

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default

    At least in text.java (and java classes start with a capital letter in the standards) your brackets are all out of synch. If you formatted your code correctly you would see that straight away.

Similar Threads

  1. execute java program within java program
    By popey in forum New To Java
    Replies: 2
    Last Post: 10-22-2009, 05:32 PM
  2. Run program from Java
    By nenadm in forum Advanced Java
    Replies: 4
    Last Post: 12-07-2008, 10:36 PM
  3. Java Program
    By littleBean in forum New To Java
    Replies: 7
    Last Post: 07-21-2008, 11:07 PM
  4. Replies: 0
    Last Post: 04-04-2008, 02:40 PM
  5. Replies: 0
    Last Post: 10-04-2007, 09:33 PM

Posting Permissions

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