• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /netgear-WNDR4500v2-V1.0.0.60_1.0.38/ap/gpl/timemachine/gettext-0.17/gettext-tools/examples/hello-java-awt/
1// Example for use of GNU gettext.
2// This file is in the public domain.
3//
4// Source code of the Java/AWT program.
5
6import java.util.*;
7import java.io.*;
8import java.text.*;
9import java.awt.*;
10import java.awt.event.*;
11import gnu.gettext.*;
12
13public 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);
21          }
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);
35          }
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);
49  }
50
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();
63    }
64    return "???";
65  }
66}
67