Scanning Input File Then Running Applet
Oct 14, 2014
So this is probably pretty simple but I can't seem to figure it out. My teacher wants us to write a code that scans a text file, then outputs some text based information AND displays an applet bar graph of the data sorta like this for the text:
Sample Bar Graph
1-10 |*****
11-20 |******
21-30 |**
31-40 |*
41-50 |***********
51-60 |******
61-70 |********
71-80 |***
81-90 |****
91-100 |****
and then an applet thats the same info just a little more graphic. My code interprets the input well, but when i try to make an applet output, the code basically forgets all of my variables and starts anew (when i just state the public static graphic (paint) class after everything) OR it refuses to scan the input file (if i switch the public class from main.....throw ExceptionIO to just public class graphic(paint))
Also, as a side note, any way to have java automatically determine how many separate lines there are in a text file without me having to manually count them.
import java.util.Scanner;
import javax.swing.JApplet;
import java.awt.*;
import java.io.*;
public class Project2 extends JApplet {
[Code] ....
View Replies
ADVERTISEMENT
Jan 17, 2014
I've been trying to get user input as a text and then outputting one of 2 answers depending on the input.
import java.util.*;
public class kt_3_1 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
[code]...
This program compiles but always returns "FUUUUUUUu", even if I'd typed "summer".
View Replies
View Related
Jul 29, 2014
I'm having an issue with my program that needs 2 lines of input when I only want one. First I call Scan.nextLine(); to fetch a word. Then I want Scan.findInLine(word).charAt(number); to scan the string word for a letter instead of having to put another line in the console. How do I make Scan.findInLine(word).charAt(number); scan a single String instead of scanning input typed by the user?
View Replies
View Related
Apr 30, 2014
When i run a applet file in browser(IE, Chrome, Firefox) it gives a error of security risk and block the application from running. All browser are giving same error. Programme is running correctly in Myeclipse
View Replies
View Related
Oct 21, 2014
When I am trying to run an applet in command prompt I am getting an error message saying: System cannot find the file specified.
Initially I compiled my applet using javac BubbleSort1.java it works fine But when I tried running this using: appletviewer BubbleSort1.html I m getting the above error. Anyhow, both the html file n the java file are in same folder in C drive. (windows 7) .....
View Replies
View Related
Mar 2, 2014
Write a program that scans a text file for possible e-mail addresses. Addresses look like this:
someone@somewhere.net
Read tokens from the input file one by one using hasNext() and next(). With the default delimiters of Scanner, an entire e-mail address will be returned as one token. Examine each token using the indexOf() method of String. If a token contains an at sign @ followed some characters later by a period, regard it as a possible e-mail address and write it to the output file.
Programs such as this scan through web pages looking for e-mail addresses that become the targets of spam. Because of this, many web pages contain disguised e-mail addresses that can't easily be automatically extracted and above that is says to modify a program from our chapter which is this:
import java.util.Scanner;
import java.io.*;
class NamedFileInOut {
public static void main (String[] args) throws IOException {
int num, square;
[Code] ....
This is the first time hasnext() and next() have been introduced to me, so whereas scan.nextInt() looks for integers, does hasNext() looks for strings or characters? the wording in the exercise text is confusing to me. so basically i should create a text file with a ton of strings and within that jumble of text, stick a few email addresses; then when the program asks the user for the input file name, use that text file's name correct? pretty sure i have it up to that point, but using the indexOf() is what i'm having trouble wrapping my head around. do i look for the index of "@" and "."? i could conceptually see how i could say if the indexOf(".") is three spaces before the end then i know it's a .com or .net or .org or whatever. but how would i use indexOf("@") when the "user name" AND the "provider" (i.e. @yahoo or @google or @whatever) have an infinite number of lengths? we haven't had literally any discussion on input/output in classes so i am totally green to this.
View Replies
View Related
Apr 12, 2014
I'm doing an assignment for uni and have come across a small hiccup. What I'm trying to do is scan in a text file and read "commands" for it line by line, E.g:
Student Mary 12345 19
Student Joe 12346 19
Change Joe 19 20
Change Mary 19 20
So that lines that begin with the word "Student" indicate that I should create a new student file with that name, student ID, and age.
"Change" indicates that I should be changing the specified student's current age to the new age etc.
What I'm currently doing is something along the lines of this:
Scanner input = new Scanner(new FileReader(args[0]));
String[] line;
while (input.nextLine().startsWith("Student")) {
line = input.nextLine().split("s+");
[Code] ....
The problem I'm having is that every second line seems to be getting skipped (because I'm calling nextLine() so much?) but I can't think of a way to "peek" at the first word of each line without advancing past it. Is there any way of doing this?
View Replies
View Related
Jan 18, 2014
I want to know can we put the data of html file example
<html>
<body><applet code="classname" width="100" height="100">
</applet>
</body>
</html>
into my Applet's java file it can be done i have read it somewhere and have also implemented it ..... but now unable to memorize it
View Replies
View Related
Jun 11, 2014
I just wrote a java program with eclipse that has to read many-many inputs from the user. I want to test it, but I really don't want to type it everytime again and again...
Can I just write all inputs in a text file and let eclipse read this file so instead of typing it again and again, Eclipse reads every line whenever it waits for a user input?
View Replies
View Related
Nov 6, 2014
We've got a java web app (running on a Solaris machine with Weblogic) and from time to time it stops working due to this error:
Java Code: java.net.SocketException: Too many open files mh_sh_highlight_all('java');
For what I've read we are somehow exceeding the established limit of file descriptors, and it seems that this may be caused for many reasons, not only open files that we forgot to close.
I am making a list of everything that may consume a file descriptor in the system mentioned above, so I can start reanalyzing the app... if needed, as I don't know if we're wasting them or if the limit is just insufficient.
View Replies
View Related
May 19, 2014
This is my program: RemoteXMLRead.java
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.apache.commons.io.filefilter.WildcardFileFilte r;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
import org.w3c.dom.Element;
import java.io.File;
[code]....
It is working fine when i run in Eclipse, but is giving error when i run in cmd.. What i need to do to over come this..
View Replies
View Related
Apr 16, 2015
I am working on a management gui for a program. I have implemented the start server button. But now I need to get something working so that when I press stop server the javaw.exe process which is running the the other jar file is stopped and ended.
The gui is going to be using a javaw.exe as well and I don't want to end the entire thing.
I just want to end the javaw.exe process that is running the other jar file.
This is my code for starting it:
JButton btnNewButton_2 = new JButton("Start Server");
btnNewButton_2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Runtime rt = Runtime.getRuntime();
try {
Process pr = rt.exec("java -jar DEDServer_release.jar");
[Code] ....
I just need to figure out what to do to stop it now.
View Replies
View Related
Apr 24, 2014
import acm.util.* ;
import acm.program.*;
import java.awt.* ;
class Chap6_ex1 extends ConsoleProgram {
public void run() {
println("This program displays a randomly schosen card.");
int number = rgen.nextInt(1 ,13);
int suit = rgen.nextInt(1 ,4);
[Code] ....
I am running the this from a Linux command line , in the cmd first i use :
javac -classpath acm.jar Chap6_ex1.java
end then :
java -cp .:acm.jar Chap6_ex1
The output i m getting after second command is :
Exception in thread "main" acm.util.ErrorException: Cannot determine the main class.
at acm.program.Program.main(Program.java:1358)
I know the problem is from the RandomGenerator class in packet acm.util.* but i dont know how to fix the problem . Every other program has worked . What I am missing or how this whole issue of packet importing works when running a java file from cmd ?
View Replies
View Related
May 22, 2014
I'm running a jar of an application and library jars from lwjgl. I'm creating a java process. It's working on Windows but not on linux.
I tried replacing the semicolons with colons but it didn't work, it just said "Main class not found: Application.natives.linux" or something like that. gamePath is the path the application is in. osName is the name of the operating system.
Here's my code:
String jarRunner = String.format("java -Djava.library.path="%snatives/" + osName + "" -cp "%sjar/lwjgl.jar;%sjar/lwjgl_util.jar;%sjar/jinput.jar;%sjar/slick.jar;%sApplication.jar" main.Main", gamePath, gamePath, gamePath, gamePath, gamePath, gamePath);
Process p = Runtime.getRuntime().exec(jarRunner);
[Code] ....
How can I make it work on linux?
View Replies
View Related
Jul 10, 2014
I'm trying to run a command line executable file using java but there is no output. On the task manager a conhost process opens when the application is run. I've tried
1)try {
Runtime.getRuntime().exec("D: est.exe");
} catch (Exception e) {
e.printStackTrace();
}
2)String[] cmd = { "D: est.exe"};
Process p = Runtime.getRuntime().exec(cmd);
p.waitFor();
and
3)//Runtime.getRuntime().exec("D: est.exe", null, new File("D:"));
same thing happens i.e. nothing happens.
View Replies
View Related
Feb 27, 2014
I have a program that is a XML-parser, and it works fine when I'm running it from NetBeans. But when I create a JAR-file and run the very same program, it cannot find the xml file. Consider this small program that addresses my problem:
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import javax.xml.parsers.DocumentBuilder;
[Code] .....
View Replies
View Related
Nov 27, 2013
I have followed the Java tutorial on JAAS Authentication and Authorization. All the sample code in the tutorials works fine also when running under a security manager. Now I am trying to modify the LoginModule class, so that it uses a password file to look up users and passwords, but as soon as I try to run the code under a security manager, I get a Security Exception. I suppose it has something to do with the code havent been granted any access to read the password file? So I tried to add this to the policy file:
grant codebase "file:./sample/module/-" {
permission java.io.FilePermission "sample/module/passwords.txt", "read";
};
It didn't do any difference. why I get this Security Exception?
The only difference from my code to the tutorial code, is that I have added the lines:
Scanner scanner = null;
try {
scanner = new Scanner(new File("src/sample/module/passwords.txt"));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
to the login() method of the SampleLoginModule class...
View Replies
View Related
May 13, 2014
I am making a breakout like game in an applet for fun. i have the game working but for the last part of the game i want to make it so each time the game is played it adds the score the player. however, the code that i wrote does not work at all. Here is the code for the game.
import java.applet.Applet;
import java.awt.Color;
import java.awt.Event;
import java.awt.Graphics;
import java.awt.Rectangle;
[Code] ......
View Replies
View Related
Aug 7, 2014
I compiled the applet, then put the applet in an HTML file using notepad and saved the html file in the right place for it to run correctly. The HTML file runs smoothly, but then it only shows the scrollbar part of my applet, and not the images or any text...
Why is This?????
Java Code:
import java.awt.*;
import java.applet.Applet;
import java.awt.event.*;
import javax.swing.ImageIcon;
public class Temperature_Convert extends Applet
implements AdjustmentListener {
private Image temp;
private Scrollbar bar;
private int old, newtemp = 0;
[code]....
View Replies
View Related
Feb 3, 2014
what is the coding for udp port scanning?
View Replies
View Related
Jul 14, 2014
So I was going to try to create a program that prompts input and creates a file (That didn't exist before) with that input as name.Then, the program prompts inputs after stating questions such as 1 + 1, then if the user inputs an answer, put "Question # = Correct "or" Wrong.Code SO Far:
Java Code:
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
public class File_Read {
public File_Read() {//File_Read is the Interactive object
[code]....
So that it puts the Correct or Wrong into the file.
View Replies
View Related
Jun 10, 2014
I am building an app, where I have to store the data eg: "hello ! how are you" in java as a string and then use scanner to get input and check if the entered word is present in the line stored. If it is stored then the entire sentence must be displayed. eg : if the stored string is "hello how are you"
if the entered string is "how", then the entire sentence "hello how are you" should be displayed.
View Replies
View Related
May 15, 2014
I want to make a tool that does the 2 following things::
- Open files that are not .txt but can be opened as .txt and return them as a string. It just returns an empty string at the moment.
- The filenames are unknown, just the file extension at the end and the the YYYYMMDD number in front are always the same, therefore I'd like the app to simply scan every file in the same folder (not the same file twice, obviously). How can this be done?
That's what I've got so far.
Java Code:
public String readFile(String filename) throws FileNotFoundException {
Scanner scanner = null;
File file = new File(filename);
String output = "";
try{
[Code] .....
View Replies
View Related
Feb 19, 2014
I have been given a task to scan the contents of a websites source code, and use delimiters to extract all hyperlinks from the site and display them. We havent been told anything about how to do this so after some looking around online this is what I have so far:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Scanner;
[Code] ....
So my program can extract each line from the source code of a website and display it, but realistically I want it to extract each WORD as such from the source code rather than every line. I've looked around online but I don't really know how it's done because I keep getting errors when I use input.read();
How to make it extract each word from the source code?
View Replies
View Related
Sep 24, 2014
Well my code is supposed to ask for an input file and then (ex: input.txt), read the input file and create an output.txt file with the anagram for the words in the file. Also it should be displayed on the screen. However my code doesn't display the anagram on screen or the output file!
Heres is the code:
import java.io.*;
import java.lang.*;
import java.util.*;
/* This program will read a file given by the user, read the words within the file and determine anagrams of the given words. If the file that the user inputs is empty, then the program will output "The input file is empty."
* The program will read the file line by line, counting the total number of words read. If there are more than 50 words, "There are more than 50 words."
* will be printed, and the program will terminate. After each line is read, the words in the line will be separated,punctuation characters will be removed, and upper case characters will be switched to lower case.
* If any word is larger than 12 characters, that word will not be considered in the total amount of words in the file and it will not be sorted.
* After each word is read, the letters will be sorted and stored into an array containing each
* word's 'signature'. After all the words have been read, words will be printed to the output file on the same line based upon their signature.
*/
public class Anagram {
//Creating constants for maximum words in file and maximum chars in word
public static final int MAX_CHARS = 12;
public static final int MAX_WORDS = 50;
[Code] ....
View Replies
View Related
Mar 21, 2015
I am trying to read a file and input each line of the file into an array. I have not set the array size as I was hoping to fill the array using a while loop. Unfortunately the scope of the array does to work inside the while loop so I am being told that the array 'students' has not been initialised even though it has just outside of the while loop. Is it possible to do what I am trying to without having the array initialised in the while loop as surely the array will be reset every time if it was in the while loop? Here is my code:
public static void students(String file) throws FileNotFoundException {
try {
File studentInfo = new File(file);
Scanner input = new Scanner(studentInfo);
String[] students;
[Code] ....
View Replies
View Related