Issue222808
Created on 2000-11-18.19:01:12 by bckfnn, last changed 2000-11-18.22:22:53 by bckfnn.
| Messages | |||
|---|---|---|---|
| msg54 (view) | Author: Finn Bock (bckfnn) | Date: 2000-11-18.19:01:12 | |
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()
|
|||
| msg55 (view) | Author: Finn Bock (bckfnn) | Date: 2000-11-18.22:22:53 | |
The paintComponent issue is not a bug. The method is protected and the proper way of calling a protected method in the superclass is:
self.super__paintComponent(g)
I can't remember what the assert issue was all about, but it is also fixed now.
|
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2000-11-18 19:01:12 | bckfnn | create | |
Supported by Python Software Foundation,
Powered by Roundup