combine multiple windows to a single window - java

I am developing an application which have the following windows
If the information entered in the windows are correct than only the user will be prompted with the windows in the above sequence. Now the customer has demanded me with this user interface.
Now I have to add all these windows in the last window format, with the specification's as the user will be allowed in the 2nd portion of the last image if the first information entered is correct.And the user when launches this app see the last image and can change the values as any time in the respective portions of the last window.
I have coded it in Swing Java.I am new to Java. I am working in Netbeans 7.1.2 I have three files as
1)Login.java
-containing my LoginDemo class which have main and form object of extended Jframe class
-Login class extending J frame and implementing action listener(this class creates an J frame of next file Enter the information.
2)Algorithm.java
creates new J frame object of next file if information is correct.
3)TravellingSalesmanProblem.java
gives the output as shown in Optimal Travel Route window.
I am accessing the information using REST call to a website.
So can anyone help me in this?

This will depend on how you structured you code. If you simply placed components directly onto the the windows/frames themselves, then you might be in for some work.
Alternatively, if you used panels, which you then placed onto windows, this might save you some time.
Anyway. Assuming you only have windows.
for each window do
myLastWindow.add(window.getContentPane());
This is pretty simple, but you'll also need to know the layout you want. I'd suggest something like GridLayout or VerticalLayout from the SwingX project.

Related

how to set a specific position though command line?

String cmd = "start calc.exe";
Process process = Runtime.getRuntime().exec(codeString);
I can call calculator out, but I wish to specify a accurate position like (200,300).
how can I rewrite my cmd String?
I know that java.awt.window can set a window or frame to the specific position.
Is there any method I can use to fill frame or window with my process?
There is no clean pure java solution because JDK does not provide API that can control non-java windows. So, if you want to can use JNI/JNA.
But I can suggest you a patch that will typically work.
Windows OS allows moving windows using keyboard. Try the following manually:
Win+R
type calc and press enter
press alt+space
press M
press enter
now use arrows to move the window. Press ESC to exit this mode.
All these actions can be implemented using java.awt.Robot.
So, you can run calculator and then immediately move its window where you want.
Well, this is not clear solution, but very simple one.
Expected Problems:
Alt+space is mapped to other, custom application
Other window that started together with calc overlaps it.
User will see that window is created somewhere and then quickly moved.
So, everything depends on how important all this for you. This solution is good as an exercise or demo but bad for real commercial application.

Calling a Java method using javascript from within a JPanel

I have a Java application which displays results on a JPanel. The results are displayed using HTML by using a JLabel.
Now I want to let the user interact with the local application by allowing local methods to be called when the user clicks on a link in that HTML document.
Is this possible?
To answer you question, then, it is possible, however you cannot use a JLabel, you need to insert a JavaFX component, and then you can set your class as a window variable on the DOM, and thus your methods can be called from JavaScript.
Have a look at this answer on this question. It looks like they are doing exactly what you want.

How do I create a gui for java that acts like a console

I created a text-based game similar to Zork and I need a gui to run it outside of Eclipse. I want to run it as a jar. (by the way I'm on a mac if that changes anything). I only need an output field and an input field. What would be the easiest way to achieve this?
And how much of my code would I need to change? (I used System.out.print for output and a Scanner for input)
If you want to crate GUI like console the simple way to do it is to add textarea component to your frame or or panel that has scroll bars through the viewport. Create a stream that feeds the component with text. Then simply redirect standard output to that stream. Finish. Start your GUI and enjoy the console.
If you don't want to run this on a terminal, you should probably use Swing with a JTextArea in which you append all the messages to the user, and a simple JTextField for the user to enter his commands.
Here's a quick example of JTextArea so you get an idea. You'll need to read more about events on Swing to make things like reacting to the user pressing the ENTER key to read the contents of the text field and run the game logic.
Note that the screenshot on the example above uses the "Metal" look and feel, but it should look much closer to a native application on the Mac.

OfficeBean won't display after moving containing Swing Panel from one Container to another

I'm developing a Java 6 applet which allows users to view OO (v.3.2) documents (read only), and if they choose, click a button which launches a new JDialog window, with the document displayed in it which allows the user to and mark and redact it as they wish. Once they are done, they can close the JDialog, which saves the document to a server and redisplay the updated document (read-only again) in the original applet window
I guessed that I could do this with a single instance of an OfficeBean, embedded in a Swing Panel. However, I cannot seem to successfully move my Panel (containing the OfficeBean) from the applet to the JDialog when the "Redact" button is clicked. All I get is a blank area in the JDialog where the document should be. I get no errors.
I have currently managed to get round this by creating new instances of the OfficeBean every time I need to display the document (once when the applet is loaded, again when the user chooses to redact and it is opened in a JDialog, and finally when they click "Save" in the dialog and the redacted result is displayed in the applet again.) However this means three trips to and from the server where the documents originate. That seems mad to me.
I'm in no way a Swing expert and may well be making a silly mistake. However, I've done a lot of fiddling around, debugging and googling and can't seem to get this to work. Can anyone help me in this? Am I trying to do something which is fundamentally impossible? I hope not.
One rule in Swing is that a component can only be displayed / attached to one part of the gui "tree" at a time. When you "move" your component to the dialog, are you first removing it from the applet?

Gui - Best way to navigate between windows?

I try to build a gui (Swing) for a simple java application. The application should have a start window like a menu. From there I would like to navigate to several other windows.
My question is what is the best-practice to achieve such a navigation? Should I build several JFrames and switch the visibility of them on/off when navigating OR should I better have one JFrame and add/remove JPanels in this single frame to navigate between the windows?
Thanks.
I recommend
Do not do a MDI application with sub-frames like those found in the old Windows days. They suck as they make the matter confusing.
Do design a tabbed interface. The welcome page/menu will be displayed on a first tab that is always created on the start.
All cool kids do that nowadays:
Visual Studio
Eclipse
Firefox
If each of your windows correspond to different task (possibly nested), you could present your application as a SDI, with on the left a task panel like:
Each of the task would display one JFrame with the associated window.
Other solution: a table of content like this picture on the left side
(note: it actually also displays a task panel in this example on the bottom right)
Multiple JFrames sounds like a better idea to me. Much more OO.
You must find a balance between these goals:
Not too many things in one "window"
The user must quickly be able to find the correct window to do the next step of work
All relevant information must be visible at any time
Eclipse solves this by creating many small editors where each editor shows some specific information and allows to modify it. Editors are then arranged within one OS window in tabs and "views". A view is always completely visible and they can be arranged. Think of a view as a way to cut an existing editor in half (horizontal or vertical) and then being able to replace one of the halves with another editor. Between each half, you have a splitter so you can adjust the sizes.
Arrangements of views are then saved in "perspectives".
This allows every user to create a perspective which contains all the necessary editors at the same time, arrange them as they need it and work effectively.

Categories