how can i put a JButton on an image?

后端 未结 4 1683
终归单人心
终归单人心 2020-12-18 07:54

I am trying to fix a JFrame where there will be a background image and on the image JButtons which will do some commands. I try to do it without layout because i want to pu

4条回答
  •  暖寄归人
    2020-12-18 08:14

    /*it is simple to put button on image first set image by making object then make button object & add the button object direct to image object rather then add to frame.*/
    
    package frame;
    
    
    
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    
    public class frame 
    {
    
        public frame() 
        {
            JFrame obj = new JFrame("Banking Software");
            JButton b1 = new JButton("Opening Account");
            JLabel image = new JLabel(new ImageIcon("money.jpg"));
            image.setBounds(0,0, 1600, 1400);
            obj.setExtendedState(JFrame.MAXIMIZED_BOTH);
            obj.add(image);
            b1.setBounds(500,400, 100, 40);
            image.add(b1);
            obj.setVisible(true);
        }
    
        public static void main(String args[]) 
        {
            new frame();
        }
    }
    

提交回复
热议问题