ButtonHandler handler = new ButtonHandler();这句话为什么出错呀? ButtonHandler handler = new ButtonHandler();这句话为什么出错呀? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 import java.awt.*;import java.awt.event.*;import javax.swing.*;public class JButtonTest extends JFrame{ private JButton Button1,Button2; private JTextField field; private JCheckBox bold,italic; public JButtonTest(){ super("Testing Buttons:"); Container container = getContentPane(); container.setLayout(new FlowLayout()); Button1 = new JButton("Button1"); container.add(Button1); Button2 = new JButton("Button2"); container.add(Button2); ButtonHandler handler = new ButtonHandler(); Button1.addActionListener(handler); Button2.addActionListener( handler); field = new JTextField("Watch the font style change",20); field.setFont( new Font("Serif",Font.PLAIN ,14)); container.add(field); bold = new JCheckBox("Bold"); container.add(bold); italic = new JCheckBox("Italic"); container.add(italic); CheckBoxHandler handler1 = new CheckBoxHandler(); bold.addItemListener( handler1); italic.addItemListener( handler1); setSize(275,180); setVisible(true); // CheckBoxHandler handler ; } public static void main(String args[]) { JButtonTest application = new JButtonTest(); application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE); } private class ButtonHandler implements ActionListener{ public void actionPerformed(ActionEvent event){ JOptionPane.showMessageDialog(null,"You pressed:" + event.getActionCommand()); } } private class CheckBoxHandler implements ItemListener{ private int valBold = Font.PLAIN ; private int valItalic = Font.PLAIN ; public void itemStateChange(ItemEvent event){ if(event.getSource() == bold) if(event.getStateChange()== ItemEvent.SELECTED) valBold = Font.BOLD ; else valBold = Font.PLAIN ; if(event.getSource() == italic) if(event.getStateChange()==ItemEvent.SELECTED ) valItalic= Font.ITALIC ; else valItalic = Font.PLAIN ; else valItalic = Font.PLAIN ; field.setFont( new Font("serif",valBold + valItalic,14)); } }}CheckBoxHandler这一行有错误.不知道为什么.麻烦大家帮我看一下,我是新手 java 向文件的首行追加一条数据 jdk API Java for循环 帮忙 java代码奇怪的写法 锁的问题 installanywhere中用户变量传递 关于Servlet的一个问题 哪里可以下JSP的中文文档及相关资料 怎样使JTree对象可以自动有滚动条, 关于整合TOMCAT和APACHE!! 高手分析下(mfc)vc++与(jb)java的区别啊 帮帮忙,各位大侠,我是一个初级人员很急,谢谢!!!
import java.awt.event.*;
import javax.swing.*;
public class JButtonTest extends JFrame{
private JButton Button1,Button2;
private JTextField field;
private JCheckBox bold,italic;
public JButtonTest(){
super("Testing Buttons:");
Container container = getContentPane();
container.setLayout(new FlowLayout());
Button1 = new JButton("Button1");
container.add(Button1);
Button2 = new JButton("Button2");
container.add(Button2);
ButtonHandler handler = new ButtonHandler();
Button1.addActionListener(handler);
Button2.addActionListener( handler);
field = new JTextField("Watch the font style change",20);
field.setFont( new Font("Serif",Font.PLAIN ,14));
container.add(field);
bold = new JCheckBox("Bold");
container.add(bold);
italic = new JCheckBox("Italic");
container.add(italic);
CheckBoxHandler handler1 = new CheckBoxHandler();
bold.addItemListener( handler1);
italic.addItemListener( handler1);
setSize(275,180);
setVisible(true);
// CheckBoxHandler handler ;
}
public static void main(String args[])
{
JButtonTest application = new JButtonTest();
application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE);
}
private class ButtonHandler implements ActionListener{
public void actionPerformed(ActionEvent event){
JOptionPane.showMessageDialog(null,"You pressed:" + event.getActionCommand());
}
}
private class CheckBoxHandler implements ItemListener{
private int valBold = Font.PLAIN ;
private int valItalic = Font.PLAIN ;
public void itemStateChange(ItemEvent event){
if(event.getSource() == bold)
if(event.getStateChange()== ItemEvent.SELECTED)
valBold = Font.BOLD ;
else
valBold = Font.PLAIN ;
if(event.getSource() == italic)
if(event.getStateChange()==ItemEvent.SELECTED )
valItalic= Font.ITALIC ;
else
valItalic = Font.PLAIN ;
else
valItalic = Font.PLAIN ;
field.setFont( new Font("serif",valBold + valItalic,14));
}
}
}CheckBoxHandler这一行有错误.不知道为什么.麻烦大家帮我看一下,我是新手