import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class JButtonDemo extends JFrame
{
private JCheckBox boldcheckbox,italiccheckbox;
private JTextField text;
public JButtonDemo()
{
super( "复选框示范 ");
JPanel panel=new JPanel();
Container c=getContentPane();
text=new JTextField( "选中复选框,文字变化 ",16);
text.setFont(new Font( "serif ",Font.PLAIN,18));
text.setForeground(Color.blue);
c.add(text,BorderLayout.CENTER);
boldcheckbox=new JCheckBox( "粗体 ");
boldcheckbox.addItemListener(new StyleChange());
panel.add(boldcheckbox);
italiccheckbox=new JCheckBox( "斜体 ");
italiccheckbox.addItemListener(new StyleChange());
panel.add(italiccheckbox);
c.add(panel,BorderLayout.SOUTH);
}
private class StyleChange implements ItemListener
{
public void itestatechanged(ItemEvent e)
{
int style=Font.PLAIN;
if(boldcheckbox.isSelected())
style+=Font.BOLD;
if(italiccheckbox.isSelected())
style+=Font.ITALIC;
text.setFont(new Font( "serif ",style,18));
}
}
public static void main(String arg[])
{
JFrame jframe=new JButtonDemo();
jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jframe.pack();
jframe.setVisible(true);
}
}
谁帮我看下这个程序,运行时提示:JButtonDemo.StyleChange is not abstract and does not override abstract method itemStateChanged(java.awt.event.ItemEvent) in java.awt.event.ItemListener
是什么意思??
------解决方案--------------------
itestatechanged
改成
itemStateChanged
注意大小写,拼写...