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

  • SEARCH
  • Home
  • 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 8746189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:09:22+00:00 2026-06-13T12:09:22+00:00

Below is the code from Filthy Rich Clients by Romain Guy and Chet Haase

  • 0

Below is the code from “Filthy Rich Clients” by Romain Guy and Chet Haase

private class ImageViewer extends JComponent {
    private BufferedImage image, landscape;

    private ImageViewer() {
        try {
            image = ImageIO.read(new File("picture.png"));
            landscape = ImageIO.read(new File("landscape.jpg"));
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }

    @Override
    protected void paintComponent(Graphics g) {
        BufferedImage temp = new BufferedImage(getWidth(), getHeight(),
            BufferedImage.TYPE_INT_ARGB);
        Graphics2D g2 = temp.createGraphics();

        if (shadow.isSelected()) {
            int x = (getWidth() - image.getWidth()) / 2;
            int y = (getHeight() - image.getHeight()) / 2;
            g2.drawImage(image, x + 4, y + 10, null);

            Composite oldComposite = g2.getComposite();
            g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_IN, 0.75f));
            g2.setColor(Color.BLACK);
            g2.fillRect(0, 0, getWidth(), getHeight());
            g2.setComposite(oldComposite);
            g2.drawImage(image, x, y, null);
        } else {
            int x = (getWidth() - image.getWidth()) / 2;
            int y = (getHeight() - image.getHeight()) / 2;
            g2.drawImage(image, x, y, null);

            Composite oldComposite = g2.getComposite();
            g2.setComposite(AlphaComposite.SrcIn);
            x = (getWidth() - landscape.getWidth()) / 2;
            y = (getHeight() - landscape.getHeight()) / 2;
            g2.drawImage(landscape, x, y, null);
            g2.setComposite(oldComposite);
        }

        g2.dispose();
        g.drawImage(temp, 0, 0, null);
    }
}

It is a part of the code to obtain the following output with different states when checkbox is checked:-
enter image description here

What i dont understand is

1)what is the line

BufferedImage temp = new BufferedImage(getWidth(), getHeight(),
        BufferedImage.TYPE_INT_ARGB);

doing there because if I write only the following code and run nothing is obtained in the output.

BufferedImage temp = new BufferedImage(getWidth(), getHeight(),
        BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2 = temp.createGraphics();

    if (jcb.isSelected()) {
        int x = (getWidth() - image.getWidth()) / 2;
        int y = (getHeight() - image.getHeight()) / 2;
        g2.drawImage(image, x + 4, y + 10, null);
           }

2)What is the need to obtain g2 after creating the ‘temp’ bufferedImage? Can’t I do it directly like

Graphics2D g2=(Graphics2D)g.create();

3)What is practical difference between TYPE_INT_RGB and TYPE_INT_ARGB.?

  • 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-06-13T12:09:23+00:00Added an answer on June 13, 2026 at 12:09 pm

    This is double buffering:
    http://docs.oracle.com/javase/tutorial/extra/fullscreen/doublebuf.html

    You first draw on an off-screen image, which in this case is backed by a BufferedImage object referenced in the variable temp; then you do whatever to the off-screen image; finally, you print the result on the component, via g.drawImage(temp, …). This is not to have the user see glitches or artifacts due to the image being constructed directly on the screen.

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

Sidebar

Related Questions

Below is the code from internalRegister method of GCMRegistrar class static void internalRegister(Context context,
I got below code from http://msdn.microsoft.com/en-us/library/dd584174(office.11).aspx for adding custom property in webpart tool pane.
I am creating a random ID using the below code: from random import *
I don't know where I've got a mistake, when I fire below code from
HI: Below code is from RequestFactoryEditorDriver: /** * Returns a new array containing the
Below is the code from a plugin I use for sitemaps. I would like
Below is the code from a plugin for Joomla. It works on it's own
Below is my code from my activity. I call setKey() to set the key,
Using the code below (from a console app I've cobbled together), I add seven
I have the code below: from the getData function im trying to call get_xml

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.