Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Inheriting painted-figures  RSS feed

 
svein kristian nykaas
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, My problem is this; I'm trying to create an own class for the GUI-parts of my application, and then I want that GUI-parts to be inherited by another class while retaining everything on the original class and just adding changes to it.

As you can see in the source bellow, I want to paint a rectangle in the upper-left corner of the GUI, however since I already painted in the GUI-class all that gets overwritten by the new Location class, which only creates the rectangle and painting over previous changes.

How can I then get to keep the lines created in GUI over to Location and also be able to create new things in the paint of Location?


GUI-class


class inheriting GUI

 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Call super.paint(g). But you shouldn't override any painting methods of any window (JFrame, JDialog, JWindow) at all. Instead, you should create a JPanel sub class and set that as the content pane of the JFrame. You will then need to override paintComponent, not paint.
 
svein kristian nykaas
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you so much! I'll look into the JPanel thing .
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!