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