• 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);
    	}
    }
    

      运行截图:

    --------------少年不努力,长大搞程序。欢迎关注,如有错误,恳请指正。
  • 相关阅读:
    STM32 定时器用于外部脉冲计数
    幸福是怎么来的
    STM32 I/O的耐压问题,中断问题,以及如何在Keil (RVMDK) 中观察程序的执行时间
    STM32输入捕获简介
    STM32 直流减速电机控制
    2013 初始
    js 为字符串添加样式
    js 实现页面显示钟表
    JavaScript 入门总结
    ADO.NET基本数据库编程
  • 原文地址:https://www.cnblogs.com/oycyqr/p/4925420.html
Copyright © 2020-2023  润新知