Folge dem Video um zu sehen, wie unsere Website als Web-App auf dem Startbildschirm installiert werden kann.
Anmerkung: Diese Funktion ist in einigen Browsern möglicherweise nicht verfügbar.
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.util.Enumeration;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
public class JTreeToXMLExample
{
public JTreeToXMLExample()
{
JTree tree = new JTree();
StringWriter writer = new StringWriter();
StringBuilder b = new StringBuilder();
writeToXML((DefaultMutableTreeNode)tree.getModel().getRoot(), writer, b);
System.out.println(writer.toString());
}
public void writeToXML(DefaultMutableTreeNode node, Writer writer, StringBuilder b)
{
String text = node.getUserObject().toString();
b.setLength(0);
try
{
b.append("<").append(text);
if (node.isLeaf())
{
b.append("/>\n");
writer.write(b.toString());
}
else
{
b.append(">\n");
writer.write(b.toString());
Enumeration<DefaultMutableTreeNode> children = node.children();
while(children.hasMoreElements()){
writeToXML(children.nextElement(), writer, b);
}
b.setLength(0);
b.append("</").append(text).append(">\n");
writer.write(b.toString());
}
}
catch (IOException e)
{
e.printStackTrace();
}
}
public static void main(String[] args)
{
new JTreeToXMLExample();
}
}