LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-10-2003, 06:22 AM   #1
JStew
Member
 
Registered: Oct 2002
Location: North Atlanta
Distribution: LFS
Posts: 229

Rep: Reputation: 30
Java Input


I have been trying to find an efficient way to handle input with Java. It seems there are no simple answers.

This is what I have been trying to use: INPUT

There's an imported file here called ITPInput.java that you compile into the directory with your main .java file. It compiles and so does the main .java file but when I try to run java main.java i get this error:
Exception in main java.lang.NoClassDefFoundError: input

Does anyone know of a way for my programs to accept user input that is somewhat simple?

in pseudocode this is what im trying to do:

print "What is your name?"
input name

print "Hello, " + name

something that is really simple.
 
Old 03-10-2003, 07:14 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
i seem to remember using system.in.read or something very similar. but that might have been a hack my university insisted on.
 
Old 03-10-2003, 07:21 AM   #3
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
i seem to remember using system.in.read or something very similar. but that might have been a hack my university insisted on.
 
Old 03-10-2003, 08:02 AM   #4
JStew
Member
 
Registered: Oct 2002
Location: North Atlanta
Distribution: LFS
Posts: 229

Original Poster
Rep: Reputation: 30
that would seem to make sense, but i think in this imported file it has to be a call by value, but after searching all morning, i think ill just stick with this import until something just hits me in the head....
 
Old 03-10-2003, 08:05 AM   #5
pperon
Member
 
Registered: Jan 2002
Location: Cleveland
Distribution: Gentoo and umm... Gentoo
Posts: 64

Rep: Reputation: 15
I actually wrote this before I realized that you were probably interested in command line input. Sorry...

Code:
import javax.swing.JOptionPane;

public class InputDemo {
        public static void main(String argv[]) {
                String name = JOptionPane.showInputDialog("What is your name?");
                JOptionPane.showMessageDialog(null, "Hello, " + name, "Hello", JOptionPane.INFORMATION_MESSAGE);    
                System.exit(0);                                                                 
        }
}

...so here's the command line way:


Code:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class InputDemo2 {
                      
   public static void main (String argv[]) {
      System.out.print("What is your name? ");
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      String name = null;
      try {
         name = br.readLine();
      } catch (IOException ioe) { 
      }
      System.out.println("Hello " + name);

   }

}
Hope this help.

-Phil
 
Old 03-10-2003, 09:09 AM   #6
JStew
Member
 
Registered: Oct 2002
Location: North Atlanta
Distribution: LFS
Posts: 229

Original Poster
Rep: Reputation: 30
Phil: yeah, i just needed the command line... i havent gotten into the applets and such just yet, but I'm sure I could use it very soon. Thanks!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Java plugin installed correctly for Firefox but not able to view any java applet tvn Linux - Software 10 04-15-2010 02:13 AM
Ctrl+Shift Unicode input gone, after installing Japanese Input Methodes polemon Linux - Newbie 1 09-20-2005 05:17 PM
java - how do you input from the command line zeviddalop Programming 4 11-10-2004 11:59 AM
Sendmail: timeout waiting for input from local during Draining Input andrewstr Linux - Software 0 07-14-2004 01:43 PM
my mouse input is takes as keyboard input in BASH e1000 Slackware 5 12-08-2003 03:00 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:36 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration