Message54
from java.awt import *
from java.awt.geom import *
from javax.swing import *
class RoundButton (JButton):
def __init__ (self, label):
JButton.__init__(self, label)
s = self.preferredSize
w = h = max(s.width, s.height)
self.preferredSize = (w, h)
self.contentAreaFilled = 0
self.shape = None
def paintComponent (self, g):
if self.model.armed:
g.color = Color.lightGray
else:
g.color = self.background
g.fillOval(0, 0, self.size.width - 1, self.size.height - 1)
#JButton.paintComponent(self, g)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
At runtime, it will complain that JButton has no
paintComponent
attribute.
def paintBorder (self, g):
g.color = self.foreground
g.drawOval(0, 0, self.size.width - 1, self.size.height - 1)
def contains (self, x, y):
shape = self.shape
if not shape or not shape.bounds.equals(self.bounds):
self.shape = Ellipse2D.Float(0, 0, self.width, self.height)
return self.shape.contains(x, y)
def main ():
button = RoundButton("Jackpot")
button.background = Color.green
frame = JFrame()
pane = frame.contentPane
assert(pane)
^^^^^^^^^^^^^
if this line removed, there will be NullPointerException at runtime.
pane.background = Color.yellow
pane.add(button)
pane.layout = FlowLayout()
frame.size = (150, 150)
frame.visible = 1
if __name__ == "__main__":
main()
|
|
| Date |
User |
Action |
Args |
| 2008-02-20 17:16:39 | admin | link | issue222808 messages |
| 2008-02-20 17:16:39 | admin | create | |
|