• 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-swing/
1// Example for use of GNU gettext.
2// This file is in the public domain.
3//
4// Source code of the Java/Swing program.
5
6import java.util.*;
7import java.io.*;
8import java.text.*;
9import java.awt.*;
10import java.awt.event.*;
11import javax.swing.*;
12import gnu.gettext.*;
13
14public class Hello {
15  public static void main (String[] args) {
16    ResourceBundle catalog = ResourceBundle.getBundle("hello-java-swing");
17    JFrame frame = new JFrame("Hello example");
18    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
19    JLabel label1 =
20      new JLabel(GettextResource.gettext(catalog,"Hello, world!"));
21    JLabel label2 =
22      new JLabel(
23          MessageFormat.format(
24              GettextResource.gettext(catalog,
25                  "This program is running as process number {0}."),
26              new Object[] { getPid() }));
27    JButton button = new JButton("OK");
28    button.addActionListener(
29        new ActionListener() {
30          public void actionPerformed (ActionEvent event) {
31            System.exit(0);
32          }
33        });
34    JPanel labels = new JPanel();
35    labels.setLayout(new GridLayout(2, 1));
36    labels.add(label1);
37    labels.add(label2);
38    JPanel buttons = new JPanel();
39    buttons.setLayout(new FlowLayout(FlowLayout.RIGHT));
40    buttons.add(button);
41    frame.getContentPane().setLayout(new BorderLayout());
42    frame.getContentPane().add(labels, BorderLayout.CENTER);
43    frame.getContentPane().add(buttons, BorderLayout.SOUTH);
44    frame.pack();
45    frame.setVisible(true);
46  }
47
48  /* Return the process ID of the current process.  */
49  private static String getPid () {
50    try {
51      String[] args = new String[] { "/bin/sh", "-c", "echo $PPID" };
52      Process p = Runtime.getRuntime().exec(args);
53      InputStream p_out = p.getInputStream();
54      String s = (new BufferedReader(new InputStreamReader(p_out))).readLine();
55      p.destroy();
56      if (s != null)
57        return s;
58    } catch (IOException e) {
59      e.printStackTrace();
60    }
61    return "???";
62  }
63}
64