⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 statusbar.java

📁 非常好的java事例以及带源码事例的java2教程
💻 JAVA
字号:
// Class defining a status bar
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;

class StatusBar extends JPanel
                implements Constants
{
  // Constructor
  public StatusBar()
  {
    setLayout(new FlowLayout(FlowLayout.LEFT, 10, 3));
    setBackground(Color.lightGray);
    setBorder(BorderFactory.createLineBorder(Color.darkGray));
    setColorPane(DEFAULT_ELEMENT_COLOR);
    setTypePane(DEFAULT_ELEMENT_TYPE);
    add(colorPane);                      // Add color pane to status bar
    add(typePane);                       // Add type pane to status bar
  }

  // Set color pane label
  public void setColorPane(Color color)
  {
    String text;                              // Text for the color pane
    if(color.equals(Color.red)) 
      text = "RED";
    else if(color.equals(Color.yellow))
      text = "YELLOW";
    else if(color.equals(Color.green))
      text = "GREEN";
    else if(color.equals(Color.blue))
      text = "BLUE";
    else
      text = "CUSTOM COLOR";
    colorPane.setForeground(color);
    colorPane.setText(text);                // Set the pane text
  }

  // Set type pane label
  public void setTypePane(int elementType)
  { 
    String text;       // Text for the type pane
    switch(elementType)
    {
      case LINE:
        text = "LINE";
        break;
      case RECTANGLE:
        text = "RECTANGLE";
        break;
      case CIRCLE:
        text = "CIRCLE";
        break;
      case CURVE:
        text = "CURVE";
        break;
      default:
        text = "ERROR";
        break;
      case TEXT:
        text = "TEXT";
        break;

    }
    typePane.setText(text);  // Set the pane text
  }

  // Panes in the status bar
  private StatusPane colorPane = new StatusPane("BLUE");
  private StatusPane typePane = new StatusPane("LINE");

  // Class defining a status bar pane
  class StatusPane extends JLabel
  {
    public StatusPane(String text)
    {
      setBackground(Color.lightGray);      // Set background color
      setForeground(Color.black);
      setFont(paneFont);                   // Set the fixed font
      setHorizontalAlignment(CENTER);      // Center the pane text 
      setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
      setPreferredSize(new Dimension(100,20));
      setText(text);                       // Set the text in the pane
    }

    // Font for pane text
    private Font paneFont = new Font("Serif", Font.PLAIN, 10);
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -