zoukankan      html  css  js  c++  java
  • Java图形界面学习---------简易登录界面

    /**
     * @author Administrator
     * Java图形界面学习---------简易登录界面
     * date:2015/10/31
     */
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Font;
    import java.awt.GridLayout;
    
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JPasswordField;
    import javax.swing.JTextField;
    
    
    public class LoginDemo extends JFrame{
    //定义组件
    	JPanel jp1,jp2;
    	JLabel Imjb,Unlb,Pwlb;
    	JTextField jtf;
    	JPasswordField jpw;
    	JButton remJB,LoginJB,cannelJB;
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		LoginDemo lg=new LoginDemo();
    	}
    	//构造方法
    	public LoginDemo(){
    	  //创建组件
    		//上部
    		ImageIcon icon = new ImageIcon("images//Login.jpg");
    		Imjb=new JLabel(icon);
    		Imjb.setOpaque(false); 
    		//中部
    		jp1=new JPanel();
    		jp1.setLayout(new GridLayout(2,1));
    		Unlb=new JLabel("    用户名:");
    		Unlb.setFont(new Font("楷体",Font.PLAIN,18));
    		Unlb.setForeground(Color.BLUE);
    		Pwlb=new JLabel("    密  码:");
    		Pwlb.setFont(new Font("楷体",Font.PLAIN,18));
    		Pwlb.setForeground(Color.BLUE);
    		jtf=new JTextField(10);
    		jpw=new JPasswordField(10);
    		jp1.add(Unlb);
    		jp1.add(jtf);
    		jp1.add(Pwlb);
    		jp1.add(jpw);
    		
    		//下部
    		jp2=new JPanel();
    		remJB=new JButton("记住密码");
    		remJB.setForeground(Color.red);
    		LoginJB=new JButton("登 录");
    		cannelJB=new JButton("取 消");
    		jp2.add(remJB);
    		jp2.add(LoginJB);
    		jp2.add(cannelJB);
    	//添加组件
    		 //设置布局方式
       	    this.setLayout(new GridLayout(3,1));
    		this.add(Imjb,BorderLayout.NORTH);
    		this.add(jp1);
    		this.add(jp2,BorderLayout.SOUTH);
    		
    		//设置窗体属性
     		this.setTitle("用户登录");
    		this.setIconImage(new ImageIcon("images/qq.png").getImage());
    	   //设置窗口居中
    	    int width=getToolkit().getDefaultToolkit().getScreenSize().width;
    	    int height=getToolkit().getDefaultToolkit().getScreenSize().height;
    	    this.setLocation(width/2-200,height/2-200);
    		this.setSize(250,168);
    		this.setResizable(false);
     		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		this.setVisible(true);
    	}
    }
    

      运行截图:

    --------------少年不努力,长大搞程序。欢迎关注,如有错误,恳请指正。
  • 相关阅读:
    原型设计
    案例分析
    编程作业
    《构建之法》阅读任务
    2021.3.11 准备工作随笔
    课程总结
    第十四周课程总结&实验报告(简单记事本的实现)
    第十三周课程总结
    第十二周
    第十一周课程总结
  • 原文地址:https://www.cnblogs.com/oycyqr/p/4925420.html
Copyright © 2011-2022 走看看