A way to refresh program? - java

I have a program that reads comma separated lists from a text file, saves it into various arrays and then performs calculations. The calculations along with the data from the text file are displayed in a GUI.
The user has the option to edit some of the data by typing in a TextField. When they click 'Save and Refresh' it should update the calculations and display the new values.
Currently I can overwrite the text file with the new data but I have no way of updating it, other than opening and closing my program.
Is there a way to refresh or restart the program as if I had opened and closed it ?
Thankyou!

Related

How to check in java if user is clicking save button unnecessarily and there is nothing to save?

In my piece of code there is one input box so data will be fetched in that box on drop down selection. And if user do not want to insert/update/delete that data and click on save button unnecessarily then i have to show an error message that: "There is nothing to save..You pressed the save button unnecessary."
Currently , i am checking if the data in input box is equals to the database value then show that error but its not working.
if (inputVal1.equals(dbVal1.getValue()) && inputVal2.equals(dbVal2.getValue())) {
addPageError(T_NOTHING_TO_SAVE);
}
Please suggest how to handle this validation in java.
Store the data in a separate variable and simply compare it to the current values in the input box. If you do this, you could even detect if the values were changed, but then changed back to the original value. Apart from this you could also even deactivate the button and compare in an edit-event of the input box if the content has really changed and enable the button accordingly.

How to Extract Data from a JTable filled by user in Java

I have created a JTable using GUI Builder in NetBeans. It is Currently Having no data. The table is editable, and is Displayed in on a Panel. This Table is called passengerDetailsTable. Now I want users to Write data in its cells and after entering data, when they press submit, data should be extracted from table and available for processing. But I am unable to do it.
I have written sample code to do above:
TableModel tm = passengerDetailsTable.getModel();
Object o = tm.getValueAt(1,1);
System.out.println(o.toString());
This code is triggered when I press submit button.
According to me It should print the value at cell(1,1). But it gives Null pointer exception. Please help me to resolve it.
Now I want users to Write data in its cells and after entering data,
Did the data get saved to the model?
See Table Stop Editing for a way to make sure the data is save when you click a button.
If this doesn't help then post a proper SSCCE that demonstrates the problem because we don't have enough information to keep guessing what you might be doing.

How to print all content of a form in java?

I've been trying to find a command or sample code that when you click a button it will print all the content inside the form.!
i am trying to recreate our invoice and have a database for it, it is also necessary that i print that content with that form as we are using it on a daily basis.

Java: Making a editable list of items in a JPanel/JFrame

Sorry, I'm kind of a beginner to GUI interfaces (well, a beginner to java, really), and I was wondering: How does one make a list of items that the user can add items to or remove items from, with the press of a + or - button?
What I really want (sorry if I'm being a little vague here) is one of those lists you sometimes see in application windows, which looks like a text box but cannot be typed in. Right now my application (it's a small app to organize the schedule of a hospital) just reads from a text file and writes to another text file. No GUI, no window, the user just writes a bunch of names in the text file, one per line, then runs the jar and opens the output file and the schedule is there. I want them to just be able to add or remove names from a list with buttons — adding a name by clicking 'plus' and typing the name, and removing a name by selecting the name and clicking 'minus'. I still, however, want it to save to a text file, so that the next time the user opens the app, all the names are still on the list.
Just to be clear, I don't want a list displaying the output (i.e. the names organized into a schedule), just one containing the input.
Thanks a lot for any help you can give.
You probably want a JList with a couple of JButton instances to add/remove items.
See:
How to Use Lists
How to Use Buttons, Check Boxes, and Radio Buttons

Continuous Updating in Java Panel or Dialog Box

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.

Categories

Resources