Install gettext-0.18.1.1.tar.gz
[msysgit.git] / mingw / share / doc / gettext / examples / hello-java-swing / Hello.java
blob7bdef7ede433e9da7b712df7bf98668495bbbf9f
1 // Example for use of GNU gettext.
2 // This file is in the public domain.
3 //
4 // Source code of the Java/Swing program.
6 import java.util.*;
7 import java.io.*;
8 import java.text.*;
9 import java.awt.*;
10 import java.awt.event.*;
11 import javax.swing.*;
12 import gnu.gettext.*;
14 public 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);
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);
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();
61 return "???";