[java]代码库
package imitationQQ;
import java.awt.Toolkit;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.JWindow;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import javax.swing.JWindow;
public class LoginFrame extends JWindow {
private static final long serialVersionUID = 10L;
private boolean flag = false;
public boolean isFlag() {
return flag;
}
public void setFlag(boolean flag) {
this.flag = flag;
}
private JLabel headImge;
private JTextField usernameInput;
private JTextField passwordInput;
private JButton login;
private JButton register;
private int xx;
private int yy;
private boolean isDraging;
public LoginFrame(int x, int y) {
setLocation(null);
}
public LoginFrame() {
setSize(445, 340);//澶у皬
setLocationRelativeTo(null);//灞忓箷涓棿
setVisible(true);//鏄剧ず
//setResizable(false);//涓嶈兘鏀惧ぇ
//setTitle("浠縌Q鑱婂ぉ杞欢");
//setDefaultCloseOperation(EXIT_ON_CLOSE);
setLayout(null);
setIconImage(Toolkit.getDefaultToolkit().createImage("imge/qqTitle.png"));
initComponet();
paintComponents(getGraphics());
paintAll(getGraphics());
addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
requestFocus();
isDraging = true;
xx = e.getX();
yy = e.getY();
}
public void mouseReleased(MouseEvent e) {
isDraging = false;
}
public void mouseEntered(MouseEvent e) {
setFlag(true);// 绐椾綋鍐呴儴鏆傛椂璁剧疆涓轰笉鑳藉彇鑹�
}
});
addMouseMotionListener(new MouseMotionAdapter() {
public void mouseDragged(MouseEvent e) {
if (isDraging) {
int left = getLocation().x;
int top = getLocation().y;
setLocation(left + e.getX() - xx, top + e.getY() - yy);
}
}
});
setVisible(true);
}
public void initComponet() {
headImge=new JLabel(new ImageIcon(Toolkit.getDefaultToolkit().createImage("imge/qqhead.png")));
headImge.setSize(80, 80);
headImge.setLocation(40, 165);
this.add(headImge);
usernameInput= new JTextField();
usernameInput.setSize(200, 30);
usernameInput.setLocation(135, 165);
this.add(usernameInput);
passwordInput= new JPasswordField();
passwordInput.setSize(200, 30);
passwordInput.setLocation(135, 190);
this.add(passwordInput);
login= new JButton("鐧诲綍");
login.setSize(80, 25);
login.setLocation(135,260);
this.add(login);
register= new JButton("娉ㄥ唽");
register.setSize(80, 25);
register.setLocation(255, 260);
this.add(register);
}
public static void main(String[] args) {
LoginFrame i=new LoginFrame();
}
}
初级程序员
by: 云代码会员 发表于:2017-11-11 13:55:14 顶(0) | 踩(0) 回复
等我有了积分来看看
回复评论