仿的QQ登录界面:
一、QQ登录界面:
二、实现结果:
背景是黑色的,在上面有些类似流星的飞过,这个是用线程简单实现的,至于流星呢,就是直线+圆的组合。呵.应该是手速问题,截图就截到一个小流星了
三、实现代码:
1.Main:
package Login; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import java.awt.FlowLayout; import java.awt.Font; import java.awt.Graphics; import java.awt.Image; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPasswordField; import javax.swing.JTextField; public class Login_UI extends JFrame{ public static void main(String[] args) { new Login_UI().init(); } private Graphics g; public void init(){ this.setTitle("动态背景测试"); this.setSize(430, 372); this.setResizable(false); this.setDefaultCloseOperation(3); this.setLocationRelativeTo(null); this.setLayout(null); // //设置界面的背景图片. JLabel label1 =new JLabel(); ImageIcon backImg =new ImageIcon("Login_Folder/backimg2.png"); label1.setIcon(backImg); label1.setBounds(0, 0, 430, 150); this.add(label1); //设置图像 JLabel lable2 =new JLabel(); Image backImg2 =new ImageIcon("Login_Folder/QQ图像.png").getImage(); lable2.setIcon(new ImageIcon(backImg2)); lable2.setBounds(42, 193, 80, 80); this.add(lable2); // //设置账号 JTextField userName =new JTextField(); userName.setBounds(133, 193, 193, 30); this.add(userName); JLabel label3 =new JLabel("注册账号:"); label3.setForeground(Color.blue); label3.setBounds(336, 193, 70, 30); this.add(label3); // //添加密码输入框 JPasswordField pwd =new JPasswordField(); pwd.setBounds(133, 222, 193, 30); this.add(pwd); JLabel label4 = new JLabel("找回密码:"); label4.setForeground(Color.blue); label4.setBounds(337, 230, 70, 30); this.add(label4); // //输入框 JCheckBox box1 =new JCheckBox("记住密码"); box1.setBounds(133, 260, 90, 12); this.add(box1); // JCheckBox box2=new JCheckBox("自动登录"); box2.setBounds(261, 260, 90, 12); this.add(box2); // JButton btn =new JButton("登 录"); btn.setBounds(133, 287, 194, 30); this.add(btn); JLabel label5 =new JLabel(); ImageIcon backImg5 =new ImageIcon("Login_Folder/img1.png"); label5.setIcon(backImg5); label5.setBounds(10, 302, 26, 21); this.add(label5); JLabel label6 =new JLabel(); ImageIcon backImg6 =new ImageIcon("Login_Folder/img2.png"); label6.setIcon(backImg6); label6.setBounds(390, 299, 26, 21); this.add(label6); this.setVisible(true); } @Override public void paint(Graphics g) { // TODO Auto-generated method stub super.paint(g); Login_Thread tr= new Login_Thread(g); tr.start(); tr.draw(g); // this.repaint(); } }
2.背景线程:
扫描二维码关注公众号,回复:
821271 查看本文章
package Login; import java.awt.Color; import java.awt.Graphics; import java.util.Random; public class Login_Thread extends Thread{ //定义属性 int x1; int y1; Random rd= new Random(); Graphics g; public Login_Thread(Graphics g){ this.x1 =rd.nextInt(430); this.y1= rd.nextInt(150); this.g=g; } public void move(){ if(x1>=430){ x1=rd.nextInt(430); } if(y1>=150){ y1=rd.nextInt(150); } x1=x1+2; y1=y1+2; } @Override public void run() { // TODO Auto-generated method stub //super.run(); try { move(); Thread.sleep(1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public void draw(Graphics g){ g.setColor(Color.white); g.drawLine(x1, y1, x1+5, y1+5); g.drawOval(x1+5, y1+5, 3, 3); } }
四、分析:
1.想了很久,不过那个背景的企鹅图案和QQ,这个不知道怎么搞到素材
2.就是账号和密码那两个框,我的实现应该有些简单了,之后再想想吧
五、总结:
好久没写界面了,写写也好难,一个布局就搞了很久.