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 9052707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:14:41+00:00 2026-06-16T13:14:41+00:00

I have written two classes, FullScreen , which contains the logic for the screenshot,

  • 0

I have written two classes, FullScreen, which contains the logic for the screenshot, and FullScreenGUI, which contains the logic for simulating the photo click effect.

The photo click effect is basically flashing the screen with white color for a short period of time, say 50ms after the screenshot is taken. It is produced by covering the whole screen by a JFrame with an opacity of 1%. The background is made white and then the opacity is changed from 1% to 100%, kept like that for 50ms, then back to 1%.

The FullScreen constructor takes two parameters, one for number of times to take screenshot, and the other for the duration in between.

The FullScreenGUI constructs a JFrame, maximises it, sets the background to white. When the fire() method is called, it changes the opacity as required to produce the effect.

The Question:

Using the code below I am able to produce the effect for the first time the screenshot is taken, but not for the subsequent clicks. Suppose, FullScreen constructor is called with the parameters (4,2) (i.e. to take 4 clicks each at 2 seconds duration), then the effect is produced nicely for the first click but not for the remaining 3 clicks. JFrame of the FullScreenGUI does not seem to come to front, so the effect is not visible. I have tried JFrame.setAlwaysOnTop(true), JFrame.toFront() but they don’t seem to bring the JFrame to the top.

There is no problem in taking the screenshot, but instead with the effect. Do you have any other ideas to produce it ?

Here is the code:

FullScreen.java

import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.imageio.ImageIO;
import javax.swing.Timer;
import javax.swing.filechooser.FileSystemView;

class FullScreen
{   
    int times, duration;
    Timer t;
    Robot r;
    BufferedImage bi;
    FullScreenGUI fg;

FullScreen(int tim, int duration) 
{
    fg = new FullScreenGUI();
    fg.setVisible(true);
    this.times = tim;
    this.duration = duration;
    try {
        r = new Robot();
    } catch (AWTException e) {
        e.printStackTrace();
    }
    System.out.println("Inside constructor");
    t = new Timer(duration*1000, new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {

            System.out.println("Inside action");
            if(times>0)
            {
                System.out.println("times: "+times);

                //Get the screenshot
                bi = capture();

                //Gives the path of the home directory. For windows, it'll go to your desktop
                FileSystemView filesys = FileSystemView.getFileSystemView();
                File fl = filesys.getHomeDirectory();
                saveImage(bi, fl);

                //Produces the "clicking" effect
                fg.setAlwaysOnTop(true);
                fg.toFront();
                fg.fire();

                times--;
            }
            else
                t.stop();
        }
    });
}

public void fire()
{
    t.start();
}

public void saveImage(BufferedImage source, File destination)
{
    System.out.println("Inside saveimage");
    if(destination.isDirectory())
    {
        System.out.println("destination: "+destination.getAbsolutePath());
        String tmp = destination.getAbsolutePath() + File.separator + "Screenshot";
        String str;
        int i=1;
        for(str=tmp; (new File(str+".png").exists()); i++)
        {
            str = tmp + "_" + String.valueOf(i);
            System.out.println("trying: "+str);
        }

        try {
            ImageIO.write(source, "png", new File(str+".png"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

public BufferedImage capture()
{
    System.out.println("Captured");
    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    return r.createScreenCapture(new Rectangle(d));
}

public static void main(String arg[])
{
    //click 4 times each at an interval of 2 seconds
    FullScreen f = new FullScreen(4,2);

    f.fire();
    while(f.t.isRunning());
}
}

FullScreenGUI.java

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class FullScreenGUI extends JFrame {

FullScreenGUI()
{
    setExtendedState(JFrame.MAXIMIZED_BOTH);
    setUndecorated(true);
    setResizable(false);
    setOpacity(0.01f);
    setAlwaysOnTop(true);

    setLayout(new BorderLayout());
    JLabel jl = new JLabel();
    jl.setBackground(Color.white);
    add(jl);        

    setDefaultCloseOperation(EXIT_ON_CLOSE);
}

public void fire()
{
    System.out.println("click");
    setVisible(true);

    try{

    setOpacity(1f);
    Thread.sleep(50);
    setOpacity(0.1f);

    }catch(Exception e) { e.printStackTrace(); }

    setVisible(false);
}

}
  • 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-16T13:14:42+00:00Added an answer on June 16, 2026 at 1:14 pm

    The source of the problem is Thread.sleep(50);.

    Don’t block the EDT (Event Dispatch Thread) – the GUI will ‘freeze’ when that happens. Instead of calling Thread.sleep(n) implement a Swing Timer for this task. See Concurrency in Swing for more details.

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

Sidebar

Related Questions

I have written two classes which contains same method (print). I want to access
Hi I work with netbeans. I have written a code which has two classes
I have written two jQuery functions, the simplified version of which run thus: $('button.class').not('.selected').on('click',
I have written two pieces of code which I intended to have identical outputs,
I have written an app in C which expects two lines at input. First
Hi I have a program written in C++ in which one or two functions
I have written two simple Java classes (one of them containing main(), and the
I have written two managed C++ wrappers for native C++ classes and I need
I have two almost identically classes written in js. I would like to make
I'm developing a library in which I have two groups of classes: A) 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.