一个很菜的问题,希望各位大虾不要笑我,(50分)

  • 主题发起人 dugugiugang
  • 开始时间
D

dugugiugang

Unregistered / Unconfirmed
GUEST, unregistred user!
源码如下:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Test extends JApplet {
public Test() {
Container contentPane = getContentPane();
ContainerWithBoxLayout yaxis =
new ContainerWithBoxLayout(BoxLayout.Y_AXIS);
ContainerWithBoxLayout xaxis =
new ContainerWithBoxLayout(BoxLayout.X_AXIS);
contentPane.setLayout(new FlowLayout());
xaxis.add(new JButton(new ImageIcon("reach.gif")));
xaxis.add(new JButton(new ImageIcon("punch.gif")));
xaxis.add(new JButton(new ImageIcon("open_hand.gif")));
yaxis.add(new JButton(new ImageIcon("ladybug.gif")));
yaxis.add(new JButton(new ImageIcon("crab.gif")));
yaxis.add(new JButton(new ImageIcon("frog.gif")));
yaxis.add(new JButton(new ImageIcon("snail.gif")));
contentPane.add(xaxis);
contentPane.add(yaxis);
}
}
class ContainerWithBoxLayout extends JPanel {
public ContainerWithBoxLayout(int orientation) {
setLayout(new BoxLayout(this, orientation));
}
}

问题:
源码中的第五行的 Test() 应为 类 Test 的一个构造方法,在本
程序段中的类 Test()并没有实例化,也就是说,没有给它创建一个
对象,按书中所说,据我的理解,一个类如果没有实例化,就应该
没有执行,为什么这段程序的构造方法一段,即 Test() {...}
却都得到了执行,程序结果是,Ie显示几个带有图像的 button.

 
extends JApplet
说明它是一个 Applet, 已经继承了超类的方法.
更重要的一点是嵌在网页中时, 当调用这个网页时,
就会自动创建, 可能是浏览器支持的.
 
Applet 是不需要显式实例化的.
 
接受答案了.
 
顶部