首页 > 其他分享 >lesson16-ImageIconDemo

lesson16-ImageIconDemo

时间:2023-10-25 16:16:33浏览次数:35  
标签:lesson16 import ImageIconDemo new jLabel public

 在Eclipse 里面执行

 

 

 

package ZYM_GUI;

import java.awt.Container;
import java.net.URL;
import javax.swing.*; 

public class ImageIconDemo extends JFrame {
	
	  public ImageIconDemo() {
		  
	         JLabel jLabel = new JLabel("Image");
	         //ALT+回车
	          URL url=ImageIconDemo.class.getResource("logo.png");
	         ImageIcon imageIcon = new ImageIcon(url);
	         jLabel.setIcon(imageIcon);
	         jLabel.setHorizontalAlignment(SwingConstants.CENTER);
	         Container contentPane = getContentPane();
	         contentPane.add(jLabel);
	         setTitle("lesson16-ImageIconDemo");
	         setBounds(1, 1, 400, 150);
	         setVisible(true);
	         setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
		  
	  }

	public static void main(String[] args) {
		new ImageIconDemo();		
		 System.out.println(ImageIconDemo.class.getResource("logo.png"));
	}

}

  

标签:lesson16,import,ImageIconDemo,new,jLabel,public
From: https://www.cnblogs.com/zym97816/p/17787420.html

相关文章