²ÉÓÃJAVA×é¼þÏÔʾ±¾µØͼƬ
³ÌÐòÉè¼ÆÖо³£»áÅöµ½ÓÃ×é¼þÀ´ÏÔʾͼƬµÄÇé¿ö, ¿ÉÒÔÏÔʾͼƬµÄ×é¼þÓкܶà,Èçawt°üÖеÄbutton,label,panelµÈ¶¼¿ÉÒÔÔÚÆäÉÏÃæ·ÅÖÃͼƬ.ͼƬÓÖ¿É·ÖΪÁ½Àà,Ò»ÀàÊÇ·ÅÖÃÓÚbuttonµÈ×é¼þÉϵÄImageIcon(ͼ±ê),ÁíÒ»ÀàÊÇ¿ÉÒÔ·ÅÖÃÔÚpanelµÈ×é¼þÉϵĽϴóµÄͼƬImage¡£
´Ó±¾µØ¼ÆËã»úÖжÁȡͼƬµÄ·½·¨Ò²Óкܶ࣬±ÈÈ磬ÀûÓÃImageIconÀ´¶ÁÈ¡±¾µØͼƬ£¬»¹¿ÉÒ԰ѶÁÈ¡µ½µÄImageIconת»»ÎªImage¡£»¹ÓÐÒ»ÖÖ»ñÈ¡ImageµÄ·½·¨ÊÇÀûÓÃToolkitÀà¡£ÎÒ¸öÈ˽Ïϲ»¶µÚ¶þÖÖ·½·¨£¬Toolkit.getDefaultToolkit().createImage("ͼƬÃû")£»ÒòΪToolkitÀàÊÇÖ±½ÓÓë±¾µØ²Ù×÷ϵͳÏàÁªÏµµÄÒ»¸öÀ࣬»ñÈ¡µ½µÄͼƬ»á¸üÕæʵ£¬¸üÖ±½Ó¡£
ÏëÒªÓÃJPanelÀ´ÏÔʾ»ñÈ¡µ½µÄͼƬ¾ÍÐèÒªÖØдJPanelÀàµÄpaint(Graphics g)·½·¨£¬¿ÉÒÔÖØдһ¸öÀàÀ´extends JpanelÀ࣬Ҳ¿ÉÒÔÔÚ¶¨ÒåJpanelÀàµÄʵÀýʱ²ÉÓÃÄäÃûÀàµÄд·¨À´ÖØÔØpaint()·½·¨¡£
ʾÀýÒ»£º
classImagePanel extends JPanel{
Image image=Toolkit.getDefaultToolkit().createImage("test.jpg")£»
public void paint(Graphics g) {
g.drawImage(image,0,0,image.getWidth(null),image.getHeight(null),null);
}
}
ʾÀý¶þ£º
Image image=Toolkit.getDefaultToolkit().createImage("test.jpg")£»
JPanel panel=new JPanel(){
public void paint(Graphics g){
g.drawImage(image,0,0,imagegetWidth(null),image.getHeight(null),null);
}
};
Ïà¹ØÎĵµ£º
Java NIO APIÏê½â
ÔÚJDK
1.4ÒÔÇ°£¬JavaµÄIO²Ù×÷¼¯ÖÐÔÚjava.ioÕâ¸ö°üÖУ¬ÊÇ»ùÓÚÁ÷µÄ×èÈû£¨blocking£©API¡£¶ÔÓÚ´ó¶àÊýÓ¦ÓÃÀ´Ëµ£¬ÕâÑùµÄAPIʹÓúܷ½
±ã£¬È»¶ø£¬Ò»Ð©¶ÔÐÔÄÜÒªÇó½Ï¸ßµÄÓ¦Óã¬ÓÈÆäÊÇ·þÎñ¶ËÓ¦Óã¬ÍùÍùÐèÒªÒ»¸ö¸üΪÓÐЧµÄ·½Ê½À´´¦ÀíIO¡£´ÓJDK 1.4Æð£¬NIO
API×÷Ϊһ¸ö»ùÓÚ»º³åÇø£¬²¢ÄÜÌṩ·Ç×èÈû(non-blo ......
import java.util.Properties;
public class ConfigReader {
private static Properties cache = new Properties();
static{
try {
cache.load(ConfigReader .class.getClassLoader().getResourceAsStream("config.properties"));
} catch (Exception e) {
&nbs ......
public class Factory {
private static Factory factory;
private static Object classLock=Factory.class;
private Factory(){}
public static Factory getFactory(){
synchronized(classLock){
......
Ḭ̈߳²È«µÄ¼¯ºÏ°üº¬2¸öÎÊÌâ
1.¶àÏ̲߳¢·¢ÐÞ¸ÄÒ» ¸ö ¼¯ºÏ Ôõô°ì£¿
2.Èç¹ûµü´úµÄ¹ý³ÌÖÐ ¼¯ºÏ ±»ÐÞ¸ÄÁËÔõô°ì£¿
a.Ò»¸öÏß³ÌÔÚµü´ú£¬ÁíÒ»¸öÏß³ÌÔÚÐÞ¸Ä
b.ÔÚͬһ¸öÏß³ÌÄÚÓÃͬһ¸öµü´úÆ÷¶ ......