using bufferedreader with applets

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sassoon12
    New Member
    • Oct 2007
    • 1

    #1

    using bufferedreader with applets

    hi. Is it possible to use bufferedreader in an applet? if so where am i going wrong here ?
    im getting the following error: E:\CIS26\Hw1App .java:23: unreported exception java.io.IOExcep tion; must be caught or declared to be thrown. String s = keyboard.readLi ne ();

    I tried writing "throws exception" after declaring paint, but then it compiles, but when it runs it gives the error: "Exception in thread "main" java.lang.NoSuc hMethodError: main
    Press any key to continue . . ."



    import java.io.Buffere dReader;
    import java.io.*;
    import javax.swing.JAp plet;
    import java.awt.Graphi cs;



    public class Hw1App extends JApplet{
    public void init (){}
    public static void paint () {
    int n=0;
    int positives=0;
    int negatives=0;
    int zeros=0;
    int i=0;


    System.out.prin tln("Please enter 7 numbers with one space in between");
    System.out.prin tln("and the computer will output how many are positive, negative, and zeros.");
    BufferedReader keyboard= new BufferedReader (new InputStreamRead er (System.in));
    String s = keyboard.readLi ne ();
    int k=s.length();
    while (i<k-1){
    int x=Integer.parse Int(s.substring (0,i+1));
    if (x>0) //adds up the positive numbers that were input
    positives++;

    else if (x<0) //adds up the negative numbers that were input
    negatives++;

    else if (x==0) //adds up the zero numbers that were input
    zeros++;

    i++;



    }
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by sassoon12
    hi. Is it possible to use bufferedreader in an applet? if so where am i going wrong here ?
    im getting the following error: E:\CIS26\Hw1App .java:23: unreported exception java.io.IOExcep tion; must be caught or declared to be thrown. String s = keyboard.readLi ne ();

    I tried writing "throws exception" after declaring paint, but then it compiles, but when it runs it gives the error: "Exception in thread "main" java.lang.NoSuc hMethodError: main
    Press any key to continue . . ."



    import java.io.Buffere dReader;
    import java.io.*;
    import javax.swing.JAp plet;
    import java.awt.Graphi cs;



    public class Hw1App extends JApplet{
    public void init (){}
    public static void paint () {
    int n=0;
    int positives=0;
    int negatives=0;
    int zeros=0;
    int i=0;


    System.out.prin tln("Please enter 7 numbers with one space in between");
    System.out.prin tln("and the computer will output how many are positive, negative, and zeros.");
    BufferedReader keyboard= new BufferedReader (new InputStreamRead er (System.in));
    String s = keyboard.readLi ne ();
    int k=s.length();
    while (i<k-1){
    int x=Integer.parse Int(s.substring (0,i+1));
    if (x>0) //adds up the positive numbers that were input
    positives++;

    else if (x<0) //adds up the negative numbers that were input
    negatives++;

    else if (x==0) //adds up the zero numbers that were input
    zeros++;

    i++;



    }
    1.) Use code tags when posting code
    2.) Do you realize that applets are not run the same way as normal java applications? How are you running your applet?

    Comment

    Working...