Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1109111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:11:02+00:00 2026-05-17T02:11:02+00:00

Bear with me… I don’t think this is too subjective but maybe I’m wrong.

  • 0

Bear with me… I don’t think this is too subjective but maybe I’m wrong.

Recently I wanted to factor out some repetitive code which drew a custom Bitmap background on our BlackBerry app.

(This question is not really about BlackBerry though, so I’ll provide some details here about the BB GUI so that non-BB Java people can weigh in…)

The class FullScreen is from the BB API – it has a method paint(Graphics) which the framework calls to draw the screen and any components added to it. It’s possible to override this to do custom painting – like drawing a Bitmap background before any other painting happens (newer BB APIs provide a Background class but our app has to work on older phones).

I wanted to have a bunch of screens all with the same background, which each did some kind of custom painting… here’s what I came up with:

abstract public class BGFullScreen extends FullScreen {
    Bitmap bg;

    public BGFullScreen(Manager mgr, long style) {
        super(mgr, style);
        bg = Bitmap.getBitmapResource("bg.jpg");
    }

    abstract protected void innerPaint(Graphics g);

    protected void paint(Graphics g) {
        g.drawBitmap(new XYRect(0, 0, bg.getWidth(), bg.getHeight()), bg, 0, 0);

        innerPaint(g);

        super.paint(g);
    }
}

Each screen will then subclass this abstract class and implement innerPaint(). This way when the BB framework calls the paint() method, each screen can have custom painting stuff happen AFTER the background is drawn (so any painting happens on top of the background) but BEFORE the components of the screen are drawn, when FullScreen.paint() is called.

(I came up with this because I’ve been studying Common Lisp at home, and it occurred to me that what I wanted to do was something like the interleaved method combination in CLOS)

Here’s a sample implementation of the abstract class above:

public class MainAppScreen extends BGFullScreen {

    public MainAppScreen() {
        super(new VerticalFieldManager(), 0);
        // add some components to the screen:
        add(new ButtonField(...));
        add(...)
    }

    protected void innerPaint(Graphics g) {
        // stuff drawn will be on top of background and under buttons 
        g.draw(...)
    }
}

Basically I want a child class to implement a method gets called in-between its parent’s implementation and its grandparent’s implementation of the same method. I couldn’t figure out any other way to do this in Java…

Is this idomatic Java? Is this actually really common and it’s a dumb question? Is this actually horrible design? (BB experts, how can I do this any other way?)

Edited to add: This does work as described – the drawing happens in the order I want.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T02:11:03+00:00Added an answer on May 17, 2026 at 2:11 am

    Yes, and not only idiomatic Java, but OO, in general. It is called template method

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(Bear with me, I promise this gets to shebang and windows.) I have about
These two may look like they have no correlation but bear with me! In
Bear with me while I explain my question. Skip down to the bold heading
Please bear with me, I'm just learning C++. I'm trying to write my header
A longwinded question - please bear with me! I want to programatically create an
I am new to visual studio/asp.net so please bear with me. Using vs 2005
A beginner question, bear with me: I'm just wondering under what circumstances one should
Ok, bear with me guys and girls as I'm learning. Here's my question. I
I'm still fairly new to ASP.NET development so bear with me. I'm going to
I'm just beginning to use Regex so bear with my terminology. I have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.