📄 qqfontchooser.java
字号:
//聊天字体选择面板
package myQQ;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.colorchooser.*;
class QQFontChooser extends QQPanel implements ActionListener
{
//字形下拉列表
JComboBox style;
//字号下拉列表
String[] sSize = {"8","9","10","11","12","14","16","18","20","22","24","26","30","36","48","72"};
JComboBox size = new JComboBox(sSize);
//其它按钮
QQButton[] other = new QQButton[3];
ImageIcon[] icP = new ImageIcon[3];
String[] sOther = {"粗体","斜体","文字颜色"};
//聊天输入面板
QQTextPane chatIn = null;
QQFontChooser(QQTextPane chatIn)
{
super(0,"chat/p1");
this.setLayout(null);
this.chatIn = chatIn; //传入聊天输入面板以随时改变字体
//取得当前环境所有字体
GraphicsEnvironment gm = GraphicsEnvironment.getLocalGraphicsEnvironment();
String[] sf = gm.getAvailableFontFamilyNames();
//构建及添加组件
style = new JComboBox(sf);
style.addActionListener(this);
style.setBounds(10,5,100,20);
this.add(style);
size.addActionListener(this);
size.setBounds(120,5,50,20);
this.add(size);
for (int i = 0; i<other.length; i++)
{
icP[i] = new ImageIcon("QQ/skin/chat/f"+i+".png");
other[i] = new QQButton(icP[i],Color.BLUE,sOther[i]);
other[i].addActionListener(this);
other[i].setBounds(180+i*30,5,20,20);
this.add(other[i]);
}
}
public void actionPerformed(ActionEvent e)
{ //字体改变事件
if(e.getSource().equals(other[0]))
{ //设置字体是否为粗体
chatIn.setFontBold(!other[0].click);
}
if(e.getSource().equals(other[1]))
{ //设置字体是否为斜体
chatIn.setFontItalic(!other[1].click);
}
if(e.getSource().equals(other[2]))
{ //设置字体颜色
JColorChooser cch = new JColorChooser();
Color c = cch.showDialog(this,"选择颜色",chatIn.cOld);
if(c==null)
c = chatIn.cOld;
chatIn.setFontColor(c);
}
if(e.getSource().equals(style))
{ //设置字形
String s = (String)style.getSelectedItem();
chatIn.setFontStyle(s);
}
if(e.getSource().equals(size))
{ //设置字号
String s = (String)size.getSelectedItem();
int i = size.getSelectedIndex();
chatIn.setFontSize(s);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -