📄 inchatui.java
字号:
package clientele;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Rectangle;
import java.awt.SystemColor;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.ScrollPaneConstants;
import javax.swing.UIManager;
public class InchatUI
{
/**
* 文本域:聊天输入
*/
JTextArea jTextArea2 = null;
/**
* 关闭按钮
*/
JButton jButton1 = null;
/**
*密送按钮
*/
JButton jButton3 = null;
/**
* 窗体
*/
JFrame jFrame = null;// 窗体
/**
* 添加按钮等
*/
JPanel jPanel = null;
/**
* 聊天发送者号码
*/
int souceid = 0;// 聊天发送者
/**
* 聊天接收者号码
*/
int destid = 0;// 聊天目标
/**
* 添加文本区
*/
JScrollPane jScrollPane2 = null;
/**
* 构造函数
*/
public InchatUI(int souceid, int destid)
{
this.souceid = souceid;
this.destid = destid;
}
/**
* 此方法初始化
*/
public JFrame getJFrame()
{
if (jFrame == null)
{
jFrame = new JFrame();
jFrame.setBackground(SystemColor.inactiveCaption);
jFrame.setSize(460, 190);
jFrame.setContentPane(getJPanel());
Toolkit toolkit = jFrame.getToolkit();
Dimension screen = toolkit.getScreenSize();
jFrame.setIconImage(Toolkit.getDefaultToolkit().getImage(
getClass().getResource("/picture/client.jpg")));
jFrame.setBounds(screen.width / 2 - 460 / 2,
screen.height / 2 - 350 / 2, 360, 199);// //让窗体在屏幕正中央显示
jFrame.setVisible(true);
jFrame.setResizable(false);
jFrame.getRootPane().setDefaultButton(jButton3);
jFrame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e)
{
jFrame.dispose();// 隐藏窗体
}
});
}
return jFrame;
}
/**
* 此方法初始化jPanel
*/
public JPanel getJPanel()
{
if (jPanel == null)
{
jPanel = new JPanel();
jPanel.setBackground(new Color(153, 153, 255));
jPanel.setLayout(null);
}
if (jTextArea2 == null)
{
jTextArea2 = new JTextArea();
jTextArea2.setFocusCycleRoot(true);
}
if (jButton1 == null)
{
jButton1 = new JButton();
jButton1.setBackground(UIManager.getColor("Button.shadow"));
jButton1.setFont(new Font("", Font.PLAIN, 14));
}
if (jButton3 == null)
{
jButton3 = new JButton();
}
if (jScrollPane2 == null)
{
jScrollPane2 = new JScrollPane();
}
jScrollPane2.setBounds(10, 22, 334, 78);
jScrollPane2.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
jScrollPane2.getViewport().add(jTextArea2);
jTextArea2.setFocusCycleRoot(true);
jTextArea2.setFont(new Font("宋体", Font.PLAIN, 15));
jTextArea2.setBorder(BorderFactory.createLineBorder(Color.black));
jTextArea2.setLineWrap(true);
jButton1.setBounds(new Rectangle(230, 119, 91, 24));
jButton1.setForeground(SystemColor.menuText);
jButton1.setText("关闭");
jButton3.setForeground(SystemColor.menuText);
jButton3.setFont(new Font("Dialog", Font.PLAIN, 14));
jButton3.setText("企业消息(S)");
jButton3.setBounds(29, 119, 109, 24);
jButton3.setMnemonic('S');
/**
* 关闭按钮行为事件监听
*/
jButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == jButton1)
jFrame.dispose();// 隐藏窗体
}
});
/**
* 密送按钮行为监听
*/
jButton3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == jButton3)
{
String imsg = Client.getTime() + " 用户"
+ String.valueOf(souceid) + "给你的消息:\n"
+ jTextArea2.getText() + "\n";
jTextArea2.setText("");// 清空
Client.client.sendIMsg(imsg, souceid, destid);// 执行Client的sendIMsg()方法
jFrame.dispose();
}
}
});
jPanel.setEnabled(true);
jPanel.add(jButton1);
jPanel.add(jButton3);
jPanel.add(jScrollPane2);
return jPanel;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -