package socket;import java.awt.*;
import java.awt.event.*;
import java.io.IOException;import javax.swing.*;public class UserUI extends JFrame implements ActionListener,MouseListener { public boolean notshow = true; private JLabel email = null;
public UserUI() {
super("");
this.setSize(new Dimension(260, 140));
this.setResizable(false);
this.setUndecorated(true);
this.addMouseListener(this);
// this.addMouseListener(new MouseAdapter(){
// public void mouseClicked(MouseEvent e){
// if (e.getSource().equals(email)){
//
// }
// }
// public void mouseEntered(MouseEvent e){
// //notshow = false;
// }
// public void mouseExited(MouseEvent e){
// UserUI.this.setVisible(false);
// //notshow = true;
// }
// });
// this.addMouseMotionListener(new MouseMotionAdapter(){
// public void mouseMoved(MouseEvent e){
//
// }
// });
} public void showUser(User user) {
JPanel main = new JPanel(null);
//main.setLayout(null);
main.setBorder(BorderFactory.createLineBorder(Color.GRAY, 1));
Icon icon = user.getPhoto();
JLabel label = new JLabel();
label.setHorizontalAlignment(SwingConstants.LEFT);
label.setVerticalAlignment(SwingConstants.TOP);
//label.setVerticalTextPosition(SwingConstants.TOP);
//label.setHorizontalTextPosition(SwingConstants.LEFT);
label.setText(user.getAccount());
label.setBounds(5, 5, 140, 105);
JLabel photo = new JLabel();
photo.setIcon(icon);
photo.setBounds(this.getWidth() - icon.getIconWidth() - 5, 5, icon.getIconWidth(), icon.getIconHeight());
main.add(label);
main.add(photo);
//增加分隔线
JButton email = new JButton(user.getEmail());
//email = new JLabel(user.getEmail());
email.setVerticalAlignment(SwingConstants.CENTER);
email.setHorizontalAlignment(SwingConstants.LEFT);
email.setBorderPainted(false);
email.setFocusable(false);
email.setContentAreaFilled(false);
email.setBounds(5, 110, 260, 30);
email.addActionListener(this);
//会覆盖上面的监听
// email.addActionListener(new ActionListener(){
// public void actionPerformed(ActionEvent e){
// JOptionPane.showMessageDialog(null,((JLabel)e.getSource()).getText());
// }
// });
main.add(email);
this.getContentPane().add(main);
//this.pack();
} public void mouseClicked(MouseEvent e) {
//e.getComponent();
if (e.getComponent() == email){
JOptionPane.showMessageDialog(null,email.getText());
}
} public void mousePressed(MouseEvent e) { }
public void mouseReleased(MouseEvent e) { }
public void mouseEntered(MouseEvent e) {
//notshow = false;
} public void mouseExited(MouseEvent e) {
this.setVisible(false);
//notshow = true;
} public void actionPerformed(ActionEvent e) {
String email = ((JLabel) e.getSource()).getText();
if (email != null && !"".equals(email)) {
try {
Runtime.getRuntime().exec("cmd /c start" + " mailto:[email protected]");
} catch (IOException ex) {
System.out.println(ex.getMessage());
}
} }
}主要目的是在这个窗口有鼠标enter就不做处理,当鼠标exit的时候需要设置为不显示。下面的email按钮是调用本地发送邮件,可是在鼠标滑过按钮的时候,窗口就被设置为不可见了。将email改为label就可以,但是触发不了发送邮件啊?其实最理想的就是email用超链接的形式/
import java.awt.event.*;
import java.io.IOException;import javax.swing.*;public class UserUI extends JFrame implements ActionListener,MouseListener { public boolean notshow = true; private JLabel email = null;
public UserUI() {
super("");
this.setSize(new Dimension(260, 140));
this.setResizable(false);
this.setUndecorated(true);
this.addMouseListener(this);
// this.addMouseListener(new MouseAdapter(){
// public void mouseClicked(MouseEvent e){
// if (e.getSource().equals(email)){
//
// }
// }
// public void mouseEntered(MouseEvent e){
// //notshow = false;
// }
// public void mouseExited(MouseEvent e){
// UserUI.this.setVisible(false);
// //notshow = true;
// }
// });
// this.addMouseMotionListener(new MouseMotionAdapter(){
// public void mouseMoved(MouseEvent e){
//
// }
// });
} public void showUser(User user) {
JPanel main = new JPanel(null);
//main.setLayout(null);
main.setBorder(BorderFactory.createLineBorder(Color.GRAY, 1));
Icon icon = user.getPhoto();
JLabel label = new JLabel();
label.setHorizontalAlignment(SwingConstants.LEFT);
label.setVerticalAlignment(SwingConstants.TOP);
//label.setVerticalTextPosition(SwingConstants.TOP);
//label.setHorizontalTextPosition(SwingConstants.LEFT);
label.setText(user.getAccount());
label.setBounds(5, 5, 140, 105);
JLabel photo = new JLabel();
photo.setIcon(icon);
photo.setBounds(this.getWidth() - icon.getIconWidth() - 5, 5, icon.getIconWidth(), icon.getIconHeight());
main.add(label);
main.add(photo);
//增加分隔线
JButton email = new JButton(user.getEmail());
//email = new JLabel(user.getEmail());
email.setVerticalAlignment(SwingConstants.CENTER);
email.setHorizontalAlignment(SwingConstants.LEFT);
email.setBorderPainted(false);
email.setFocusable(false);
email.setContentAreaFilled(false);
email.setBounds(5, 110, 260, 30);
email.addActionListener(this);
//会覆盖上面的监听
// email.addActionListener(new ActionListener(){
// public void actionPerformed(ActionEvent e){
// JOptionPane.showMessageDialog(null,((JLabel)e.getSource()).getText());
// }
// });
main.add(email);
this.getContentPane().add(main);
//this.pack();
} public void mouseClicked(MouseEvent e) {
//e.getComponent();
if (e.getComponent() == email){
JOptionPane.showMessageDialog(null,email.getText());
}
} public void mousePressed(MouseEvent e) { }
public void mouseReleased(MouseEvent e) { }
public void mouseEntered(MouseEvent e) {
//notshow = false;
} public void mouseExited(MouseEvent e) {
this.setVisible(false);
//notshow = true;
} public void actionPerformed(ActionEvent e) {
String email = ((JLabel) e.getSource()).getText();
if (email != null && !"".equals(email)) {
try {
Runtime.getRuntime().exec("cmd /c start" + " mailto:[email protected]");
} catch (IOException ex) {
System.out.println(ex.getMessage());
}
} }
}主要目的是在这个窗口有鼠标enter就不做处理,当鼠标exit的时候需要设置为不显示。下面的email按钮是调用本地发送邮件,可是在鼠标滑过按钮的时候,窗口就被设置为不可见了。将email改为label就可以,但是触发不了发送邮件啊?其实最理想的就是email用超链接的形式/
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货