万能百科  > 计算机   > 

[填空题] 下列JApplet使用重写paintCompon6t()方法来绘制图像,请填写正确的代码在横线处。 import java.awt.*; imp

2021-07-20   

[填空题] 下列JApplet使用重写paintCompon6t()方法来绘制图像,请填写正确的代码在横线处。

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()方法,必须在绘制图像之前调用super.paintComponent()方法来对构件的背景进行绘制。

词条内容仅供参考,如果您需要解决具体问题
(尤其在法律、医学等领域),建议您咨询相关领域专业人士。

标签