//import java.awt.*;
//import java.awt.event.*;
//import javax.swing.*;
//
//class ComboBoxFrame extends JFrame __________{
// public ComboBoxFrame(){
// setTitle("exam_13");
// setSize(300,200);
// addWindowListener(new WindowAdapter(){
// public void windowClosing(WindowEvent e){
// System.exit(0);
// }
// });
// style = new JComboBox();
// style.setEditable(true);
// style.addItem("Serif");
// style.addItem("SansSerif");
// style.addItem("Monospaced");
// style.addItem("Dialog");
// style.addItem("DialogInput");
// style.addActionListener(this);
//
// JPanel p = new JPanel();
// p.add(style);
// getContentPane().add(p, "South");
// panel = new ComboBoxTestPanel();
// getContentPane().add(panel, "Center");
// }
//
// public void actionPerformed(ActionEvent evt){
// JComboBox source = (JComboBox)__________;
// String item = (String)source.getSelectedItem();
// panel.setStyle(item);
// }
//
// private ComboBoxTestPanel panel;
// private JComboBox style;
//}
//
//class ComboBoxTestPanel extends JPanel{
// public ComboBoxTestPanel() {
// setStyle("Serif");
// }
// public void setStyle(String s){
// setFont(new Font(s, Font.PLAIN, 12));
// repaint();
// }
// public void paintComponent(Graphics g){
// super.paintComponent(g);
// g.drawString("Welcome to China!", 0, 50);
// }
//}
//
//public class exam_13{
// public static void main(String[] args){
// JFrame frame = new ComboBoxFrame();
// frame.show();
// }
//}第一个空我觉得是填 implements ActionListener ,那第二个空应该填什么呢?
//import java.awt.event.*;
//import javax.swing.*;
//
//class ComboBoxFrame extends JFrame __________{
// public ComboBoxFrame(){
// setTitle("exam_13");
// setSize(300,200);
// addWindowListener(new WindowAdapter(){
// public void windowClosing(WindowEvent e){
// System.exit(0);
// }
// });
// style = new JComboBox();
// style.setEditable(true);
// style.addItem("Serif");
// style.addItem("SansSerif");
// style.addItem("Monospaced");
// style.addItem("Dialog");
// style.addItem("DialogInput");
// style.addActionListener(this);
//
// JPanel p = new JPanel();
// p.add(style);
// getContentPane().add(p, "South");
// panel = new ComboBoxTestPanel();
// getContentPane().add(panel, "Center");
// }
//
// public void actionPerformed(ActionEvent evt){
// JComboBox source = (JComboBox)__________;
// String item = (String)source.getSelectedItem();
// panel.setStyle(item);
// }
//
// private ComboBoxTestPanel panel;
// private JComboBox style;
//}
//
//class ComboBoxTestPanel extends JPanel{
// public ComboBoxTestPanel() {
// setStyle("Serif");
// }
// public void setStyle(String s){
// setFont(new Font(s, Font.PLAIN, 12));
// repaint();
// }
// public void paintComponent(Graphics g){
// super.paintComponent(g);
// g.drawString("Welcome to China!", 0, 50);
// }
//}
//
//public class exam_13{
// public static void main(String[] args){
// JFrame frame = new ComboBoxFrame();
// frame.show();
// }
//}第一个空我觉得是填 implements ActionListener ,那第二个空应该填什么呢?
//import java.awt.event.*;
//import javax.swing.*;
//
//class ComboBoxFrame extends JFrame implements ActionListener {
// public ComboBoxFrame(){
// setTitle("exam_13");
// setSize(300,200);
// addWindowListener(new WindowAdapter(){
// public void windowClosing(WindowEvent e){
// System.exit(0);
// }
// });
// style = new JComboBox();
// style.setEditable(true);
// style.addItem("Serif");
// style.addItem("SansSerif");
// style.addItem("Monospaced");
// style.addItem("Dialog");
// style.addItem("DialogInput");
// style.addActionListener(this);
//
// JPanel p = new JPanel();
// p.add(style);
// getContentPane().add(p, "South");
// panel = new ComboBoxTestPanel();
// getContentPane().add(panel, "Center");
// }
//
// public void actionPerformed(ActionEvent evt){
// JComboBox source = (JComboBox)evt.getSource()
;
// String item = (String)source.getSelectedItem();
// panel.setStyle(item);
// }
//
// private ComboBoxTestPanel panel;
// private JComboBox style;
//}
//
//class ComboBoxTestPanel extends JPanel{
// public ComboBoxTestPanel() {
// setStyle("Serif");
// }
// public void setStyle(String s){
// setFont(new Font(s, Font.PLAIN, 12));
// repaint();
// }
// public void paintComponent(Graphics g){
// super.paintComponent(g);
// g.drawString("Welcome to China!", 0, 50);
// }
//}
//
//public class exam_13{
// public static void main(String[] args){
// JFrame frame = new ComboBoxFrame();
// frame.show();
// }
//}
在JDK1.4中通过了
得到事件源对象
然后赋给style.
获取当前监听器监听到的组件名。
同意楼上的解释