| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1090 人关注过本帖
标题:谁帮忙看一下为什么没用啊mouseClicked
取消只看楼主 加入收藏
a892502843
Rank: 1
等 级:新手上路
帖 子:17
专家分:4
注 册:2016-5-24
结帖率:50%
收藏
 问题点数:0 回复次数:0 
谁帮忙看一下为什么没用啊mouseClicked
程序代码:
package com.library.mainFrame;

import java.awt.*;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.JPanel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import com.library.bean.*;
import com.library.Dao.*;

public class login extends JFrame implements MouseListener
{

    private JFrame frame;
    private JTextField userName;
    private JTextField passWord;
    private static final long serialVersionUID = 1L;
    private static final String TIP = "用户名/手机/邮箱";
    private JPanel panel;

    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    login window = new login();
                    window.frame.setVisible(true);
                    window.frame.setLocationRelativeTo(null);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the application.
     */
    public login() {
        initialize();
    }

    /**
     * Initialize the contents of the frame.
     */
    private void initialize() {
        frame = new JFrame();
        frame.setIconImage(Toolkit.getDefaultToolkit().getImage(login.class.getResource("/com/library/images/IconImage.jpg")));
        frame.setTitle("图书管理系统");
        frame.setResizable(false);
        frame.setBounds(100, 100, 793, 598);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().setLayout(null);
        
        JButton login_button = new JButton("");
        login_button.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                User user;
                UserDao userDao;
                userDao=new  UserDao();
                user=userDao.getUser(userName.getText(),passWord.getText());
                if(user.getUserName()!=null)
                {
                    try{
                    //mainFrame mainframe=new mainFrame();
                    //mainframe.setVisible(true);
                    frame.setVisible(false);
                    }catch(Exception ex){
                        ex.printStackTrace();
                    }
                }else{
                    JOptionPane.showMessageDialog(null, "账号或密码错误,请您重新再试!");
                    userName.setText("");
                    passWord.setText("");
                }
            }
        });
        login_button.setIcon(new ImageIcon(login.class.getResource("/com/library/images/loginButton.jpg")));
        login_button.setBounds(504, 286, 50, 51);
        frame.getContentPane().add(login_button);
        
        panel = new JPanel();
        panel.setName("panel");
        panel.setBounds(310, 220, 244, 51);
        frame.getContentPane().add(panel);
        panel.setLayout(null);
        panel.addMouseListener (this);
        
        userName = new JTextField(TIP);
        userName.setBounds(0, 0, 244, 51);
        panel.add(userName);
        userName.setForeground(Color.LIGHT_GRAY);
        userName.setFont(new Font("宋体", Font.PLAIN, 20));
        userName.setName("");
        userName.setToolTipText("");
        userName.setColumns(10);
        userName.addMouseListener(this);

        passWord = new JTextField();
        passWord.setText("密码");
        passWord.setForeground(Color.LIGHT_GRAY);
        passWord.setFont(new Font("宋体", Font.PLAIN, 20));
        passWord.setBounds(310, 286, 193, 51);
        frame.getContentPane().add(passWord);
        passWord.setColumns(10);
        
        JLabel label = new JLabel("");
        label.setIcon(new ImageIcon(login.class.getResource("/com/library/images/login.jpg")));
        label.setBounds(0, 0, 793, 571);
        frame.getContentPane().add(label);
    }
    @Override
      public void mouseClicked ( MouseEvent e )
        {
            Component component = e.getComponent ();
            String name = component.getName ();
            if (e.getButton () == MouseEvent.BUTTON1)
            {
                if ("userName".equals (name))
                {
                    JTextField userName = (JTextField) component;
                    if (TIP.equals (userName.getText ()))
                    {
                        userName.setText ("");
                    }
                }
                else if ("panel".equals (name))
                {
                    JTextField userName = (JTextField) ( (JPanel) component ).getComponents ()[0];
                    if ("".equals (userName.getText ()))
                    {
                        userName.setText (TIP);
                    }
                }
            }
        }
      @Override
        public void mousePressed ( MouseEvent e )
        {}
     
        @Override
        public void mouseReleased ( MouseEvent e )
        {}
     
        @Override
        public void mouseEntered ( MouseEvent e )
        {}
     
        @Override
        public void mouseExited ( MouseEvent e )
        {}

    
}
图片附件: 游客没有浏览图片的权限,请 登录注册
用户名不消失
搜索更多相关主题的帖子: import 
2016-11-22 21:32
快速回复:谁帮忙看一下为什么没用啊mouseClicked
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020177 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved