下列JApplet使用重写paintComponet()方法来绘制图像,请填写正确的代码在横线处。 import java.awt.*; import javax.swing.*; public class Test extends JA

admin2010-07-28  26

问题 下列JApplet使用重写paintComponet()方法来绘制图像,请填写正确的代码在横线处。
   import java.awt.*;
   import javax.swing.*;
   public class Test extends JApplet
   {
        staic String fileName =  "IMG onClick=over(this) title=放大().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 onClick=over(this) title=放大)
        {
                this.i = IMG onClick=over(this) title=放大;
        }
        public void paintComponent(Graphics gg)
        {
               【  】;
                gg.drawImage(i,20,20,this);
        }
   }

选项

答案super.paintComponent(gg)

解析 在Panel子类中重写paintComponent()方法,必须在绘制图像之前调用super.paintComponent()方法来对构件的背景进行绘制。
转载请注明原文地址:https://jikaoti.com/ti/jtH0FFFM
0

最新回复(0)