zoukankan      html  css  js  c++  java
  • Swing编程把图片放入frame里。先不作为背景图片

    总结:

    总之遵循一条,所有的组件都不是直接放入frame里的。还要label的重要性,panel。面板类

    虽然我还是不会做,但总算出了个图片出来~~~~~~~~~~~~~

    package com.kk;
    
    import javax.swing.ImageIcon;
    import javax.swing.*;
    import java.awt.FlowLayout;
    import javax.swing.JPanel;
    import java.awt.BorderLayout;
    
    public class yc {
    	public yc() {
    
    	}
    
    	public static void main(String[] args) {
    		JFrame frame = new JFrame("背景图片设置");
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		// 妈的。想哭啊。我不知道为什么我ll
    		ImageIcon ico = new ImageIcon("d:\21.jpg");
    		JLabel label = new JLabel(ico);// 把背景图片放在标签里
    		// JPanel im=new JPanel(ico);//将图片放入panel里有错吗?
    		frame.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));// 将背景图片加入到frame里的layeredpane面板里
    		label.setBounds(0, 0, ico.getIconWidth(), ico.getIconHeight());// 设置背景标签的位置
    		JButton b = new JButton("赞");
    		JButton b2 = new JButton("喜欢");
    
    		// frame.add(label,BorderLayout.SOUTH);
    
    		frame.add(label);
    		frame.add(b2);
    		frame.add(b);
    		frame.setLayout(new FlowLayout());
    		// frame.setLayout(new BorderLayout());
    		frame.setBounds(0, 0, 444, 444);
    		frame.setVisible(true);
    	}
    
    }
    

      

  • 相关阅读:
    POJ 3114 Tarjan+Dijkstra
    278. First Bad Version
    209. Minimum Size Subarray Sum
    154. Find Minimum in Rotated Sorted Array II
    153. Find Minimum in Rotated Sorted Array
    710. Random Pick with Blacklist
    767. Reorganize String
    524. Longest Word in Dictionary through Deleting
    349. Intersection of Two Arrays
    350. Intersection of Two Arrays II
  • 原文地址:https://www.cnblogs.com/langlove/p/3428610.html
Copyright © 2011-2022 走看看