|
|
Welcome to the Java Forums.
You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:
- have access to post topics
- communicate privately with other members (PM)
- not see advertisements between posts
- have the possibility to earn one of our surprises if you are an active member
- access many other special features that will be introduced later.
Registration is fast, simple and absolutely free so please, join our community today!
If you have any problems with the registration process or your account login, please contact us.
|
|

04-27-2008, 04:00 PM
|
|
Member
|
|
Join Date: Dec 2007
Posts: 17
|
|
|
Creating a java gui to create xml code
Hi All,
I need some help. I want to create a GUI java application with choice boxes and text fields that you can use to create xml code with. I just need some help.
1. I think I might be going about my code in the complete wrong direction. So if any one knows of a better way please help me.
2. when I run my code it works so there is no compile error but what I do not understand is when I choose something from my choice box it gets printed out in the following way:
<java.awt.Choice[choice0,128,0,128x21,current=nA] name = title=
but I want it to print out like this
<nA name = title =
First code is the GUI code:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class ToGUI extends JFrame {
private JLabel chooseAs;
private JLabel chooseOp;
private JLabel chooseAt;
private JLabel nameFilter;
private JLabel disc;
private JLabel nodeTitle;
private JLabel searchString;
private TextField tf1;
private TextField tf2;
private TextField tf3;
private TextField tf4;
private JFrame frame;
private Choice as;
private Choice op;
private Choice at;
private Panel north;
private Panel center;
private Panel west;
private TextArea jta;
private JButton generate;
private JButton clear;
public ToGUI() {
frame = new JFrame("ToGUI");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
Panel center = new Panel();
Panel north = new Panel();
Panel west = new Panel();
Container c = getContentPane();
c.setLayout(new BorderLayout());
nameFilter = new JLabel("Filter name:");
disc = new JLabel("Discription:");
nodeTitle = new JLabel("Title:");
tf1 = new TextField();
tf2 = new TextField();
tf3 = new TextField();
tf4 = new TextField();
JButton generate = new JButton("Generate");
JButton clear = new JButton("Clear");
searchString = new JLabel("Search String:");
chooseAs = new JLabel("Choose Assertion:");
chooseOp = new JLabel("Choose Operator:");
chooseAt = new JLabel("Choose Attribute:");
Choice as = new Choice();
as.add("nA");
as.add("iAn");
as.add("f");
Choice op = new Choice();
op.add("OR");
op.add("AND");
op.add("NOOP");
Choice at = new Choice();
at.add("SN");
at.add("SLn");
at.add("SO");
north.setLayout(new GridLayout (4,1));
north.add(chooseAs);
north.add(as);
north.add(chooseOp);
north.add(op);
north.add(chooseAt);
north.add(at);
north.add(nameFilter);
north.add(tf1);
north.add(disc);
north.add(tf2);
north.add(nodeTitle);
north.add(tf3);
north.add(searchString);
north.add(tf4);
c.add(west, BorderLayout.WEST);
west.setLayout(new GridLayout(1,1));
west.add(generate);
west.add(clear);
c.add(north, BorderLayout.NORTH);
jta = new TextArea(17,70);
center.add(jta);
c.add(center, BorderLayout.SOUTH);
ToChoice tc = new ToChoice(as, jta, tf1, tf3);
as.addItemListener(tc);
generate.addActionListener(tc);
tf1.addActionListener(tc);
tf3.addActionListener(tc);
}
public static void main(String [] args){
ToGUI c = new TopoGUI();
c.setSize(520, 450);
c.setVisible(true);
}
}
next code is my choice code:
import java.awt.event.*;
import java.awt.*;
public class ToChoice implements ItemListener, ActionListener {
private Choice c;
private TextArea ta;
private TextField tf;
private TextField tff;
public ToChoice(Choice c, TextArea ta, TextField tf, TextField tff) {
this.c = c;
this.ta = ta;
this.tf = tf;
this.tff = tff;
}
public void itemStateChanged(ItemEvent f)
{
String c = f.getItem().toString();
}
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand() == "Generate" || e.getSource() == tf)
{
ta.setText("<" + c + " " + "name =" + " " + tf.getText() + " " + "title=" + tff.getText() + '\n' + ta.getText());
tf.setText("");
}
else if(e.getActionCommand() =="Clear")
{
ta.setText("");
}
}
}
|
|

04-27-2008, 07:43 PM
|
 |
Senior Member
|
|
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 527
|
|
java.awt.Choice[choice0,128,0,128x21,current=nA] name = title=
I think that was a string representation of the Choice object.
Correct me if im wrong....
Is there any output that's not similar to the pattern above?
if none, you can just cut the
java.awt.Choice[choice0,128,0,128x21,current=nA]
and have some String manipulation over it.....
eg. Specific string extractor method, that will extract the remaining string and returns the specific string you want.
__________________
A specific, detailed, simple, well elaborated, and "tested before asking" question may gather more quick replies. hopefully To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

04-27-2008, 08:50 PM
|
|
Member
|
|
Join Date: Dec 2007
Posts: 17
|
|
|
Hi sukatoa,
thanks for your reply. Could you help me understand what you mean about string extractor method.
|
|

04-27-2008, 08:56 PM
|
 |
Senior Member
|
|
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 527
|
|
Thats my term only.... a kind of implementation where you will design your own specific class/method that receives the and returns a desired string....
Given:
java.awt.Choice[choice0,128,0,128x21,current=nA] name="Jman" title="ManJ"
__________________
A specific, detailed, simple, well elaborated, and "tested before asking" question may gather more quick replies. hopefully To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|