java界面添加动态背景图片

java界面添加动态背景图片


之前在网上找了一些代码添加背景图片,有些用得了有些用不了,总是不得要领,后来学了用工具写界面,自己试了一下添加图片,效果还不错,原理如图.
在这里插入图片描述
效果如图
在这里插入图片描述
测试代码如下:如有需要,自取
链接:https://pan.baidu.com/s/1S3d0_Tyf4BecWc0V7l8NQQ
提取码:0hth
复制这段内容后打开百度网盘手机App,操作更方便哦

package 项目;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.border.EmptyBorder;

import manage.service.UserService;
import manage.vo.manager;

import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.security.auth.login.LoginContext;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class login_gif extends JFrame implements ActionListener  {

	private JPanel contentPane;
	private JTextField textField_name;
	private JPasswordField textField_PS;
	private JButton btnNewButton ;
	private JButton button ;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					login_gif frame = new login_gif();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public login_gif() {
		this.setTitle("人脸识别系统");// 设置窗体的标题
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 700, 600);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JPanel panel = new JPanel();
		panel.setBounds(0, 10, 434, 217);
		contentPane.add(panel);
		panel.setLayout(null);
		
		JLabel Name = new JLabel("\u7528\u6237\u540D");
		Name.setBounds(48, 28, 54, 15);
		Name.setForeground(Color.white);
		panel.add(Name);
		
		JLabel passWorld = new JLabel("\u5BC6\u7801");
		passWorld.setBounds(48, 65, 54, 15);
		passWorld.setForeground(Color.white);
		panel.add(passWorld);
		
		textField_name = new JTextField();
		textField_name.setBounds(112, 28, 130, 18);
		panel.add(textField_name);
		textField_name.setColumns(10);
		
		textField_PS = new JPasswordField();
		textField_PS.setBounds(112, 63, 130, 18);
		panel.add(textField_PS);
		textField_PS.setColumns(10);
		
		btnNewButton = new JButton("\u767B\u5F55 ");//登录按钮;
		
		btnNewButton.setBounds(90, 119, 68, 23);
		panel.add(btnNewButton);
		
		button = new JButton("\u6CE8\u518C");//注册按钮
		button.setBounds(174, 119, 68, 23);
		panel.add(button);
		panel.setOpaque(false);
		ImageIcon icon = new ImageIcon("src/项目/人脸识别.jpg");
		JLabel jl=new JLabel(icon);
		jl.setBounds(0, 0, icon.getIconWidth(), icon.getIconHeight());
		this.add(jl);
		
		//添加事件监听
		
		btnNewButton.addActionListener(this);
		button.addActionListener(this);
	}

	@Override
	public void actionPerformed(ActionEvent e){
		
		String ID=new String(textField_name.getText());//获取用户输入的数据
        String password=new String(textField_PS.getPassword());
        UserService judege=new UserService();
        manager ma=new manager();
        if(e.getSource()==btnNewButton)
        {
        	//System.out.println(textField_PS.getText()+"    "+textField_name.getText());测试
            if(judege.isRight(ID,password))
            {
                ma.setID(ID);
                ma.setPassword(password);
                //测试界面
                JOptionPane.showMessageDialog(null, "登录成功");   
                 /*
                  * 
                  * 
                  * 
                  * 
                  * 
                  * 
                  * 跳转到操作界面
                  * 
                  * 
                  * 
                  * 
                  * 
                  */
                //System.out.println("             kkkkkk");测试
                this.dispose();
            }
            else
            {
                JOptionPane.showMessageDialog(null,"用户名或密码错误","登录失败",JOptionPane.ERROR_MESSAGE);
                textField_name.setText("");
                textField_PS.setText("");
            }
        }else if(e.getSource()==button){
        	logon_gif frame = new logon_gif();
			frame.setVisible(true);
            this.dispose();
        }
    }

	
}


  • 9
    点赞
  • 45
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值