Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / September 2005

Tip: Looking for answers? Try searching our database.

Having a problem with Standard Input (System.in)

Thread view: 
bherbst65@hotmail.com - 21 Sep 2005 19:12 GMT
Hi All,

I have Win2K with NT and am using j2sdk1.4.2_08

With the current IDE that I am using the console at the bottom displays
the instructions and then to enter the data, I have to seemingly have
to use the data Standard Input(System.in)
window. This is really aggravating because I have to constantly reset
the focus with the mouse in the Standard Input(System.in) with each new
question presented in the console.

Here is a  snip of what I am speaking about.

import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.awt.*;
import javax.swing.*;

public class MyPanelA extends JPanel  {
 private  String highestpwr,start,end,constant,interval,coefficient;
 private  double
constnumdblnum,intervaldblnum,startdblnum,enddblnum,x,y = 0.0;
 private  double CoeffArraydblnum[] = new double[10];
 private  int highestpwrnum,xmove,x1,ymove,y1 = 0;

 public MyPanelA() {
   InputStreamReader keyboard = new InputStreamReader(System.in);
   BufferedReader in = new BufferedReader(keyboard);
   System.out.println("We are going to enter the function's details
now");
   try
   {
     System.out.println("     ");
     System.out.println("Please enter the highest power for x :");
     //user enter the highest power
     highestpwr = in.readLine();
     highestpwrnum = Integer.parseInt(highestpwr);

     System.out.println("Please enter the desired start, end (left,
right) values for x:");

     //enter minimum start of the x values left side
     System.out.println("Start left sided from :");
     start = in.readLine();
     startdblnum = Double.parseDouble(start);

     //enters maximum end of the x values right side
     System.out.println("Ends on right side : ");
     end = in.readLine();
     enddblnum = Double.parseDouble(end);

     //enter increment step  0.1
     System.out.println("Now enter the interval :");
     interval = in.readLine();
     intervaldblnum = Double.parseDouble(interval);

     //enter constant term -2.0
     System.out.println("Please enter the constant number :");
     constant = in.readLine();
     constnumdblnum = Double.parseDouble(constant);

     for (int i = highestpwrnum; i > 0; i--) {
       System.out.println("Please enter coefficient for the X^" + i +
" term");
       coefficient = in.readLine();
       CoeffArraydblnum[i] = Double.parseDouble(coefficient);
     }
   } // end of try
   catch (Exception e) {
     e.printStackTrace();
   }
 }

Bob
Oliver Wong - 21 Sep 2005 19:49 GMT
> Hi All,
>
[quoted text clipped - 6 lines]
> the focus with the mouse in the Standard Input(System.in) with each new
> question presented in the console.

[code snipped]

   Your code doesn't have a static main function, and so therefore we can't
actually run it.

   That being said, it's very strange that you mixing System.out.println()
and System.in.readline() and Swing components (i.e. JPanel).

   Is this supposed to be a console-based (text only) application? If so,
eliminate all references to javax.swing.

   - Oliver
Monique Y. Mudama - 21 Sep 2005 19:55 GMT
> Hi All,
>
[quoted text clipped - 6 lines]
> focus with the mouse in the Standard Input(System.in) with each new
> question presented in the console.

What's your question?  What do you want it to do?

It sounds like this is an IDE problem, not a java problem.  As you
don't even mention which IDE you're using, it's hard to make any
suggestions.

Signature

monique

Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html

bherbst65@hotmail.com - 21 Sep 2005 21:26 GMT
Hi Oliver and Monique,

Thanks for resonding. I am using IDE: drjava-stable-20050814-2234.exe
version that is the latest.

How can I force both the print and the input  so that the message is
contained entirely in the console window?

As the snip reads above:

System.out.println("Ends on right side : ");
end = in.readLine();

OR

How can I force both the print and the input  so that the message is in
contained entirely in the popup?

Oliver,
Isn't input legal in swing? I need swing to do the JPanel as noted in
the snip. The program is quite long so I did not show the entire but if
you really need it, I can show it here.

Bob
Oliver Wong - 21 Sep 2005 21:32 GMT
> How can I force both the print and the input  so that the message is
> contained entirely in the console window?
[quoted text clipped - 8 lines]
> How can I force both the print and the input  so that the message is in
> contained entirely in the popup?

   It's much, much easier, IMHO, to do all the input to appear in the
console window, than to make do all the input and output in the pop up. So I
recommend you eliminate the pop up. The first step to doing that is to
remove all reference to javax.swing.

> Oliver,
> Isn't input legal in swing? I need swing to do the JPanel as noted in
> the snip. The program is quite long so I did not show the entire but if
> you really need it, I can show it here.

   It's legal in the sense that it compiled, and the program ran, but as
you see, it's not doing what you wanted it to do. You don't need a pop up,
right? So get rid of the pop up altogether.

   - Oliver
Roedy Green - 22 Sep 2005 01:40 GMT
>With the current IDE that I am using the console at the bottom displays
>the instructions and then to enter the data, I have to seemingly have
>to use the data Standard Input(System.in)
>window. This is really aggravating because I have to constantly reset
>the focus with the mouse in the Standard Input(System.in) with each new
>question presented in the console.

Here are some approaches.

1. run your app outside the IDE. Then the console in/out will be
merged.

2. did around in the IDE to see if there in an option to merge in/out

3. write a AWT or SWING app that gathers data through JTextFields
rather than by asking individual questions.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.

bherbst65@hotmail.com - 22 Sep 2005 07:53 GMT
Hi All,

I took a short trip to the goal line: downloaded jdk1.5.0_05 and then
downloaded drjava-beta-20050806-2057.exe which was also an improvement.
Now things behave normally, once inside the Standard Input(System.in),
the responses are one right after the other with no mouse clicks
necessary, just a press of the enter key.

Thanks to all for your advice and help

Bob


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.