• Swing JButton设置背景图片


    import org.*;
    import org.v1.*;
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.swing.*;
    import javax.swing.border.Border;
    import org.AbstractFrame;
    import org.config.FrameConfig;
    import org.config.FrameManager;
    import org.dao.BaseDaoFactory;
    import org.dao.UserDao;
    import org.event.ResizeEvent;
    import org.util.FrameUtil;
    import org.util.PropertiesUtil;
    
    /**
     *
     * 主登录窗口类
     *
     * @author weijian.zhongwj
     */
    public class Login extends AbstractFrame {
    
        public Login() {
            InitBackGround();
            this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            this.setSize(FrameManager.currentWidth, FrameManager.currentHeight);
            this.setResizable(true);
            this.setMinimumSize(new Dimension(800,600));
    //        this.setLocationRelativeTo(null);
            this.setLocation(FrameManager.currentX, FrameManager.currentY);
            this.setVisible(true);
            this.setTitle("");
            addButtonEnter();
        }
        private JPanel panel;
    
        public void InitBackGround() {
            final ImageIcon icon = new ImageIcon(ClassLoader.getSystemResource(FrameConfig.WELCOME_IMAGE));
    
            panel = new JPanel() {
    
                protected void paintComponent(Graphics g) {
                    g.drawImage(icon.getImage(), 0, 0, FrameConfig.WIDTH, FrameConfig.HEIGH, null);
                    super.paintComponent(g);
                }
            };
            panel.setLayout(null);
            panel.setOpaque(false);
            panel.setPreferredSize(new Dimension(750, 550));
            JScrollPane scrollPane = new JScrollPane(panel);
            getContentPane().add(scrollPane);
        }
    
        private void addButtonEnter() {
            ImageIcon icon = new ImageIcon(FrameConfig.WELCOME_BUTTON);
            JButton enter = new JButton(icon);
            enter.setBounds(900, 380, 380, 270);
            enter.setOpaque(false);
            enter.setContentAreaFilled(false);
            enter.setMargin(new Insets(0, 0, 0, 0));
            enter.setFocusPainted(false);
            enter.setBorderPainted(false);
            enter.setBorder(null);
            panel.add(enter);
            enter.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                }
            });
    
        }
    
        public static void main(String[] args) {
            try {
                JFrame.setDefaultLookAndFeelDecorated(true);
                UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
                Login frame = new Login();
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
            } catch (InstantiationException ex) {
                Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {
                Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
            } catch (UnsupportedLookAndFeelException ex) {
                Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }


  • 相关阅读:
    python并发编程之多进程
    python并发编程之多进程理论部分
    Python GIL(Global Interpreter Lock)
    python并发编程之多线程
    前端基础之CSS
    前端知识之HTML内容
    Python杂货铺-(1)os模块在python中执行shell命令
    Hive学习小记-(17)inline(array(struct))与explode
    Hive学习小记-(16)hive加载解析json文件
    Hive学习小记-(15)transform函数
  • 原文地址:https://www.cnblogs.com/secbook/p/2655160.html
Copyright © 2020-2023  润新知