[填空題] 下列JApplet使用重寫paintCompon6t()方法來繪制圖像,請?zhí)顚懻_的代碼在橫線處。 import java.awt.*; imp
[填空題] 下列JApplet使用重寫paintCompon6t()方法來繪制圖像,請?zhí)顚懻_的代碼在橫線處。
import java.awt.*;
import javax.swing.*;
public class Test extends JApplet
staic String fileName = "img().gif";
public void init()
Container cp = getContentPane();
cp.setLayout(new GridLayout(1,1));
Image i = getImage(getCodeBase(),fileName);
MyImagePanel ip=new MyInmagePanel(i);
cp. add (ip);
class MyImagePanel extends JPanel
Image i;
public MyImagePanel(Image img)
this.i = img;
public void paintComponent(Graphics gg)
【15】 ;
gg.drawImage(i,20,20,this);
正確答案:
super.paintComponent(gg)
參考解析:在Panel子類中重寫paintComponent()方法,必須在繪制圖像之前調(diào)用super.paintComponent()方法來對構(gòu)件的背景進(jìn)行繪制。
詞條內(nèi)容僅供參考,如果您需要解決具體問題
(尤其在法律、醫(yī)學(xué)等領(lǐng)域),建議您咨詢相關(guān)領(lǐng)域?qū)I(yè)人士。