主题:[讨论]java内部类的使用
这个是我作业的部分代码,完整的代码在上传的文件里.
代码的目的是:当调用public TimePanel()
{
start();
}
是,在panel上显示系统的时间.
我执行的结果没任何显示不知道为什么.....请大侠指点!
paintPerformedpublic class TimePanel extends JPanel
{
public TimePanel()
{
start();
}
public void paintPerformed(Graphics g)
{
super.paintComponent(g);
Graphics2D g2=(Graphics2D)g;
//to show the present time
Date date=new Date();
DateFormat dateFormat = DateFormat.getTimeInstance();
String d = dateFormat.format(date);
g2.drawString(d,100, 200);
if(beep==true)
{
Toolkit.getDefaultToolkit().beep();
}
}
public void setBeep()
{
this.beep=true;
}
public void makeButton()
{
//create button
JButton startButton=new JButton("start");
JButton stopButton=new JButton("stop");
JButton beepButton=new JButton("beep");
//add button to the panel
add(startButton);
add(stopButton);
add(beepButton);
//action of the button
startButton.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(ActionEvent e)
{
start();
}
}
);
stopButton.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(ActionEvent e)
{
stop();
}
});
beepButton.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Toolkit.getDefaultToolkit().beep();
}
});
}
public void start()
{
StartAction lis = new StartAction();
t = new Timer(1000, lis);
t.start();
}
public void stop()
{
t.stop();
}
private boolean beep;
private Timer t;
//inner class StartAction
class StartAction implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
[color=FF00FF] repaint();[/color]
}
}
public static void main(String[] args)
{
// TODO Auto-generated method stub
}
}
StartAction为TimePanel的内部类,当调用StartAction的repaint方法时,会调用到TimePanel的paintPerformed方法吗?