本文實例為大家分享了Java Swing仿QQ登錄界面展示的具體代碼,供大家參考,具體內容如下
閑來無事將早些時候已實現的QQ登錄界面再實現了一遍,純手工打造(意思是沒有用NetBeans、MyEclipse的拖動功能)。
源代碼如下:
package ibees.qq; import java.awt.BorderLayout; import java.net.URL; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JPasswordField; import javax.swing.JTextField; /** * 仿QQ登錄界面,僅供學習參考,涉及到的有窗口居中、JPanel、LayoutManager的使用 * @author hhzxj2008 * */ public class QQLoginView extends JFrame { /** * */ private static final long serialVersionUID = -5665975170821790753L; public QQLoginView() { initComponent(); } private void initComponent() { setTitle("用戶登錄"); //設置LOGO URL image = QQLoginView.class.getClassLoader().getResource("ibees/qq/images/year.jpg");//圖片的位置 JLabel imageLogo = new JLabel(new ImageIcon(image)); add(imageLogo,BorderLayout.NORTH); //QQ號和密碼 JPanel jp = new JPanel(); JPanel jpAccount = new JPanel(); jpAccount.add(new JLabel("帳號")); JTextField userTextField = new JTextField(15); jpAccount.add(userTextField); jpAccount.add(new JLabel("用戶注冊")); jp.add(jpAccount); JPanel jpPass = new JPanel(); jpPass.add(new JLabel("密碼")); JPasswordField passTextField = new JPasswordField(15); jpPass.add(passTextField); jpPass.add(new JLabel("找回密碼")); jp.add(jpPass); //登錄設置 JPanel jpstatus = new JPanel(); jpstatus.add(new JLabel("狀態")); JComboBox statusComboBox = new JComboBox(); statusComboBox.addItem("Q我"); statusComboBox.addItem("在線"); statusComboBox.addItem("隱身"); statusComboBox.addItem("離線"); jpstatus.add(statusComboBox); jpstatus.add(new JCheckBox("記住密碼")); jpstatus.add(new JCheckBox("自動登錄")); jp.add(jpstatus); add(jp); //底部登錄按鈕 JPanel bottomPanel = new JPanel(); bottomPanel.setLayout(new BorderLayout()); bottomPanel.add(new JButton("設置"),BorderLayout.WEST); bottomPanel.add(new JButton("登錄"),BorderLayout.EAST); add(bottomPanel,BorderLayout.SOUTH); setSize(324,230); setDefaultCloseOperation(EXIT_ON_CLOSE); setLocationRelativeTo(null); } /** * @param args */ public static void main(String[] args) { java.awt.EventQueue.invokeLater(new Runnable(){ @Override public void run() { new QQLoginView().setVisible(true); } }); } }
效果:
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VeVb武林網。
新聞熱點
疑難解答
圖片精選