|
- /*
- * ChineseTest.java
- * July 17, 2001
- *
- * author SuperMMX
- */
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- import java.net.*;
- public class ChineseTest extends JFrame
- {
- public static void main(String[] args)
- {
- ChineseTest frame = new ChineseTest("Test Chinese on Linux box");
- frame.addWindowListener
- (
- new WindowAdapter()
- {
- public void windowClosing(WindowEvent e)
- {
- System.exit(0);
- }
- }
- );
- }
- private int tabCount = 0;
- private JList fonts;
- private JPanel up;
- private JTextArea textArea;
- private JButton refresh;
- public ChineseTest(String s)
- {
- super(s);
- init();
- setSize(400, 600);
- Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
- setLocation(screenSize.width/2 - 200,
- screenSize.height/2 - 150);
- setVisible(true);
- }
- private void init()
- {
- JPanel down;
- GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
-
- getContentPane().setLayout(new BorderLayout());
- up = new JPanel();
- down = new JPanel();
- getContentPane().add(up, BorderLayout.NORTH);
- getContentPane().add(down, BorderLayout.CENTER);
-
- refresh = new JButton("Refresh");
- up.add(refresh);
- fonts = new JList(ge.getAvailableFontFamilyNames());
- fonts.setSize(250, 400);
- JScrollPane listScroller = new JScrollPane(fonts);
- listScroller.setPreferredSize(new Dimension(250,400));
- listScroller.setMinimumSize(new Dimension(250, 400));
- listScroller.setAlignmentX(LEFT_ALIGNMENT);
- up.add(listScroller);
- textArea = new JTextArea("这是中文测试", 5, 20);
- down.add(textArea);
-
- refresh.addMouseListener
- (
- new MouseAdapter()
- {
- public void mouseClicked(MouseEvent e)
- {
- String s = (String)fonts.getSelectedValue();
- Font font = new Font(s, Font.PLAIN, 12);
- textArea.setFont(font);
- }
- }
- );
- }
- }
复制代码 |
|