📄 messagetip.java
字号:
package smoker.tools;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import smoker.client.*;
public class MessageTip extends JWindow implements ActionListener {
private static final long serialVersionUID = 1L;
private JLabel labSeeMsg;
private JLabel labUser;
private User user;
private JButton btnClose;
private IUserListManager iUserListManager;
public MessageTip(IUserListManager iUserListManager, User user) {
this.iUserListManager = iUserListManager;
this.user = user;
this.setSize(200, 150);
this.setBackground(new Color(218, 243, 253));
this.setAlwaysOnTop(true);
init();
GUIManager.rightBottomWindow(this);
}
private void init() {
JPanel container = (JPanel) this.getContentPane();
container.setLayout(new BoxLayout(container, BoxLayout.Y_AXIS));
Border bor = BorderFactory.createLineBorder(Color.gray);
TitledBorder title = BorderFactory.createTitledBorder(bor, "发现新消息",
TitledBorder.CENTER, TitledBorder.BELOW_TOP);
container.setBorder(title);
labSeeMsg = new JLabel("阅读消息");
labUser = new JLabel("来自【 " + user.getNickName() + " 】的消息!",
JLabel.CENTER);
btnClose = new JButton("关闭");
btnClose.addActionListener(this);
btnClose.setActionCommand("Close");
btnClose.setBorderPainted(false);
JPanel userPane = new JPanel();
userPane.setLayout(new BoxLayout(userPane, BoxLayout.X_AXIS));
userPane.add(Box.createHorizontalStrut(5));
userPane.add(labUser);
JPanel seePane = new JPanel();
seePane.setLayout(new BoxLayout(seePane, BoxLayout.X_AXIS));
seePane.add(Box.createHorizontalStrut(5));
seePane.add(labSeeMsg);
JPanel btnPane = new JPanel();
btnPane.setLayout(new BoxLayout(btnPane, BoxLayout.X_AXIS));
btnPane.add(Box.createHorizontalStrut(125));
btnPane.add(btnClose);
container.add(Box.createVerticalStrut(20));
container.add(userPane);
container.add(Box.createVerticalStrut(10));
container.add(seePane);
container.add(Box.createVerticalStrut(25));
container.add(btnPane);
labSeeMsg.addMouseListener(new MouseAdapter() {
private Font font = new Font("Default", Font.ITALIC, 12);;
Font defaultFont = labSeeMsg.getFont();
Color defaultForeColor = labSeeMsg.getForeground();
public void mouseClicked(MouseEvent e) {
if(e.getButton() != MouseEvent.BUTTON1) {
return;
}
iUserListManager.openChatGui(user);
dispose();
}
public void mouseEntered(MouseEvent e) {
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
labSeeMsg.setFont(font);
labSeeMsg.setForeground(Color.BLUE);
}
public void mouseExited(MouseEvent e) {
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
labSeeMsg.setFont(defaultFont);
labSeeMsg.setForeground(defaultForeColor);
}
});
}
public void actionPerformed(ActionEvent e) {
String command = e.getActionCommand();
if (command.equals("Close")) {
dispose();
}
}
// public static void main(String[] args) {
// User u = new User();
// u.setNickName("测试用户");
// new MessageTip(u).setVisible(true);
// }
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -