代ç å¦ä¸ï¼
import java.awt.*;ç¨åºåæï¼
JComponent.paintå
ç»å¶ç»ä»¶ï¼ç¶åç»å¶ç»ä»¶çè¾¹æ¡ï¼åç»å¶ç»ä»¶çåç»ä»¶ãè°ç¨ç顺åºç¡®ä¿ç»ä»¶ãè¾¹æ¡ååç»ä»¶é½æ¯å¯è§çãå¦æç»ä»¶æä¸ä¸ª UI代表ï¼åJComponent.paintComponentè°ç¨è¯¥ä»£è¡¨çUpdateæ¹æ³ï¼è¯¥æ¹æ³ä¸ºä¸éæç»ä»¶æ¦é¤èæ¯ï¼ç¶åç»å¶ç»ä»¶ã
CInsteadæ¯ä¸ä¸ªä¸éæçç»ä»¶ï¼å¦æéè½½paintæ¹æ³ï¼å
¶èæ¯å¾æ¯æ æ³è¢«æ¦é¤çï¼å æ¤ï¼å³ä½¿æ´æ°äºç»ä»¶çææå
å«ç»ä»¶ï¼å¨çé¢ä¸æ¯çä¸å°çãæ以å¿
é¡»éè½½paintComponentæ¹æ³ï¼å¨ç»å¶åç»ä»¶åå
æ¦é¤èæ¯ã
对åç¼åç»ä»¶ï¼paintæ¹æ³è´è´£æç»ä»¶ç»å¶å°å±å¤ç¼åä¸ï¼ç¶åæå±å¤ç¼åæ·è´å°ç»ä»¶çå±ä¸ä»£è¡¨ä¸ï¼æ£å 为å¦æ¤ï¼ä¸å»ºè®®ä¸ºSwingç»ä»¶éè½½paintï¼å¦æéè¦éæ°å®ä¹å¦ä½ç»å¶ç»ä»¶ï¼é£ä¹å°±éè½½paintComponent()ã
那用drawImage,需要的包,你自己包含以下。
package com.Swing;先写个panel用来贴图片的,然后再用另一个主frame加载这个panel即可。
package com.card.frame.image;