Skip to content

Commit

Permalink
mudando o modo de sobreescrever o metodo paintComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
HugoLnx committed Jun 12, 2010
1 parent 278ab24 commit f8186d1
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions no_jruby.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -18,12 +18,9 @@
java_import java.awt.geom.Line2D java_import java.awt.geom.Line2D


class MyJPanel < JPanel class MyJPanel < JPanel
# criação do método paint_component # criação do método paint, que ira sobreescreve
# poderiamos sobreescrever o metodo paintComponent aew mesmo # o metodo original do JPanel
# teriamos que trocar o nome do metodo para paintComponent def paint(g)
# e apagar o alias abaixo
# só fiz dessa maneira visando respeitar a convenção ruby =D
def paint_component(g)
# em ruby não faz muita diferença isso, jah q para recuperar # em ruby não faz muita diferença isso, jah q para recuperar
# o size não tem tanta verbosidade quanto em java xD # o size não tem tanta verbosidade quanto em java xD
size = self.size size = self.size
Expand All @@ -44,9 +41,6 @@ def paint_component(g)
# Desenha o texto "This is a test!" # Desenha o texto "This is a test!"
g.draw_string 'This is a test!',100,150 g.draw_string 'This is a test!',100,150
end end
# alias que irá "substituir" o método paintComponent(q precisa ser sobreescrito)
# pelo método paint_component
alias paintComponent paint_component
end end


# Cria um frame # Cria um frame
Expand Down

0 comments on commit f8186d1

Please sign in to comment.