---
title: "impl与内部类"
author: "googya"
date: "2009-08-23T11:20:06Z"
tags: []
slug: "impl"
draft: false
lastmod: "2009-08-23T11:20:06Z"
id: 455737
url: "https://googya.iteye.com/blog/455737"
---

```jruby
# To change this template, choose Tools | Templates
# and open the template in the editor.

#puts "Hello World"
include Java
include_class javax.swing.JFrame
include_class javax.swing.JPanel
include_class javax.swing.JButton
include_class java.awt.event.ActionListener
include_class javax.swing.JOptionPane
include_class java.awt.Color


#include_class java.awt.Container
class ButtonFrame < JFrame
  def initialize
    super "Hello world Swing"
    setTitle__method "Button"
    set_size(300,200)
    panel=ButtonPanel.new
    getContentPane().add(panel)
    set_default_close_operation JFrame::EXIT_ON_CLOSE
    set_visible true
  end
end



class ButtonPanel <JPanel
  def initialize
    super
    yellowbutton=JButton.new("Yellow")
    redbutton=JButton.new("Red")
    bluebutton=JButton.new("Blue")
    add(yellowbutton)
    add(redbutton)
    add(bluebutton)   
    yellowbutton.addActionListener ActionListener.impl{ setBackground(Color::YELLOW) }
    bluebutton.addActionListener ActionListener.impl{ 
setBackground(Color::BLUE) }
    redbutton.addActionListener ActionListener.impl{ setBackground(Color::RED) }
      end
#  class Color_T
#      include ActionListener
#      def initialize(c)
#        @c=c
#      end
#      def action_performed(event)
#           setBackground(@c)
#      
#      end
#  end

  
  
end
  ButtonFrame.new
```


在用class Color_T的时候，出现问题了，Color_T是内部类，但是setbackground是外部类的方法，在Java中这个不存在访问的问题。但是JRuby中出现问题了，但是我还不清楚问题如何解决