How can I do password masking (to hide an input text from terminal window) in Java?
I got the solution of using the console but I want to do it in an IDE (BLUEJ) ,which is not possible using the console. I want help.
The console in any IDE or terminal/command line can not be edited after something is printed out in it and simply prints what you ask of it and takes in input that you type.
However, if you are working with a GUI in Swing or JavaFX, you can display your text in a JPasswordField or PasswordField which hides the input as its typed while still storing the correct string values.
Related
I am currently working on a Java applet. The Java app has a text box which only allows plain text (Java code) to be written which will then be converted to visually represent the codes written by the user, i.e assume the user has created a linked list, I have to display the linked list using Grahics2D to draw boxes and all. I'm not able to interpret the codes written by the user in the text area. I would be very grateful to receive some of your help.
I have tried to solve the issue using Beanshell like this:
Interpreter bsh = new Interpreter();
bsh.eval("import java.lang.String;");
bsh.eval(srcCode);
Where srcCode is the text I have retrived from the text field like this:
txtCode.getText()
The interpreter is not able to compile classes written by the user.
How could I solve the issue I'm having?
I am developing a cmd like console using jTextArea, for an IDE. What I want to do is as I click the execute button, it provides me interactive input/output screen in the jTextArea.
I am able to grab the output contents of the cmd screen, but what if user wants to run a command like take two integers as input from stdin (here from my jTextArea) and display the sum, on my console screen, as if it happened in a normal cmd/terminal.
How do I send input to that instance/session?
See java.lang.Process, method java.lang.Process.getOutputStream()
The name OutputStream is a doubtful choice because it's the input of the underlying process, the output for your program.
I am a huge newbie and I have a program that normally prints items to the Java console window. I would like this program to become a window in which the user can interact with. The reason why I have not resorted to dialog boxes and panels is because this program require multiple prints to the console window. A traditional dialog box does not continuously update or compound on data that has already been printed on the box. I realize that there is another way of doing this by creating a program that mimics the Java console window. Because I am a noob, all of the java console redirecting questions and answers on this site have blown over my head. Can anyone please help me?
See maybe How to Use Editor Panes and Text Panes will be helpful and give you some ideas.
The short answer is, every time you want to update the contents of a text box, call the setText function again. There's no "append" function on the contents: you have to give the entire contents each time. If you want something that mimics a console window, where messages continue to scroll, the simplest thing to do is to keep the entire contents in a StringBuilder. Each time you get new text append to the StringBuilder, then setText(myStringBuilder.toString).
You could, I supppose, write mybox.setText(mybox.getText()+"new contents"). That would be a little inefficient but probably not a big deal.
I don't know exactly what you're up to, but trying to redirect console output to a text box sounds like more nuisance that it's worth. Just put your data in the text box: don't write it somewhere else, then try to get it back and put it where you want it. I suppose if you have thousands of lines of code writing to the console and now you want it to go a text box, there might be value in not having to change all that code. But the structure of a console app is so different from the structure of a GUI app that changing the output statements would probably be the least of the things you'd have to rework.
I have a console application that uses System.out.println's to output text. What I want to do is turn it into an applet, where instead of System.out.println's, it displays the text in a text box. Is there a relatively easy way to convert this?
Message Console is a simple class that will allow you to redirect ouput to a JTextArea or JTextPane.
Is there a relatively easy way to convert this?
Sure, all you need to do is create an applet1 and add a single JTextArea2 to it. And then instead of your System.out.println(str)'s, you do textArea.setText(str) (or textArea.setText(textArea.getText() + "\n" + str) to append text)
http://download.oracle.com/javase/tutorial/deployment/applet/
http://download.oracle.com/javase/tutorial/uiswing/components/textarea.html
EDIT
And to get user input, checkout the showInputDialog method from the JOptionPane class. Examples can be found here:
http://docs.oracle.com/javase/tutorial/uiswing/components/dialog.html
i have created a input form using Netbeans IDE containing a button and a Textarea.
if i click a button it should call output.java program where the main part of execution resides and it should display the output in the TextArea created in the input.java.
Am not getting the output in TextArea..the reason is my output.java program cudnt identify the textarea.
but am getting output in window output console.please help me overcome this problem.thanks in advance
That's because you're doing it all wrong. The textarea is in a different process so you need to capture the output of the other program yourself.
Try passing a reference of the JTextarea in question to the output.java as a Constructor or method argument.