//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 ,那第二个空应该填什么呢?

解决方案 »

  1.   

    //import java.awt.*;
    //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();
    // }
    //}
      

  2.   

    应该填evt.getSource()还是repaint();还是其他的?
      

  3.   

    evt.getSource()
    在JDK1.4中通过了
      

  4.   

    填repaint();好象也可以通过编译吧?因为我之前也是填repaint(); 那evt.getSource();可以完成什么功能呢?
      

  5.   

    evt.getSource()
    得到事件源对象
      

  6.   

    获得source里面的值
    然后赋给style.
      

  7.   

    evt.getSource()
    获取当前监听器监听到的组件名。
      

  8.   

    evt.getSource()
    同意楼上的解释