|
Tips & Tricks |
|
public class OpenBrowserAction
implements ActionListener{
public void actionPerformed(ActionEvent
ae){
try {
URI uri = new URI(“http://
www.javajazzup.com”);
Desktop desktop = null;
//Test whether
Desktop class is supported on the current
platform.
if (Desktop.isDesktopSupported()) {
// If it’s
supported, retrieve an instance.
desktop = Desktop.getDesktop();
}
if (desktop != null)
// Launch
the default browser to display a URI.
desktop.browse(uri);
}
catch (IOException e) {
e.printStackTrace();
}
catch (URISyntaxException e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) throws
Exception {
LaunchBrowser screen = new
LaunchBrowser();
}
}
This program shows a frame, which holds a
command button labeled by “Open Browser”.
|
|
Clicking the button opens “http://
www.javajazzup.com” in the default
browser.
4. Reading XML file:
This program reads the XML file using DOM
parser, which loads the XML file into the memory
and makes its object model that can be
traversed to get its elements. The class
DocumentBuilderFactory is responsible for
obtaining new DOM parsers that produces DOM
object trees from XML documents. The java
program ReadMyXMLFile.java parses
EmpInfo.xml file and prints its elements to
the console in the desired manner.
EmpInfo.xml
<?xml version = “1.0” ?>
<Employee-Info>
<Employee>
<Emp_Id> E001 </Emp_Id>
<Emp_Name> Emp1 </Emp_Name>
<Emp_E-mail> emp1@javajazzup.com </
Emp_E-mail>
</Employee>
<Employee>
<Emp_Id> E002 </Emp_Id>
<Emp_Name> Emp2 </Emp_Name>
<Emp_E-mail> emp2@javajazzup.com </
Emp_E-mail>
</Employee>
</Employee-Info>
|
|
Dec 2007 | Java Jazz Up | 73 |
|
|
View All Topics |
All Pages of this Issue |
Pages:
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
32,
33,
34,
35,
36,
37,
38,
39,
40,
41,
42,
43,
44,
45,
46,
47,
48,
49,
50,
51,
52,
53 ,
54,
55,
56,
57,
58,
59,
60,
61,
62,
63 ,
64,
65 ,
66 ,
67 ,
68 ,
69 ,
70 ,
71 ,
72 ,
73 ,
74 ,
75 ,
76 ,
77 ,
78 ,
79 ,
80 ,
81 ,
82 , Download PDF |
|
|
|
|
|
|
|
|
|