下面是一个程序,用兰色标记的地方看不能懂(根说关于超类的),我把它贴出来哪位帮忙讲解一下。谢谢拉
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class MyFrame extends JFrame
implements ActionListener
{
public MyFrame()
{
setTitle("Swing示例程序9");
setSize(300, 200);
setLocation(100,100);
addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent e)
{ System.exit(0);
}
} );
//增加复选框
JPanel p = new JPanel();
ckDog = addCheckBox(p, "Dog");
ckCat = addCheckBox(p, "Cat");
getContentPane().add(p, "South");
panel = new MyPanel();
getContentPane().add(panel, "Center");
}
//增加复选框方法
public JCheckBox addCheckBox(JPanel p, String name)
{
JCheckBox c = new JCheckBox(name);
c.addActionListener(this);
p.add(c);
return c;
}
public void actionPerformed(ActionEvent evt)
{
if (ckDog.isSelected())
{
panel.bDog = true;
}
else
{
panel.bDog = false;
}
if (ckCat.isSelected())
{
panel.bCat = true;
}
else
{
panel.bCat = false;
}
//调用MyPanel.paintComponent(...),绘制MyPanel上的内容
panel.repaint();
}
private MyPanel panel;
private JCheckBox ckDog;
private JCheckBox ckCat;
}
class MyPanel extends JPanel
{
public MyPanel()
{
bDog = false;
bCat = false;
}
//绘制信息
public void paintComponent(Graphics g)
{
super.paintComponent(g);//?这个语法是什么意思?
if (bDog)
g.drawString("I love the dog",20, 30);
if (bCat)
g.drawString("I love the cat",20, 60);
}
public boolean bDog;
public boolean bCat;
}
public class Swing13_9
{ public static void main(String[] args)
{ JFrame frame = new MyFrame();
frame.setVisible(true);
}
}