1 // Example for use of GNU gettext.
2 // Copyright (C) 2003 Free Software Foundation, Inc.
3 // This file is in the public domain.
5 // Source code of the Java/Swing program.
11 import java
.awt
.event
.*;
16 public static void main (String
[] args
) {
17 ResourceBundle catalog
= ResourceBundle
.getBundle("hello-java-swing");
18 JFrame frame
= new JFrame("Hello example");
19 frame
.setDefaultCloseOperation(WindowConstants
.EXIT_ON_CLOSE
);
21 new JLabel(GettextResource
.gettext(catalog
,"Hello, world!"));
25 GettextResource
.gettext(catalog
,
26 "This program is running as process number {0}."),
27 new Object
[] { getPid() }));
28 JButton button
= new JButton("OK");
29 button
.addActionListener(
30 new ActionListener() {
31 public void actionPerformed (ActionEvent event
) {
35 JPanel labels
= new JPanel();
36 labels
.setLayout(new GridLayout(2, 1));
39 JPanel buttons
= new JPanel();
40 buttons
.setLayout(new FlowLayout(FlowLayout
.RIGHT
));
42 frame
.getContentPane().setLayout(new BorderLayout());
43 frame
.getContentPane().add(labels
, BorderLayout
.CENTER
);
44 frame
.getContentPane().add(buttons
, BorderLayout
.SOUTH
);
46 frame
.setVisible(true);
49 /* Return the process ID of the current process. */
50 private static String
getPid () {
52 String
[] args
= new String
[] { "/bin/sh", "-c", "echo $PPID" };
53 Process p
= Runtime
.getRuntime().exec(args
);
54 InputStream p_out
= p
.getInputStream();
55 String s
= (new BufferedReader(new InputStreamReader(p_out
))).readLine();
59 } catch (IOException e
) {