📄 mespanel.java
字号:
package group;
import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
/**
<code>MesPanel</code>此类是通用的用来显示消息的面板类
@author wls
*/
public class MesPanel extends JPanel
{
private JTextArea textAreaMes; //用于显示信息的文本区域
private TitledBorder titleBorder; //面板的有标题的边界
/**
构造函数,接收一个标题字符串,此标题显示在面板边界中
@param title 标题字符串
@param rowSize 面板中文本区域显示的行数
@param hSize 面板中文本区域显示的列数
*/
public MesPanel(String title, int rowSize, int hSize) //rowSize是行数,hSize是列数
{
textAreaMes = new JTextArea(rowSize, hSize);
textAreaMes.setEditable(false);
textAreaMes.setLineWrap(true); //使文本区域自动换行
textAreaMes.setWrapStyleWord(true); //使文本区域以单词换行
textAreaMes.setFont(new Font("Serif", Font.PLAIN, 14));//设置文本区域的字体
add(new JScrollPane(textAreaMes));
titleBorder = BorderFactory.createTitledBorder(
BorderFactory.createEtchedBorder(EtchedBorder.RAISED,
Color.black, Color.white), title); //创建一个用于面板的3D直线边界
setBorder(titleBorder);
}
/**
用于设置文本区中的文字的字体的方法
*/
public void setTextFont(Font f)
{
textAreaMes.setFont(f);
}
/**
设置文本区中的背景色
*/
public void setBackGroudColor(Color c)
{
textAreaMes.setBackground(c);
}
/**
用于设置面板的标题的字体的方法
*/
public void setTitleFont(Font f)
{
titleBorder.setTitleFont(f);
}
/**
此方法用于更新消息列表
@param mes 保存着消息的字符串数组
*/
public synchronized void updateMes(String[] mes) //此方法用于更新服务器的消消列表
{
String temp = "";
for(int i = 0; i < mes.length; i++)
{
temp += (" " + mes[i] + "\n");
}
textAreaMes.setText(temp);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -