1) parsing XML string content using dom4j
Import Org.dom4j.DocumentHelper;
String domstring = getdomstring ();
Document document = Documenthelper.parsetext (domstring);
list<element> list = Document.selectnodes ("Table/tr/td/div/div/span");
String str = list.get (0). GetText (). substring (3). Trim ();
2) Get the string returned by the server side via URL
Import Cp.common.IOUtils;
private static String getdomstring () throws ioexception{
InputStream in = null;
try {
URL url = new URL ("http://10.12.123.40/userinfo.aspx");
URLConnection UC = Url.openconnection ();
Uc.connect ();
in = (InputStream) url.getcontent ();
byte[] Buff = new byte[in.available ()];
In.read (Buff, 0, in.available ());
String str = new string (Buff, "UTF-8");
str = str.substring (Stringutils.indexof (str, "table")-1);
str = str.replace ("TopLevel", ""). Replace (" ", ""). Replace ("┆", "");
return str;
} finally {
Ioutils.closequietly (in);
}
}
3) pages implemented by Java Swing
public class App extends JFrame {
public static final int frame_width = 600;
public static final int frame_height = 450;
Private Mainpanel Mainpanel;
Private Configpanel Configpanel;
Private CardLayout Cardmanager;
Public App () {
Settitle ("STGCP" + version.getversion ());
Seticonimage (New ImageIcon (GetClass (). getClassLoader (). GetResource ("Tools.png")). GetImage ());
SetSize (Frame_width, frame_height);
Setlocationrelativeto (NULL);
Cardmanager = new CardLayout ();
Getcontentpane (). setlayout (Cardmanager);
Setminimumsize (New Dimension (Frame_width + +, frame_height));
Mainpanel = new Mainpanel ();
Getcontentpane (). Add (Mainpanel, "Mainpanel");
Configpanel = new Configpanel ();
Getcontentpane (). Add (Configpanel, "Configpanel");
Mainpanel.geteventdispatcher (). Setconfigpanel (Configpanel);
Pack ();
Setresizable (FALSE);
SetVisible (TRUE);
Setdefaultcloseoperation (Exit_on_close);
ActionListener al = new ActionListener () {
@Override
public void actionperformed (ActionEvent e) {
if ("Showsettings". Equals (E.getactioncommand ())) {
Cardmanager.show (App.this.getContentPane (), "Configpanel");
Configpanel.refreshconfigvalues ();
} else if ("Mainpanel". Equals (E.getactioncommand ())) {
Cardmanager.show (App.this.getContentPane (), "Mainpanel");
} else if ("ShowHelp". Equals (E.getactioncommand ())) {
Joptionpane.showmessagedialog (App.this, Version.gettips (), "hint", joptionpane.information_message);
}
}
};
Mainpanel.registercardlayoutchangelistener (AL);
Configpanel.registercardlayoutchangelistener (AL);
Addwindowlistener (New Windowadapter () {//Window Close Event
public void windowclosing (WindowEvent e) {
System.exit (0);
};
public void windowiconified (WindowEvent e) {//Window minimized event
App.this.setVisible (FALSE);
App.this.miniTray ();
}
});
New Thread (New Runnable () {
@Override
public void Run () {
String name = Userinfoutil.getuserrealname ();
if (Stringutils.isnotblank (name)) {
App.this.setTitle (App.this.getTitle () + "-Hello," + name);
}
}
}). Start ();
}
private void Minitray () {
ImageIcon trayimg = new ImageIcon (GetClass (). getClassLoader (). GetResource ("Tools.png"));
PopupMenu pop = new PopupMenu ();
MenuItem show = new MenuItem ("show");
MenuItem exit = new MenuItem ("Exit");
Final Systemtray tray = Systemtray.getsystemtray ();
Final TrayIcon TrayIcon = new TrayIcon (Trayimg.getimage (), "STGCP", pop);
Trayicon.setimageautosize (TRUE);
Show.addactionlistener (new ActionListener () {
public void actionperformed (ActionEvent e) {
Tray.remove (TrayIcon);
App.this.setVisible (TRUE);
App.this.setExtendedState (Jframe.normal);
App.this.toFront ();
}
});
Exit.addactionlistener (new ActionListener () {
public void actionperformed (ActionEvent e) {
Tray.remove (TrayIcon);
System.exit (0);
}
});
Pop.add (show);
Pop.add (exit);
Trayicon.addmouselistener (New Mouseadapter () {
public void mouseclicked (MouseEvent e) {
if (e.getclickcount () = = 2) {
Tray.remove (TrayIcon);
App.this.setVisible (TRUE);
App.this.setExtendedState (Jframe.normal);
App.this.toFront ();
}
}
});
try {
Tray.add (TrayIcon);
} catch (Awtexception E1) {
E1.printstacktrace ();
}
}
public static void Main (string[] args) {
Swingutilities.invokelater (New Runnable () {
@Override
public void Run () {
Font biggerfont = new Font ("Arial", Font.plain, 14);
Font font1 = new Font ("Arial", Font.plain, 12);
Font font2 = new Font ("Arial", Font.plain, 12);
Uimanager.put ("Panel.font", Font2);
Uimanager.put ("Popupmenu.font", Font2);
Uimanager.put ("Button.font", font1);
Uimanager.put ("Label.font", font1);
Uimanager.put ("Editorpane.font", Font2);
Uimanager.put ("Textfield.font", Biggerfont);
Uimanager.put ("Passwordfield.font", Biggerfont);
Uimanager.put ("Textpane.font", font1);
Uimanager.put ("Swing.boldmetal", false);
New App ();
}
});
}
}
DOM4J to parse the XML, get the string returned by the server side through the URL, the page implemented by Java Swing