changelf.java

来自「JAVA实现的酒店管理系统」· Java 代码 · 共 77 行

JAVA
77
字号
package file1;

/*
 * @Author:黄顺武
 * @Description:窗口风格选择面版
 */

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class ChangeLF extends JPanel implements ActionListener {

	private JFrame frame;
	private JRadioButton windowButton, motifButton, metalButton;
	private JLabel noticeLabel;
	private static ChangeLF lf = new ChangeLF();// 静态变量,避免被重复初始化

	public ChangeLF() {
		ButtonGroup bg = new ButtonGroup();
		windowButton = new JRadioButton("Window");
		motifButton = new JRadioButton("Motif");
		metalButton = new JRadioButton("Metal");
		bg.add(windowButton);
		bg.add(motifButton);
		bg.add(metalButton);
		noticeLabel = new JLabel("请 您 选 择 窗 口 风 格 : ");
		noticeLabel.setFont(new Font(Font.DIALOG, Font.BOLD, 12));
		this.setLayout(new FlowLayout(FlowLayout.CENTER, 10, 2));
		this.add(noticeLabel);
		this.add(windowButton);
		this.add(motifButton);
		this.add(metalButton);
		windowButton.addActionListener(this);
		motifButton.addActionListener(this);
		metalButton.addActionListener(this);
	}

	public void setFrame(JFrame f) {// 设置被设置风格的窗口框架
		this.frame = f;
	}

	public static ChangeLF getChangeLF() {// 返回定义的静态变量
		return lf;
	}

	public void actionPerformed(ActionEvent ae) {
		if (ae.getActionCommand().equalsIgnoreCase("Window")) {
			try {
				UIManager
						.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
				SwingUtilities.updateComponentTreeUI(frame);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		if (ae.getActionCommand().equalsIgnoreCase("Motif")) {
			try {
				UIManager
						.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
				SwingUtilities.updateComponentTreeUI(frame);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		if (ae.getActionCommand().equalsIgnoreCase("Metal")) {
			try {
				UIManager
						.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
				SwingUtilities.updateComponentTreeUI(frame);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
}

⌨️ 快捷键说明

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