1 // Example for use of GNU gettext.
2 // This file is in the public domain.
4 // Source code of the Java/Swing program.
10 import java
.awt
.event
.*;
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
);
20 new JLabel(GettextResource
.gettext(catalog
,"Hello, world!"));
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
) {
34 JPanel labels
= new JPanel();
35 labels
.setLayout(new GridLayout(2, 1));
38 JPanel buttons
= new JPanel();
39 buttons
.setLayout(new FlowLayout(FlowLayout
.RIGHT
));
41 frame
.getContentPane().setLayout(new BorderLayout());
42 frame
.getContentPane().add(labels
, BorderLayout
.CENTER
);
43 frame
.getContentPane().add(buttons
, BorderLayout
.SOUTH
);
45 frame
.setVisible(true);
48 /* Return the process ID of the current process. */
49 private static String
getPid () {
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();
58 } catch (IOException e
) {