Java Reference
In-Depth Information
// create an MenuIntl object, tell it to show up
new
new
MenuIntl
().
setVisible
(
true
true
);
}
/** Construct the object including its GUI */
public
public
MenuIntl
() {
super
super
(
"MenuIntlTest"
);
JMenuItem mi
;
// used in various spots
Container cp
=
getContentPane
();
cp
.
setLayout
(
new
new
FlowLayout
());
JLabel lab
;
cp
.
add
(
lab
=
new
new
JLabel
());
setDefaultCloseOperation
(
EXIT_ON_CLOSE
);
JMenuBar mb
=
new
new
JMenuBar
();
setJMenuBar
(
mb
);
ResourceBundle b
=
ResourceBundle
.
getBundle
(
"i18n.Widgets"
);
String titlebar
;
try
try
{
titlebar
=
b
.
getString
(
"program"
+
".title"
); }
catch
catch
(
MissingResourceException e
) {
titlebar
=
"MenuIntl Demo"
; }
setTitle
(
titlebar
);
String message
;
try
try
{
message
=
b
.
getString
(
"program"
+
".message"
); }
catch
catch
(
MissingResourceException e
) {
message
=
"Welcome to the world of Java"
;
}
lab
.
setText
(
message
);
JMenu fm
=
mkMenu
(
b
,
"file"
);
// In finished code there would be a call to
// mi.addActionListener(...) after *each* of
// these mkMenuItem calls!
fm
.
add
(
mi
=
mkMenuItem
(
b
,
"file"
,
"open"
));
fm
.
add
(
mi
=
mkMenuItem
(
b
,
"file"
,
"new"
));
fm
.
add
(
mi
=
mkMenuItem
(
b
,
"file"
,
"save"
));
fm
.
add
(
mi
=
mkMenuItem
(
b
,
"file"
,
"exit"
));
mi
.
addActionListener
(
new
new
ActionListener
() {
public
public
void
void
actionPerformed
(
ActionEvent e
) {
MenuIntl
.
this
.
setVisible
(
false
false
);
MenuIntl
.
this
.
dispose
();
System
.
exit
(
0
);
}