Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





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.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-27-2008, 04:00 PM
Member
 
Join Date: Dec 2007
Posts: 17
Jman is on a distinguished road
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("");
}
}
}
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-27-2008, 07:43 PM
sukatoa's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 527
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
Quote:
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
Quote:
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.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 04-27-2008, 08:50 PM
Member
 
Join Date: Dec 2007
Posts: 17
Jman is on a distinguished road
Hi sukatoa,

thanks for your reply. Could you help me understand what you mean about string extractor method.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 04-27-2008, 08:56 PM
sukatoa's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 527
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
Thats my term only.... a kind of implementation where you will design your own specific class/method that receives the
Quote:
Given:
and returns a desired string....

Given:
Quote:
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.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to create directory through Java Code Java Tip java.io 0 04-04-2008 04:44 PM
Creating and checking directories with java code tim New To Java 8 01-07-2008 07:41 AM
how to create a menu bar in java tommy New To Java 1 08-05-2007 09:43 AM
Create a Calculator in Java Albert New To Java 2 07-04-2007 10:01 AM
how to create pdf document from java sreedharvlsi New To Java 1 07-02-2007 01:57 PM


All times are GMT +3. The time now is 08:24 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org