源程序:
import java.awt.* ;
import javax.swing.* ;
import java.io.* ;
public class Test{
public static void main(String[] args){
JFrame frame = new JFrame("测试") ;
String picPath = "d:" + File.separator + "android.png" ;
File file = new File(picPath) ;
InputStream input = null ;
byte[] b = new byte[(int)file.length()] ;
try{
input = new FileInputStream(file) ;
input.read(b) ;
input.close() ;
}catch(Exception e){
e.printStackTrace() ;
}
Icon icon = new ImageIcon(b) ;
JLabel lab = new JLabel("ANDROID" , icon , JLabel.CENTER) ;
Font fnt = new Font("Serief" , Font.ITALIC + Font.BOLD , 28) ;
lab.setFont(fnt) ;
lab.setBackground(Color.YELLOW) ;
lab.setForeground(Color.RED) ;
frame.add(lab) ;
frame.setSize(1200 , 700) ;
frame.setBackground(Color.WHITE) ;
frame.setLocation(1 , 1) ;
frame.setVisible(true) ;
}
}
运行结果: