Huang Crystal

Greenhorn
+ Follow
since Jul 17, 2001
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Huang Crystal

Hi all,
I'm a greenhorn in Java so I need your advices on quite alot of swing basics.
Firstly, I areadly have 3 JButtons onto the JFrame.
The first button is "Add", it should have the functions of able to get the data from the JTextFields and save them to a file. The file will contain 1 line per product.
Secondly, a "Clear" button to clear the text fields.
Thirdly, a "Print" button to read all the data in the file and print to a standard output.
Pls advise and if poss. , wif some egs too...
thanx in advance..
22 years ago
Hi folks,I have already posted a message before and have been receiving a few replies(thanx)...But still can't solve my question. So here I am, posting it again and urge for more helps....Thanx alot..
I'm having problems with a current project which requires drawing up a pie chart with XSL and XML, the result will be in SVG.
There will be a few sectors in this chart and the angle of each sector is determined by its sales value in the XML file. However, the number of sectors and angle will change if new values are added to the XML file. For eg, presently the chart may consists of only 5 sectors, however when 2 new values are added in, the number of sectors will be 7.
As I am totally new to SVG, I have no idea on what's going on.
Any help/examples is greatly, enormously appreciated. Thanx alot..

------------------
0=),
Crystal
Hi there,
I've checked out the the website and I've tried to use the codings but it doesn't work. And what if I have to also display the values in percentage %?
Is there anyone with any examples?
Thanx alot...
------------------
0=),
Crystal
Thank you, Tanya.
------------------
0=),
Crystal
Hi all,
I have a project which requires mi to draw a pie chart using the XML values and XSL. Degrees have to be calculated to ensure the pie sectors are divided according to its value. Does anyone has an example or reference on this project of mine?
Any help is greatly appreciated.
Thanks alot..
------------------
0=),
Crystal
I will email you the classes.
Thanx for your help.
------------------
0=),
Crystal
Hi all,
I'm trying to convert a .csv file to .xml file. I've written some codes but there is error.
The result in .xml file should display 2 different rows of data, but instead the program just took the last row of data to form the .xml file. Which means that the result displayed consists of 2 same row of data. So, how should I go about writing the codes in order to make the 2 different row of data be displayed? Any advice is greatly appreciated.
Below is my codings:
/*
* CSVToXML.java
*/
package com.dotcomerp.tools.classes;
import java.io.File;
import java.util.*;
import javax.swing.text.*;
import org.jdom.Element;
import com.dotcomerp.tools.classes.*;
import com.dotcomerp.tools.interfaces.*;
public class CSVToXML implements DataConvert {

private static final String sTagRow = "tag";
private static final String sDataRow = "data";

public CSVToXML()
{
}

/*
/**
* Convert input string format to output format
* @param sInput input string
* @return output string
*/

public String convert(String sInput){

Element eResult = new Element("result");
List lResult = eResult.getMixedContent();
List lTags = null;
List list = StringUtility.splitAll(sInput, "\r\n");
Iterator i = list.iterator();
boolean bFirstRow = true;
List lTagsArray = new ArrayList();
Element eRow = null;

//iterate for the row
while (i.hasNext()) {
String sRow = (String)i.next();
System.out.println("sRow: " + sRow);
//System.out.println("\n\neresult 1:" + XMLParser.elemToString(eResult));

if(isTagName(sRow)){
//retrieve tags information from the first few rows
lTags = StringUtility.splitAll(sRow, ",");
lTagsArray.add(lTags);
System.out.println("lTagsArray: " + lTagsArray);
}
else
{
if(bFirstRow)
{ //last tags row
lTags = StringUtility.splitAll(sRow, ",");
lTagsArray.add(lTags);
System.out.println("lTagsArray2: " + lTagsArray);
eRow = getTagElement(lTagsArray);
//System.out.println("eRow: " + XMLParser.elemToString(eRow));
bFirstRow = false;
}
else
{
List lData = StringUtility.splitAll(sRow, ",");
System.out.println("lData: " + lData);

//this statement is to iterate the data
Iterator iData = lData.iterator();

//eRow is the element containing tags, lParent == <f/> <d/>
List lParent = eRow.getChildren();
Iterator iParent = lParent.iterator();
System.out.println("\n\neresult 2:" + XMLParser.elemToString(eResult));

while(iParent.hasNext())
{
//get the parent tags, <f/> <d/>
Element eParent = (Element)iParent.next();
System.out.println("Parent: " + eParent);
//get the tags WITHIN the parent tags
List lChildren = eParent.getChildren();
System.out.println("lChildren: " + lChildren);

//this statement is to iterate the children tags
Iterator iChild = lChildren.iterator();
//List lPrevious =
System.out.println("\n\neresult 3:" + XMLParser.elemToString(eResult));

while(iChild.hasNext() && iData.hasNext())
{
Element eChildTag = (Element)iChild.next();
String sData = (String)iData.next();
Element ans = eChildTag.setText(sData);
System.out.println("eChildTag: " + eChildTag);
System.out.println("sData: " + sData);
System.out.println("-----------------------");
}
}
System.out.println("\n\neresult before:" + XMLParser.elemToString(eResult));
lResult.add(eRow);
System.out.println("\n\nerow:" + XMLParser.elemToString(eRow));
System.out.println("\n\neresult after:" + XMLParser.elemToString(eResult));
}
}
}
//System.out.println("\n\neresult final:" + XMLParser.elemToString(eResult));
return XMLParser.elemToString(eResult);
}

/**
* Convert file content from one form to another
* @param sInputFileName input file name
* @param sOutputFileName output file name
*/

public void convert(String sInputFileName,String sOutputFileName)
{
DataConvert dc = new CSVToXML();
System.out.println("\nFile Content Conversion");
try
{
//read content of file
String sInput = FileUtility.readFile(sInputFileName);
//convert file content to xml format
String sOutput = dc.convert(sInput);
//store the edited file content to the sOutputfileName
FileUtility.overwriteFile(sOutputFileName, sOutput);
}
catch(Exception e)
{
System.out.println("Errors : " + e.getMessage());
}
}


/**
* Check for tag name row.
* Case 1: ,....
* Case 2: ...,
* Case 3: ...,,....
*/

private boolean isTagName(String sRow)
{
if(sRow.charAt(0)==',' | | sRow.charAt(sRow.length()-1)== ',' | | sRow.indexOf(",,") >= 0) {
//get tag names after the "tag" tag
//String tag = StringUtility.getBefore(",", sRow);
return true;
}
return false;
}

private Element getTagElement(List lTagsArray)
{
Element eData = new Element("row");
Element eRoot = eData;
//lTagsArray is the list containing tags, this method iterates thru the tags
Iterator i = lTagsArray.iterator();
Element eTag = null;
//count the row
int iCount = 0;
while(i.hasNext())
{ //iterating a row at a time
List lRow = (List)i.next();
Iterator iRow = lRow.iterator();

while(iRow.hasNext())
{
//extract/iterate the tag names within the current row
String sTag = (String)iRow.next();

if(!"".equals(sTag))
{ //new element found
eTag = new Element(sTag);
eRoot.getMixedContent().add(eTag);
}
//iterating the lTagsArray to check whether if the next row exists
//the i here == lTagsArray
if(i.hasNext())
{
List lNextTagsRow = (List)lTagsArray.get(iCount+1);
//add child elements to eTag
Iterator iNextTag = lNextTagsRow.iterator();

if(iNextTag.hasNext())
{
String sNextTag = (String)iNextTag.next();
Element eNewTag = new Element(sNextTag);
eTag.getMixedContent().add(eNewTag);
lNextTagsRow.remove(sNextTag);
}
}

}
iCount++;
}
return eData;
}
}
------------------
0=),
Crystal
Hi,
I do not quite understand. Do you mind to explain more specifically?
Thanx..
------------------
0=),
Crystal
22 years ago
Hi all,
I am implementing a GUI interface using swing. One of the requirements is to provide the status in the status bar.
For example, when the program is pinging all the IP addresses within the domain, the status bar should display something like "Pinging IP addresses...". Another example would be when opening a file, the status bar should display "Opening file..." etc.
Any example codes/help will be greatly appreciated.
Thanx for the help...0=)
------------------
0=),
Crystal
22 years ago
Thanx for the codes, Luong Nguyen.
It worked.
0=),
Crystal
22 years ago

Originally posted by Luong Nguyen:
Hi,
You can use Runtime.exec(cmd) method to launch the system's default browser. This is an example:
public class BrowserControl
{
/**
* Display a file in the system browser. If you want to display a
* file, you must include the absolute path name.
*
* @param url the file's url (the url must start with either "http://"
or
* "file://").
*/
public static void displayURL(String url)
{
boolean windows = isWindowsPlatform();
String cmd = null;
try
{
if (windows)
{
// cmd = 'rundll32 url.dll,FileProtocolHandler http://...'
cmd = WIN_PATH + " " + WIN_FLAG + " " + url;
Process p = Runtime.getRuntime().exec(cmd);
}
else
{
// Under Unix, Netscape has to be running for the "-remote"
// command to work. So, we try sending the command and
// check for an exit value. If the exit command is 0,
// it worked, otherwise we need to start the browser.
// cmd = 'netscape -remote openURL(http://www.javaworld.com)'
cmd = UNIX_PATH + " " + UNIX_FLAG + "(" + url + ")";
Process p = Runtime.getRuntime().exec(cmd);
try
{
// wait for exit code -- if it's 0, command worked,
// otherwise we need to start the browser up.
int exitCode = p.waitFor();
if (exitCode != 0)
{
// Command failed, start up the browser
// cmd = 'netscape http://www.javaworld.com'
cmd = UNIX_PATH + " " + url;
p = Runtime.getRuntime().exec(cmd);
}
}
catch(InterruptedException x)
{
System.err.println("Error bringing up browser, cmd='" +
cmd + "'");
System.err.println("Caught: " + x);
}
}
}
catch(IOException x)
{
// couldn't exec browser
System.err.println("Could not invoke browser, command=" + cmd);
System.err.println("Caught: " + x);
}
}
/**
* Try to determine whether this application is running under Windows
* or some other platform by examing the "os.name" property.
*
* @return true if this application is running under a Windows OS
*/
public static boolean isWindowsPlatform()
{
String os = System.getProperty("os.name");
if ( os != null && os.startsWith(WIN_ID))
return true;
else
return false;
}
/**
* Simple example.
*/
public static void main(String[] args)
{
displayURL("http://www.javaworld.com");
}

// Used to identify the windows platform.
private static final String WIN_ID = "Windows";
// The default system browser under windows.
private static final String WIN_PATH = "rundll32";
// The flag to display a url.
private static final String WIN_FLAG = "url.dll,FileProtocolHandler";
// The default browser under unix.
private static final String UNIX_PATH = "netscape";
// The flag to display a url.
private static final String UNIX_FLAG = "-remote openURL";
}


Thanx for the codes..
22 years ago
Hi all,
My problem is that I have to link the helpMenuItem to a specified URL, which in turns will launch the system's default web browser. Can anybody help me?
It will be better if there is example.
any help is GREATLY APPRECIATED..
0=),
Crystal
22 years ago
Hi all,
I have already implemented a Tree at the left panel of my GUI. But I want it to display the file (or all files in that particular directory) on the other panel, when clicked by the user, just like the function of the window explorer. How should I go about doing it?
Below are parts of my code:
DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root");
getTree(root,new File("c:\\jakarta-tomcat\\trans\\data"));
JTree jTree2 = new JTree(root);
jPanel2.add(jTree2);
jTree2.putClientProperty("JTree.lineStyle", "Angled");
private void getTree(DefaultMutableTreeNode parent, File f)
{
String fileNames[] = f.list();
for(int i=0;i<fileNames.length;i++)>
{ //files within the directory
DefaultMutableTreeNode child = new DefaultMutableTreeNode(fileNames[i]);
parent.add(child);
File fTmp = new File(f,fileNames[i]);
if(fTmp.isDirectory())
getTree(child,fTmp);
}
Thanx so much..
22 years ago
Hi all,
I am implementing a GUI interface using swing. One of the requirements is to provide the status in the status bar.
For example, when the program is pinging all the IP addresses within the domain, the status bar should display something like "Pinging IP addresses...". Another example would be when opening a file, the status bar should display "Opening file..."..etc..
Any example codes/help will be greatly appreciated.
Thanx for the help...0=)
[This message has been edited by Huang Crystal (edited August 02, 2001).]
22 years ago
Hi all, can anyone tell me how to display the time and date in the status bar using swing?
Advice on the implementation on the status bar is need too.
thanx in advance...
22 years ago