Install gettext-0.18.1.1.tar.gz
[msysgit.git] / mingw / share / doc / gettext / examples / hello-java-awt / Hello.java
blobe10202b39262b51b5b794eede9e883808b7b572d
1 // Example for use of GNU gettext.
2 // This file is in the public domain.
3 //
4 // Source code of the Java/AWT program.
6 import java.util.*;
7 import java.io.*;
8 import java.text.*;
9 import java.awt.*;
10 import java.awt.event.*;
11 import gnu.gettext.*;
13 public class Hello {
14 public static void main (String[] args) {
15 ResourceBundle catalog = ResourceBundle.getBundle("hello-java-awt");
16 Frame frame = new Frame("Hello example");
17 frame.addWindowListener(
18 new WindowAdapter() {
19 public void windowClosing (WindowEvent event) {
20 System.exit(0);
22 });
23 Label label1 = new Label(GettextResource.gettext(catalog,"Hello, world!"));
24 Label label2 =
25 new Label(
26 MessageFormat.format(
27 GettextResource.gettext(catalog,
28 "This program is running as process number {0}."),
29 new Object[] { getPid() }));
30 Button button = new Button("OK");
31 button.addActionListener(
32 new ActionListener() {
33 public void actionPerformed (ActionEvent event) {
34 System.exit(0);
36 });
37 Container labels = new Container();
38 labels.setLayout(new GridLayout(2, 1));
39 labels.add(label1);
40 labels.add(label2);
41 Container buttons = new Container();
42 buttons.setLayout(new FlowLayout(FlowLayout.RIGHT));
43 buttons.add(button);
44 frame.setLayout(new BorderLayout());
45 frame.add(labels, BorderLayout.CENTER);
46 frame.add(buttons, BorderLayout.SOUTH);
47 frame.pack();
48 frame.setVisible(true);
51 /* Return the process ID of the current process. */
52 private static String getPid () {
53 try {
54 String[] args = new String[] { "/bin/sh", "-c", "echo $PPID" };
55 Process p = Runtime.getRuntime().exec(args);
56 InputStream p_out = p.getInputStream();
57 String s = (new BufferedReader(new InputStreamReader(p_out))).readLine();
58 p.destroy();
59 if (s != null)
60 return s;
61 } catch (IOException e) {
62 e.printStackTrace();
64 return "???";