473,385 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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.IOException; must be caught or declared to be thrown. String s = keyboard.readLine ();

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.NoSuchMethodError: main
Press any key to continue . . ."



import java.io.BufferedReader;
import java.io.*;
import javax.swing.JApplet;
import java.awt.Graphics;



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.println("Please enter 7 numbers with one space in between");
System.out.println("and the computer will output how many are positive, negative, and zeros.");
BufferedReader keyboard= new BufferedReader (new InputStreamReader (System.in));
String s = keyboard.readLine ();
int k=s.length();
while (i<k-1){
int x=Integer.parseInt(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++;



}
Oct 16 '07 #1
1 2219
r035198x
13,262 8TB
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.IOException; must be caught or declared to be thrown. String s = keyboard.readLine ();

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.NoSuchMethodError: main
Press any key to continue . . ."



import java.io.BufferedReader;
import java.io.*;
import javax.swing.JApplet;
import java.awt.Graphics;



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.println("Please enter 7 numbers with one space in between");
System.out.println("and the computer will output how many are positive, negative, and zeros.");
BufferedReader keyboard= new BufferedReader (new InputStreamReader (System.in));
String s = keyboard.readLine ();
int k=s.length();
while (i<k-1){
int x=Integer.parseInt(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?
Oct 16 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Rick | last post by:
Hi, I'm having problems with Java applets. I just generated a JApplet (also tried normal Applet) in Netbeans which is delivered with the newest JDK. When I compile it in Netbeans it seems to...
5
by: Ayesha Ahsan | last post by:
Hi, I use Runtime.getRuntime().exec(command) to make my system call. For Windows based Dos, i add "cmd /c" before I type in my system call. So for example make the system call "dir": String...
1
by: SPG | last post by:
Hi, I have a servlet application that I am trying to write a very basic load tester for. There application has several servlets, but all rely on the same session being used (IE: For logged in...
8
by: Andreas Røsdal | last post by:
Hi, Is there such a thing as python applets for web browsers? (eg. such as java applets?) I think that could be useful. Andreas R.
12
by: Wladimir Borsov | last post by:
On one of my web pages there is an java applets which works fine on my computer. However I noticed on some other computer that the run of java applets are disabled. I got an error message...
4
by: kdsutaia | last post by:
hi! I am trying to read file line by line using BufferReader class.Following I have written to read but some how for few of the file it is not reading the whole file. Can any help me to resolve this...
0
by: choukse | last post by:
Hi All, I am trying to bind to ADAM instance with a windows user through JNDI and it keeps failing. My ADAM and AD is running on same Windows 2k3 server. But, through LDP I am able to bind with...
0
by: =?Utf-8?B?YmVuIG1pdGNo?= | last post by:
hi i have a question about how to arrange linkage between a "framework" executable and an extensible set of "applet"s in DLLs that plug into the executable. the main exe is an application for...
1
by: chanshaw | last post by:
Hey I'm trying to execute a simple statement but im getting a java.sql.Statement is abstract; cannot be instantiated. I just want to execute a simple select statement import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.