Results 1 to 4 of 4
- 04-27-2008, 02:00 PM #1
Member
- Join Date
- Dec 2007
- Posts
- 17
- Rep Power
- 0
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, 05:43 PM #2
I think that was a string representation of the Choice object.java.awt.Choice[choice0,128,0,128x21,current=nA] name = title=
Correct me if im wrong....
Is there any output that's not similar to the pattern above?
if none, you can just cut theand have some String manipulation over it.....java.awt.Choice[choice0,128,0,128x21,current=nA]
eg. Specific string extractor method, that will extract the remaining string and returns the specific string you want.freedom exists in the world of ideas
- 04-27-2008, 06:50 PM #3
Member
- Join Date
- Dec 2007
- Posts
- 17
- Rep Power
- 0
Hi sukatoa,
thanks for your reply. Could you help me understand what you mean about string extractor method.
- 04-27-2008, 06:56 PM #4
Similar Threads
-
How to create directory through Java Code
By Java Tip in forum java.ioReplies: 1Last Post: 04-14-2009, 03:34 PM -
Creating and checking directories with java code
By tim in forum New To JavaReplies: 8Last Post: 01-07-2008, 05:41 AM -
how to create a menu bar in java
By tommy in forum New To JavaReplies: 1Last Post: 08-05-2007, 07:43 AM -
Create a Calculator in Java
By Albert in forum New To JavaReplies: 2Last Post: 07-04-2007, 08:01 AM -
how to create pdf document from java
By sreedharvlsi in forum New To JavaReplies: 1Last Post: 07-02-2007, 11:57 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks