?? statusbar.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;
}
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);
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -