import java.awt.*;
import java.awt.event.*;
import java.text.*;
import java.util.*;
import javax.swing.*;
import javax.swing.border.TitledBorder;
public class SimpleExample
extends JPanel {
c.setComponentOrientation(o);
if (c
instanceof JMenu) {
int ncomponents = menu.getMenuComponentCount();
for (int i = 0 ; i < ncomponents ; ++i) {
applyComponentOrientation( menu.getMenuComponent(i), o );
}
int ncomponents = container.getComponentCount();
for (int i = 0 ; i < ncomponents ; ++i) {
applyComponentOrientation( container.getComponent(i), o );
}
}
}
private void loadResources() {
try {
mre.printStackTrace();
}
}
private static JFrame getFrame
() {
return frame;
}
public SimpleExample() {
// Load our resource bundle
loadResources();
ge.getAllFonts();
// Setup the fonts
smallFont
= new Font("Bitstream Cyberbit",
Font.
PLAIN,
14);
mediumFont
= new Font("Bitstream Cyberbit",
Font.
PLAIN,
18);
bigFont
= new Font("Bitstream Cyberbit",
Font.
PLAIN,
20);
// Create the buttons
button
= new JButton(resources.
getString("Hello"));
button.setToolTipText(resources.getString("HelloToolTip"));
button.setFont(mediumFont);
// Setup the buttons
oneButton.setFont(mediumFont);
oneButton.setMnemonic(resources.getString("OneMnemonic").charAt(0));
oneButton.
setHorizontalAlignment(JButton.
TRAILING);
oneButton.
setHorizontalTextPosition(JButton.
TRAILING);
twoButton.setFont(mediumFont);
twoButton.setMnemonic(resources.getString("TwoMnemonic").charAt(0));
twoButton.
setHorizontalAlignment(JButton.
TRAILING);
twoButton.
setHorizontalTextPosition(JButton.
TRAILING);
threeButton
= new JRadioButton(resources.
getString("Three"));
threeButton.setFont(mediumFont);
threeButton.setMnemonic(resources.getString("ThreeMnemonic").charAt(0));
threeButton.
setHorizontalAlignment(JButton.
TRAILING);
threeButton.
setHorizontalTextPosition(JButton.
TRAILING);
// Group the radio buttons
group.add(oneButton);
group.add(twoButton);
group.add(threeButton);
// Register a listener for the radio buttons
RadioListener myListener = new RadioListener();
oneButton.addActionListener(myListener);
twoButton.addActionListener(myListener);
threeButton.addActionListener(myListener);
// Setup the button panel
tb.setTitleFont(smallFont);
tb.setTitleJustification(
buttonPanel.setBorder(tb);
buttonPanel.add(button);
buttonPanel.add(oneButton);
buttonPanel.add(twoButton);
buttonPanel.add(threeButton);
// Setup the date panel
tb.setTitleFont(smallFont);
tb.setTitleJustification(
datePanel.setBorder(tb);
months.setFont(mediumFont);
String weekDays
[] = dfs.
getWeekdays();
days.setFont(mediumFont);
// Determine what day is the first day of the week
int firstDayOfWeek = cal.getFirstDayOfWeek();
int dayOfWeek;
for (dayOfWeek = firstDayOfWeek; dayOfWeek < weekDays.length; dayOfWeek++)
days.addItem(weekDays[dayOfWeek]);
for (dayOfWeek = 0; dayOfWeek < firstDayOfWeek; dayOfWeek++)
days.addItem(weekDays[dayOfWeek]);
if (!co.isLeftToRight()) {
datePanel.add(days);
datePanel.add(months);
} else {
datePanel.add(months);
datePanel.add(days);
}
add(datePanel);
// Setup the formatting panel
tb.setTitleFont(smallFont);
tb.setTitleJustification(co.isLeftToRight() ?
formatPanel.setBorder(tb);
double theNumber = 1234.56;
numberLabel.
setForeground(Color.
black);
numberLabel.setFont(bigFont);
JLabel percentLabel
= new JLabel(pFormat.
format(theNumber
));
percentLabel.
setForeground(Color.
black);
percentLabel.setFont(bigFont);
JLabel currencyLabel
= new JLabel(cFormat.
format(theNumber
));
currencyLabel.
setForeground(Color.
black);
currencyLabel.setFont(bigFont);
dateLabel.
setForeground(Color.
black);
dateLabel.setFont(bigFont);
if (co.isLeftToRight()) {
formatPanel.add(numberLabel);
formatPanel.add(percentLabel);
formatPanel.add(currencyLabel);
formatPanel.add(dateLabel);
} else {
formatPanel.add(dateLabel);
formatPanel.add(currencyLabel);
formatPanel.add(percentLabel);
formatPanel.add(numberLabel);
}
add(formatPanel);
}
(JMenu) menuBar.
add(new JMenu(resources.
getString("FileMenu")));
file.setFont(mediumFont);
file.setMnemonic(resources.getString("FileMenuMnemonic").charAt(0));
file.
add(new JMenuItem(resources.
getString("FileMenuExit")));
exitItem.setFont(mediumFont);
exitItem.setMnemonic(resources.getString("FileMenuExitMnemonic").charAt(0));
}
});
menuBar.add(new LocaleChanger());
return menuBar;
}
public void reloadResources() {
try {
mre.printStackTrace();
}
}
/**
* An ActionListener that listens to the radio buttons
*/
String lnfName
= e.
getActionCommand();
Object[] options
= { resources.
getString("OK"), resources.
getString("CANCEL") };
MessageFormat.
format(resources.
getString("WarningMsg"), arguments
),
resources.getString("WarningTitle"),
null, options, options[0]);
try {
button.setEnabled(false);
}
}
}
/**
* A class to change the locale for the application
*/
public LocaleChanger() {
super();
setText(resources.getString("LanguageMenu"));
setFont(mediumFont);
setMnemonic(resources.getString("LanguageMenuMnemonic").charAt(0));
// Sort the language names according to the rules specific to each locale
al.add(resources.getString("Arabic"));
al.add(resources.getString("Chinese"));
al.add(resources.getString("English"));
al.add(resources.getString("German"));
al.add(resources.getString("Italian"));
al.add(resources.getString("French"));
al.add(resources.getString("Hebrew"));
al.add(resources.getString("Japanese"));
al.add(resources.getString("Russian"));
for (int i = 0; i < al.size(); i++) {
mi.setFont(mediumFont);
if (langName.
equalsIgnoreCase((String)al.
get(i
)))
mi.setSelected(true);
mi.addItemListener(this);
langGroup.add(mi);
}
}
if (rb.isSelected()) {
String selected
= rb.
getText();
if (selected.equals(resources.getString("Arabic"))) {
} else if (selected.equals(resources.getString("English"))) {
} else if (selected.equals(resources.getString("German"))) {
} else if (selected.equals(resources.getString("Italian"))) {
} else if (selected.equals(resources.getString("French"))) {
} else if (selected.equals(resources.getString("Hebrew"))) {
} else if (selected.equals(resources.getString("Chinese"))) {
} else if (selected.equals(resources.getString("Japanese"))) {
} else if (selected.equals(resources.getString("Russian"))) {
}
}
SimpleExample panel = new SimpleExample();
SimpleExample.frame.setVisible(false);
SimpleExample.frame.getContentPane().removeAll();
SimpleExample.frame.setJMenuBar(panel.createMenuBar());
SimpleExample.frame.getContentPane().add("Center", panel);
SimpleExample.frame.pack();
SimpleExample.frame.show();
applyComponentOrientation(SimpleExample.getFrame(), co);
}
}
public static void main
(String [] argv
) {
SimpleExample panel = new SimpleExample();
frame
= new JFrame("Simple Example");
});
frame.setJMenuBar(panel.createMenuBar());
frame.getContentPane().add("Center", panel);
frame.pack();
frame.setVisible(true);
}
}
//源代码片段来自云代码http://yuncode.net