From: Oti <oh...@ya...> - 2003-02-25 12:57:48
|
[ Byron Hammond ] > I'm having some problems doing some graphics stuff at the moment. > I just want to do some simple drawing inside a JPanel. > > I derive my class from JPanel and override paintComponent(Graphics g) > (as recommended by the Java swing tutorials) but I get an error > message, now matter how I try to do it. > > I realize JPanel only inherits paintComponent from JComponent, but as > I said, it doesn't matter what I do... > Any help is appreciated. > > class a(JPanel): > paintComponent(self, Graphics): > JPanel.paintComponent(self, Graphics) > Graphics.drawRect(1, 1, 100, 100) > > AttributeError: class 'javax.swing.JPanel' has no attribute > 'paintComponent' > > or... > > class a(JPanel): > paintComponent(self, Graphics): > JComponent.paintComponent(self, Graphics) > Graphics.drawRect(1, 1, 100, 100) > > AttributeError: class 'javax.swing.JComponent' has no attribute > 'paintComponent' Byron, since method paintComponent(Graphics) is protected on JComponent, use the self.super__ syntax: class a(JPanel): paintComponent(self, Graphics): self.super__paintComponent(Graphics) Graphics.drawRect(1, 1, 100, 100) The syntax you suggested: JPanel.paintComponent(self, Graphics) is for overriding public methods. Hope this helps, and best wishes, Oti. __________________________________________________ Do you Yahoo!? Yahoo! Tax Center - forms, calculators, tips, more http://taxes.yahoo.com/ |