Results 1 to 4 of 4
  1. #1
    Jman is offline Member
    Join Date
    Dec 2007
    Posts
    17
    Rep Power
    0

    Default 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("");
    }
    }
    }

  2. #2
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    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.
    freedom exists in the world of ideas

  3. #3
    Jman is offline Member
    Join Date
    Dec 2007
    Posts
    17
    Rep Power
    0

    Default

    Hi sukatoa,

    thanks for your reply. Could you help me understand what you mean about string extractor method.

  4. #4
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    Thats my term only.... a kind of implementation where you will design your own specific class/method that receives the
    Given:
    and returns a desired string....

    Given:
    java.awt.Choice[choice0,128,0,128x21,current=nA] name="Jman" title="ManJ"
    freedom exists in the world of ideas

Similar Threads

  1. How to create directory through Java Code
    By Java Tip in forum java.io
    Replies: 1
    Last Post: 04-14-2009, 04:34 PM
  2. Replies: 8
    Last Post: 01-07-2008, 06:41 AM
  3. how to create a menu bar in java
    By tommy in forum New To Java
    Replies: 1
    Last Post: 08-05-2007, 08:43 AM
  4. Create a Calculator in Java
    By Albert in forum New To Java
    Replies: 2
    Last Post: 07-04-2007, 09:01 AM
  5. how to create pdf document from java
    By sreedharvlsi in forum New To Java
    Replies: 1
    Last Post: 07-02-2007, 12:57 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •