metalthememenu.java
来自「这是用elipes平台开发的java编程实例,数据库用access .若想用el」· Java 代码 · 共 56 行
JAVA
56 行
package lib;
import javax.swing.plaf.metal.*;
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;
public class MetalThemeMenu extends JMenu implements ActionListener {
MetalTheme[] themes; //Program's Themes Array.
//Constructor of Class.
public MetalThemeMenu (String name, MetalTheme[] themeArray) {
super (name); //Setting the Theme Menu Name.
themes = themeArray;
ButtonGroup group = new ButtonGroup (); //Creating the Themes Group.
for (int i = 0; i < themes.length; i++) { //Creating the Themes Menu.
//Creating the Themes Radio Button by Getting their own Name.
JRadioButtonMenuItem item;
if( i != 0)
item = new JRadioButtonMenuItem (themes[i].getName());
else
item = new JRadioButtonMenuItem ("金属色");
group.add (item); //Adding theme into Group.
add (item);
item.setActionCommand (i + ""); //Setting the ActionCommand.
item.addActionListener (this); //Setting the theme's Action.
if ( i == 0)
item.setSelected (true); //Setting the theme's Selection.
}
}
//Action Performed by the Theme Menu.
public void actionPerformed (ActionEvent e) {
String numStr = e.getActionCommand (); //Getting the Action Command.
MetalTheme selectedTheme = themes [ Integer.parseInt (numStr) ]; //Converting the String into Integer.
MetalLookAndFeel.setCurrentTheme (selectedTheme); //Getting the Selected theme.
try { //Setting the Program's Look.
UIManager.setLookAndFeel ("javax.swing.plaf.metal.MetalLookAndFeel");
}
catch (Exception ex) { }
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?