zoukankan      html  css  js  c++  java
  • 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);
            }
        }
    }


  • 相关阅读:
    Leetcode 33.搜索旋转排序数组
    Leetcode 32.最长有效括号
    Leetcode 31.下一个排列
    Leetcode 30.与所有单词相关联的子串
    Leetcode 25.k个一组翻转链表
    Leetcode 24.两两交换链表中的节点
    做数据分析需要“搞”人?
    求职互联网数据分析,如何准备行业知识?
    如何利用Social Listening从社会化媒体中“提炼”有价值的信息?
    运营实操|如何利用微信后台数据优化微信运营
  • 原文地址:https://www.cnblogs.com/secbook/p/2655160.html
Copyright © 2011-2022 走看看