这里的this 是表示什么意思?   public ButtonPanel(String title, String[] options)
   {  
      setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), title));
      setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
      group = new ButtonGroup();
      
      // make one radio button for each option
      for (int i = 0; i < options.length; i++)
      {  
         JRadioButton b = new JRadioButton(options[i]);
         b.setActionCommand(options[i]);
         add(b);
         group.add(b);
         b.setSelected(i == 0);
      }
   }     public String getSelection()
   {  
      return group.getSelection().getActionCommand();
   }
   
   private ButtonGroup group;
}
   
class OptionDialogFrame extends JFrame 
{  
   public OptionDialogFrame()
   {  
      setTitle("OptionDialogTest");
      setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);      JPanel gridPanel = new JPanel();
      gridPanel.setLayout(new GridLayout(2, 3));
      
      typePanel = new ButtonPanel("Type", 
         new String[] 
         {  
            "Message", 
            "Confirm", 
            "Option", 
            "Input" 
         });      messageTypePanel = new ButtonPanel("Message Type", 
         new String[] 
         {  
            "ERROR_MESSAGE", 
            "INFORMATION_MESSAGE", 
            "WARNING_MESSAGE", 
            "QUESTION_MESSAGE",
            "PLAIN_MESSAGE" 
         });
         
      messagePanel = new ButtonPanel("Message", 
         new String[] 
         {  
            "String", 
            "Icon", 
            "Component", 
            "Other", 
            "Object[]"
         });
      
      optionTypePanel = new ButtonPanel("Confirm", 
         new String[] 
         {  
            "DEFAULT_OPTION", 
            "YES_NO_OPTION", 
            "YES_NO_CANCEL_OPTION", 
            "OK_CANCEL_OPTION" 
         });
         
      optionsPanel = new ButtonPanel("Option", 
         new String[] 
         {  
            "String[]", 
            "Icon[]", 
            "Object[]" 
         });
         
      inputPanel = new ButtonPanel("Input",
         new String[]
         {  
            "Text field",
            "Combo box"
         });
         
      gridPanel.add(typePanel);
      gridPanel.add(messageTypePanel);
      gridPanel.add(messagePanel);
      gridPanel.add(optionTypePanel);
      gridPanel.add(optionsPanel);
      gridPanel.add(inputPanel);      // add a panel with a Show button      JPanel showPanel = new JPanel();
      JButton showButton = new JButton("Show");
      showButton.addActionListener(new ShowAction());
      showPanel.add(showButton);
      
      add(gridPanel, BorderLayout.CENTER);
      add(showPanel, BorderLayout.SOUTH);
   }     public Object getMessage()
   {  
      String s = messagePanel.getSelection();
      if (s.equals("String"))
         return messageString;
      else if (s.equals("Icon"))
         return messageIcon;
      else if (s.equals("Component"))
         return messageComponent;
      else if (s.equals("Object[]"))
         return new Object[]
         {  
            messageString,
            messageIcon,
            messageComponent,
            messageObject
         };
      else if (s.equals("Other"))
         return messageObject;
      else return null;
   }
   
     public Object[] getOptions()
   {  
      String s = optionsPanel.getSelection();
      if (s.equals("String[]"))
         return new String[] { "Yellow", "Blue", "Red" };
      else if (s.equals("Icon[]"))
         return new Icon[]
         {  
            new ImageIcon("yellow-ball.gif"),
            new ImageIcon("blue-ball.gif"),
            new ImageIcon("red-ball.gif")
         };
      else if (s.equals("Object[]"))
         return new Object[]
         {  
            messageString,
            messageIcon,
            messageComponent,
            messageObject
         };
      else 
         return null;
   }
   public int getType(ButtonPanel panel)
   {  
      String s = panel.getSelection();
      try
      {
         return JOptionPane.class.getField(s).getInt(null);
      }
      catch(Exception e)
      {  
         return -1;
      }
   }     private class ShowAction implements ActionListener
   {
      public void actionPerformed(ActionEvent event)
      {  
         if (typePanel.getSelection().equals("Confirm"))
            JOptionPane.showConfirmDialog(
               OptionDialogFrame.this,
               getMessage(),
               "Title",
               getType(optionTypePanel),
               getType(messageTypePanel));
         else if (typePanel.getSelection().equals("Input"))
         {  
            if (inputPanel.getSelection().equals("Text field"))
               JOptionPane.showInputDialog(
                  OptionDialogFrame.this,
                  getMessage(),
                  "Title",
                  getType(messageTypePanel));
            else
               JOptionPane.showInputDialog(
                  OptionDialogFrame.this,
                  getMessage(),
                  "Title",
                  getType(messageTypePanel),
                  null,
                  new String[] { "Yellow", "Blue", "Red" },
                  "Blue");
         }
         else if (typePanel.getSelection().equals("Message"))
            JOptionPane.showMessageDialog(
               OptionDialogFrame.this,
               getMessage(),
               "Title",
               getType(messageTypePanel));
         else if (typePanel.getSelection().equals("Option"))
            JOptionPane.showOptionDialog(
               OptionDialogFrame.this,               getMessage(),
               "Title",
               getType(optionTypePanel),
               getType(messageTypePanel),
               null,
               getOptions(),
               getOptions()[0]);           
      }
   }   public static final int DEFAULT_WIDTH = 600;
   public static final int DEFAULT_HEIGHT = 400;     private ButtonPanel typePanel;
   private ButtonPanel messagePanel;
   private ButtonPanel messageTypePanel;
   private ButtonPanel optionTypePanel;
   private ButtonPanel optionsPanel;
   private ButtonPanel inputPanel;
   
   private String messageString = "Message";
   private Icon messageIcon = new ImageIcon("blue-ball.gif");
   private Object messageObject = new Date();
   private Component messageComponent = new SamplePanel();
 }
class SamplePanel extends JPanel
{  
   public void paintComponent(Graphics g)
   {  
      super.paintComponent(g);
      Graphics2D g2 = (Graphics2D) g;
      Rectangle2D rect = new Rectangle2D.Double(0, 0, getWidth() - 1, getHeight() - 1);
      g2.setPaint(Color.YELLOW);
      g2.fill(rect);
      g2.setPaint(Color.BLUE);
      g2.draw(rect);
   }   public Dimension getMinimumSize()
   {  
      return new Dimension(10, 10);
   }
}

解决方案 »

  1.   

    this是每个类内部创建好的对象,属性名是this
      

  2.   

    答:每一个非static 型内部类都含有一个指向外部类的对象的引用,这个引用就是:外部类类名.this。
    因此:OptionDialogFrame.this就是内部类ShowAction对象中指向外部类OptionDialogFrame类的对象的引用。即:该内部类ShowAction对象所指向的那个外部类的对象。
      

  3.   

    因为这个是内部类 要用 outclass.this来指代自己 普通的类直接用this表示自己
      

  4.   

    "outclass.this来指代自己"。当然不是指自己。而是内部类对象所引用的那个外部类对象。
      

  5.   

    An instance for class OptionDialogFrame in current context.
      

  6.   

    内部类保存了一个外部类对象的引用,内部类的创建也必须初始化这个引用。
    Outer o = new Outer();
    Outer.Inner i = o.new Inner();所以,在Inner类中,如果要引用外围类的对象,就要使用Outer.this,而this则是Inner类对象本身。
      

  7.   

    哥们,你记好,THIS只在本类中用,指向本类中的NEW对像哦!嘻嘻.........
      

  8.   

    这里指在当前,即ShowAction类(内部类)中的OptionDialogFrame类的一个对象句柄。
    结贴吧,3楼其实说得也很清楚了。hoho