📄 configureframe.java
字号:
package source;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JOptionPane;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.ImageIcon;
import javax.swing.JColorChooser;
import javax.swing.UIManager;
import javax.swing.colorchooser.DefaultColorSelectionModel;
import java.awt.Color;
import java.awt.Image;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseAdapter;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.io.File;
//配置系统界面
class ConfigureFrame extends JFrame
{
//默认颜色风格
final static Color DEF_backColor = new Color(230, 255, 240);
final static Color DEF_foreColor = new Color(0, 0, 0);
final static Color DEF_selectColor = new Color(11,181,255);
final static Color DEF_menuColor = new Color(181,181,255);
final static Color DEF_conBackColor = new Color(255,255,255);
final static Color DEF_conForeColor = new Color(0, 0, 0);
final static Color DEF_conSelColor = new Color(11,181,255);
//自定义颜色风格
Color backColor = DEF_backColor;
Color foreColor = DEF_foreColor;
Color selectColor = DEF_selectColor;
Color menuColor = DEF_menuColor;
Color conBackColor = DEF_conBackColor;
Color conForeColor = DEF_conForeColor;
Color conSelColor = DEF_conSelColor;
//内容面板
JPanel contentPane = null;
JPanel labelPane = null;
JPanel buttonPane = null;
//标签
JLabel backGround = null;
JLabel backSample = null;
JLabel foreGround = null;
JLabel foreSample = null;
JLabel selectGround = null;
JLabel selectSample = null;
JLabel menuGround = null;
JLabel menuSample = null;
JLabel conBackground = null;
JLabel conForeground = null;
JLabel conSelect = null;
JLabel conBackSample = null;
JLabel conForeSample = null;
JLabel conSelSample = null;
//按钮
JButton OK_Button = null;
JButton NO_Button = null;
JButton DEF_Button = null;
public ConfigureFrame()
{
try
{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(Exception e)
{
JOptionPane.showMessageDialog(ConfigureFrame.this,
e.toString() + ":\n运行时错误!",
"出错啦!", JOptionPane.INFORMATION_MESSAGE);
}
//内容面板
labelPane = new JPanel();
JPanel buttonPane = new JPanel();
//标签
backGround = new JLabel("设置窗口背景颜色");
conBackground = new JLabel("设置控制台背景色");
backSample = new JLabel("窗口背景颜色预览");
foreGround = new JLabel("设置编辑文本颜色");
conForeground = new JLabel("设置控制台前景色");
foreSample = new JLabel("编辑文本颜色预览");
selectGround = new JLabel("设置选择文本颜色");
conSelect = new JLabel("设置控制台选择色");
conBackSample = new JLabel("控制台背景色预览");
conForeSample = new JLabel("控制台前景色预览");
conSelSample = new JLabel("控制台选择色预览");
selectSample = new JLabel("选择文本颜色预览");
menuGround = new JLabel("设置菜单栏目颜色");
menuSample = new JLabel("菜单栏目颜色预览");
//按钮
OK_Button = new JButton("确定");
NO_Button = new JButton("取消");
DEF_Button = new JButton("默认");
//框架设置
setTitle("CoffeeEditor系统配置");
ImageIcon icon=new ImageIcon("source" + File.separator + "gefeng.jpg");
Image image=icon.getImage();
setIconImage(image);
setSize(260, 200);
setResizable(false);
labelPane.setLayout(new GridLayout(7, 2, 50, 5));
buttonPane.setLayout(new FlowLayout());
contentPane = (JPanel) this.getContentPane();
//框架颜色风格设置
contentPane.setBackground(Color.WHITE);
labelPane.setBackground(Color.WHITE);
buttonPane.setBackground(Color.WHITE);
backSample.setForeground(this.backColor);
foreSample.setForeground(this.foreColor);
selectSample.setForeground(this.selectColor);
conBackSample.setForeground(this.conBackColor);
conForeSample.setForeground(this.conForeColor);
conSelSample.setForeground(this.conSelColor);
menuSample.setForeground(this.menuColor);
//关闭设置窗口
addWindowListener(new WindowAdapter()
{
public void WindowClosing(WindowEvent e)
{
setVisible(false);
}
});
//背景颜色设置
backGround.addMouseListener(new MouseAdapter()
{
public void mouseReleased(MouseEvent e)
{
backColor = JColorChooser.showDialog(backGround,
"ColorChooser", DEF_backColor);
backSample.setForeground(backColor);
}
});
//前景颜色设置
foreGround.addMouseListener(new MouseAdapter()
{
public void mouseReleased(MouseEvent e)
{
foreColor = JColorChooser.showDialog(foreGround,
"ColorChooser", DEF_foreColor);
foreSample.setForeground(foreColor);
}
});
//选择颜色设置
selectGround.addMouseListener(new MouseAdapter()
{
public void mouseReleased(MouseEvent e)
{
selectColor = JColorChooser.showDialog(selectGround,
"ColorChooser", DEF_selectColor);
selectSample.setForeground(selectColor);
}
});
//菜单栏背景颜色
menuGround.addMouseListener(new MouseAdapter()
{
public void mouseReleased(MouseEvent e)
{
menuColor = JColorChooser.showDialog(menuGround,
"ColorChooser", DEF_menuColor);
menuSample.setForeground(menuColor);
}
});
//控制台背景颜色
conBackground.addMouseListener(new MouseAdapter()
{
public void mouseReleased(MouseEvent e)
{
conBackColor = JColorChooser.showDialog(conBackground,
"ColorChooser", DEF_conBackColor);
conBackSample.setForeground(conBackColor);
}
});
//控制前背景颜色
conForeground.addMouseListener(new MouseAdapter()
{
public void mouseReleased(MouseEvent e)
{
conForeColor = JColorChooser.showDialog(conForeground,
"ColorChooser", DEF_conForeColor);
conForeSample.setForeground(conForeColor);
}
});
//控制选择字体颜色
conSelect.addMouseListener(new MouseAdapter()
{
public void mouseReleased(MouseEvent e)
{
conSelColor = JColorChooser.showDialog(conSelect,
"ColorChooser", DEF_conSelColor);
conSelSample.setForeground(conSelColor);
}
});
//容器添加控件
labelPane.add(backGround);
labelPane.add(backSample);
labelPane.add(foreGround);
labelPane.add(foreSample);
labelPane.add(selectGround);
labelPane.add(selectSample);
labelPane.add(menuGround);
labelPane.add(menuSample);
labelPane.add(conBackground);
labelPane.add(conBackSample);
labelPane.add(conForeground);
labelPane.add(conForeSample);
labelPane.add(conSelect);
labelPane.add(conSelSample);
buttonPane.add(OK_Button);
buttonPane.add(NO_Button);
buttonPane.add(DEF_Button);
contentPane.add(labelPane, "Center");
contentPane.add(buttonPane, "South");
setVisible(false);
}
//系统风格转换,回调方法
public void systemStyleChange(final Notepad notepad)
{
//确定提交按钮
OK_Button.addMouseListener(new MouseAdapter()
{
public void mouseReleased(MouseEvent e)
{
notepad.jta.setBackground(backColor);
notepad.jta.setForeground(foreColor);
notepad.jta.setSelectionColor(selectColor);
notepad.menuBar.setBackground(menuColor);
notepad.fileMenu.setBackground(menuColor);
notepad.editMenu.setBackground(menuColor);
notepad.toolsMenu.setBackground(menuColor);
notepad.advancedMenu.setBackground(menuColor);
notepad.csta.setBackground(conBackColor);
notepad.csta.setForeground(conForeColor);
notepad.csta.setSelectionColor(conSelColor);
setVisible(false);
}
});
//取消按钮
NO_Button.addMouseListener(new MouseAdapter()
{
public void mouseReleased(MouseEvent e)
{
setVisible(false);
}
});
//恢复默认按钮
DEF_Button.addMouseListener(new MouseAdapter()
{
public void mouseReleased(MouseEvent e)
{
notepad.jta.setBackground(DEF_backColor);
notepad.jta.setForeground(DEF_foreColor);
notepad.jta.setSelectionColor(DEF_selectColor);
notepad.menuBar.setBackground(DEF_menuColor);
notepad.fileMenu.setBackground(DEF_menuColor);
notepad.editMenu.setBackground(DEF_menuColor);
notepad.toolsMenu.setBackground(DEF_menuColor);
notepad.advancedMenu.setBackground(DEF_menuColor);
notepad.csta.setBackground(DEF_conBackColor);
notepad.csta.setForeground(DEF_conForeColor);
notepad.csta.setSelectionColor(DEF_conSelColor);
setVisible(false);
}
});
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -