creating an xml from the values in a Dialog in Java Swing - java

I have to create an xml file based on the value of attributes set by user in dialog of Java Swing.There are five attributes name,age,sex,date of birth and place. when the user clicks on OK button of the Dialog box an xml file should be created in the temp directory of the user.
Kindly help me as I am new to Java Swing
Regards,
Kumar

Create a GUI with controls to collect the data you specified. Create a class to generate the XML output. Call this class.

To build a Swing GUI, you start with a JFrame.
Within this JFrame, you have a master JPanel.
The attributes will each have JLabel components and JTextField components. You will use a layout manager to arrange the label and text field components.
You have a JButton so that the user can tell your program that she's entered all of the attributes.
You should be able to look up all these Swing components and build a GUI.
Then, as jzd said, you create a class to generate the XML output and call this class from the GUI.

Related

Finish input into JEditorPane on ENTER

I am using a JEditorPane as a component to show code. The JEditorPane resides in my custom PropertyEditorSupport for my Netbeans Platform app and is show in an OutlineView and the Properties window.
I've already limited the JEditorPane to be one line only, using a DocumentFilter. However I am not able to rebuild the funcionality a JTextField has, to finish input into the component by hitting the ENTER key.
I have already thought about adding a KeyListener event to my JEditorPane but am not sure what to do in case of the event. Is there a method to be called to "finish input of text"?
I am using a JEditorPane as a component to show code.
I've already limited the JEditorPane to be one line only
Those two statements seems to contradict one another. Usually codes consists of multiple lines, not one line.
In any case if you are simply display text then I would use a JTextPane as it supports text attributes. A JEditorPane is used to display HTML.
I have already thought about adding a KeyListener event
Don't use a KeyListener. Swing was designed to be used with Key Bindings. Basically you create an Action (in your case you would extend TextAction) and you bind the Action to a KeyStroke. Check out Key Bindings which contains more information as well as a link to the Swing tutorial on How to Use Key Bindings.

Creating a text adventure in Java

I am trying to create a text based adventure in Java I need help in combining a Scanner with JPanel so that the user can type into the panel directly rather than choosing from a list of options. Is there any way of doing this or would a dialogue be needed and if so is there a way of doing so within the JPanel?
For doing so, you need to add some components to your panel, such as, JtextField or JTextArea.
Then you have to add a action listener to your text field/area.
You can find a lot of advices with a simple google search.

java swing- Possible to add JLabel next to application icon/title?

Is the above question possible? The effect I'm trying to achieve is similar to how MS Word displays "Document- Microsoft Word (Technical Preview)" in this picture link: http://img.blogsolute.com/ms-word-2010.png, but with a colored background.
You can set the title of any frame you create by passing the title string to the constructor of the JFrame. You can't, however, add any controls to the 'decoration' portion of the frame - i.e., the title bar.
What you probably can do, however, is create an undecorated frame, and manually add the decoration using customised Border objects. This effectively allows you to put any controls you like around the outside, and the root pane will happily work inside it.
Why do you need JLabel for that? You can use setTitle("") for this purpose

How to pass data from a JTextField to another JTextField

I need to pass a text from a JTextField in a JFrame to a second JTextField in another JFrame. GUI has been created using GUI Editor netbeans 6.9.
Don't use a GUI Editor, especially if you are just learning Swing.
You need a reference saved somewhere to both fields so that you getText() of the first JTextField and setText() on the second field.
Use textField.getText to get the text from a textfield and anotherTextField.setText to set the text of the other textfield.
If your JFrames are in two different classes you may have to expose methods in those classes to get and set the text between them.
You should bind your model to both of the views (JTextFields) instead of copying Text from one to another.
Read http://www.martinfowler.com/eaaDev/OrganizingPresentations.html for more information.

How to use GUI form created in IntelliJ IDEA

I'm creating a simple GUI form with one button in IntelliJ IDEA 9. The class which was created with the form is not JFrame or any other swing class. How I can call my form in my source code?
I was stumped when IntelliJ consistently errored out when choosing Form main() from the insert menu, with an error message saying something about an invalid root component.
It turns out it means that the JPanel that is the main (root) component of your Form needs to have a field bound to it, and by default it doesn't do this.
Simply select the JPanel in the form designer, and give it a name (field name) in the property pane.
After this it will generate the main() just fine.
Simply go into the class associated with your form, press alt + insert and choose "Form main()".
Resources :
GUI Designer Basics
First add private JPanel Main; inside the class. Then, in the form's panel properties, add Main to the field name. Then, go to your class and from the Alt + Insert menu, select Main.
Now, the error wont come.

Categories

Resources