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.
Related
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.
I am new to javafx and building an java application using it with eclipse IDE. I learned how to create a main fx class and user interface with Scene builder. The main problem is i dont know how to get the user input (from the text field or from text area ) and display that text on console output or save that text into database after clicking 'save' button.
i want to know how can do above tasks using controller class in eclipse.
Any help would be appreciated and Thanks in advance.
I advise you first to learn the JavaFX without (FXML/Controller) and for your question :
//Event when button clicked
yourButton.setOnAction(evt->{
//display the text of your textField on the console
System.out.println(yourTextField.getText());
});
As for the Button with a Controller, you have to separate your program into two parts (View FXML |Controller java ). The official documentation explains it very well here, good luck !
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 am trying to make a simple application using LWUIT 1.4. Now i got a problem with TextField.
When I type a characters in TextField, the commands I have added will get hidden and it overlaps with Clear and T9 command. How do i remove these commands?
Can anyone please provide me reference or sample code for removing the command.
Thanks in advance.
Use either TextField.setReplaceMenu(false) or derive text field and override installCommands and the removeCommands methods.
I currently have a program that prints lines of text to the screen in various manners such as 'System.out.println()' statements and for loops the print all elements in an array to screen.
I am now adding a GUI to this program. My problem is that I want to print everything that prints to eclipse's console to a textbox in my GUI instead. Is this possible and if so how would I go about doing this.
Thanks in Advance.
Check out this blog article, entitled Redirecting System.out and System.err to JTextPane or JTextArea. It describes almost everything you need.
The basic idea is that you create your own specialized output stream. In your implementation of the write() methods, you call some code to append the new data to your text box. Then, you set this new output stream as your System.out by calling System.setOut() or System.setErr().
NOTE: that article is missing one thing. You need to start your program in a separate thread.
An idea:
Create your own PrintStream that outputs everything to this textbox.
Then set this new PrintStream to be the standard output stream like that:
System.setOut(myPrintStream());