package com.ogane.xi.test; import java.awt.*; import java.awt.event.*; import com.ogane.xi.FlipedLabel; public class FlipedLabelTest extends Frame implements ActionListener { static final String TEXT_EN = "Welcome to Java world!"; static final String TEXT_JA = "ようこそJavaの世界へ!"; static final String FONT1 = "Serif"; static final String FONT2 = "SansSerif"; static final String FONT3 = "Monospaced"; static final String SMALL = "12"; static final String MIDIUM = "16"; static final String LARGE = "20"; FlipedLabel label_0; FlipedLabel label_90; FlipedLabel label_180; FlipedLabel label_270; String font_name = FONT1; int font_style = Font.PLAIN; int font_size = Integer.valueOf(LARGE).intValue(); public FlipedLabelTest() { enableEvents(AWTEvent.WINDOW_EVENT_MASK); setTitle("FlipedLabelTest"); setLayout(new BorderLayout()); setBackground(new Color(220, 211, 200)); // --- 反時計方向に0度回転 --- label_0 = new FlipedLabel(TEXT_EN, FlipedLabel.DEGREE_0); add(BorderLayout.NORTH, label_0); // --- 反時計方向に90度回転 --- label_90 = new FlipedLabel(TEXT_EN, FlipedLabel.DEGREE_90); add(BorderLayout.WEST, label_90); // --- 反時計方向に180度回転 --- label_180 = new FlipedLabel(TEXT_EN, FlipedLabel.DEGREE_180); add(BorderLayout.SOUTH, label_180); // --- 反時計方向に270度回転 --- label_270 = new FlipedLabel(TEXT_EN, FlipedLabel.DEGREE_270); add(BorderLayout.EAST, label_270); // ボタン Panel buttons = new Panel(); buttons.setLayout(new GridLayout(0, 3)); add(BorderLayout.CENTER, buttons); addButton("English", buttons); addButton("日本語", buttons); addButton("", buttons); addButton("Left", buttons); addButton("Center", buttons); addButton("Right", buttons); addButton("Red", buttons); addButton("Green", buttons); addButton("Blue", buttons); addButton(FONT1, buttons); addButton(FONT2, buttons); addButton(FONT3, buttons); addButton("Plain", buttons); addButton("Italic", buttons); addButton("Bold", buttons); addButton(SMALL, buttons); addButton(MIDIUM, buttons); addButton(LARGE, buttons); setLabelFont(font_name, font_style, font_size); pack(); validate(); setSize(280, 300); setVisible(true); } void addButton(String label, Container parent) { Button btn = new Button(label); btn.addActionListener(this); parent.add(btn); } public void actionPerformed(ActionEvent ev) { String label = ((Button)ev.getSource()).getLabel(); //---- Label Text ---- if(label.equals("English")) { setLabelText(TEXT_EN); return; } if(label.equals("日本語")) { setLabelText(TEXT_JA); return; } //---- Label Alignment ---- if(label.equals("Left")) setLabelAlignment(FlipedLabel.LEFT); if(label.equals("Center")) setLabelAlignment(FlipedLabel.CENTER); if(label.equals("Right")) setLabelAlignment(FlipedLabel.RIGHT); //---- Background Color ---- if(label.equals("")) setLabelBackground(new Color(220, 211, 200)); if(label.equals("Red")) setLabelBackground(Color.red); if(label.equals("Green")) setLabelBackground(Color.green); if(label.equals("Blue")) setLabelBackground(new Color(180, 180, 255)); //---- Font ---- if(label.equals(FONT1) || label.equals(FONT2) || label.equals(FONT3)) { font_name=label; setLabelFont(font_name, font_style,font_size); } if(label.equals("Plain") || label.equals("Italic") || label.equals("Bold")) { if(label.equals("Plain")) font_style = Font.PLAIN; if(label.equals("Italic")) font_style = Font.ITALIC; if(label.equals("Bold")) font_style = Font.BOLD; setLabelFont(font_name, font_style,font_size); } if(label.equals(SMALL) || label.equals(MIDIUM) || label.equals(LARGE)) { font_size=Integer.valueOf(label).intValue(); setLabelFont(font_name, font_style, font_size); } } void setLabelText(String txt) { label_0.setText(txt); label_90.setText(txt); label_180.setText(txt); label_270.setText(txt); } void setLabelFont(String name, int style, int size) { Font font = new Font(name, style, size); label_0.setFont(font); label_90.setFont(font); label_180.setFont(font); label_270.setFont(font); } void setLabelBackground(Color color) { label_0.setBackground(color); label_90.setBackground(color); label_180.setBackground(color); label_270.setBackground(color); } void setLabelAlignment(int align) { label_0.setAlignment(align); label_90.setAlignment(align); label_180.setAlignment(align); label_270.setAlignment(align); } protected void processWindowEvent(WindowEvent e) { super.processWindowEvent(e); if (e.getID() == WindowEvent.WINDOW_CLOSING) { System.exit(0); } } public static void main(String[] args) { new FlipedLabelTest(); } }