package com.ten;
import java.awt.Container;
import java.net.URL;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.*;
public class MyImageIcon extends JFrame{
public MyImageIcon(){
Container con = getContentPane();
JLabel jl = new JLabel("这是一个JFrame窗体",JLabel.CENTER);
URL url = MyImageIcon.class.getResource("imageButton.jap");
Icon icon = new ImageIcon(url);
jl.setIcon(icon);
jl.setHorizontalAlignment(SwingConstants.CENTER);
jl.setOpaque(true);
con.add(jl);
setSize(250,100);
setVisible(true);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
public static void main(String[] args){
new MyImageIcon();
}
}
相关分类