Results 1 to 4 of 4
  1. #1
    robc3129 is offline Member
    Join Date
    Sep 2013
    Posts
    6
    Rep Power
    0

    Default Letterbox screen mask

    Hi guys

    I'm relatively new here and quite new to Java Swing too so please excuse my ignorance.

    What i'm trying to do is find out if there's a way of creating a kind of screen masking class in java. Something whereby the screen is overlaid with an opaque frame with a viewable letterbox style window across the middle which would move with the mouse. The way i have been going about this is to create two JFrame's, one for the top of the screen and one for the bottom. The JFrames leave about a 100px gap in the centre of the screen and then update their heights and locations when the mouse moves. This kinds of gives the effect i'm looking for but it;s not consistent across platform for some reason (not working too well in Windows 7) and it's also very laggy.

    Can anyone suggest of a way that i might be able to achieve what i'm looking for?

    Thanks in advance!

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,760
    Rep Power
    5

    Default Re: Letterbox screen mask

    Using two JFrames is probably not the way to go but it is hard to know without seeing your code. Also, I am still not entirely sure what you are trying to do. Please submit an Short, Self Contained, Correct Example to demonstrate what you have done thus far.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    robc3129 is offline Member
    Join Date
    Sep 2013
    Posts
    6
    Rep Power
    0

    Default Re: Letterbox screen mask

    Thanks jim829.

    Sorry it's taken me so long to follow up to this thread...

    Here's a VERY crude example of what i was trying to do. Please bare in mind that this was just something quickly knocked up to see if this approach would likely work...

    Java Code:
    import java.awt.Color;
    import java.awt.Dimension;
    import javax.swing.JFrame;
    import org.jnativehook.mouse.NativeMouseEvent;
    
    /**
     *
     * @author rob
     */
    public class Mask implements Runnable{
        private static JFrame frameTop = new JFrame("Mask Top");
        private static JFrame frameBottom = new JFrame("Mask Bottom");
        
        private static Mask mask  = null;
        
        private static final int screenWidth = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds().width;
        private static final int screenHeight = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds().height;
        
        public static synchronized Mask getInstance() {
            if (mask == null) {
                mask = new Mask();
            }
    
            return mask;
        }
    
        @Override
        public void run() {
            frameTop.setPreferredSize(new Dimension(screenWidth, 500));
            frameBottom.setPreferredSize(new Dimension(screenWidth, 500));
            
            frameTop.setSize(new Dimension(screenWidth, 500));
            frameBottom.setSize(new Dimension(screenWidth, 500));
            
            try{
                frameTop.setOpacity(new Float(0.8));
                frameBottom.setOpacity(new Float(0.8));
            }catch(Exception e){}
            
            frameTop.setLocation(0, 0);
            frameBottom.setLocation(0, screenHeight);
            
            frameTop.setUndecorated(true);
            frameTop.setBackground(new Color(0,0,0,0));
            frameBottom.getContentPane().setBackground(Color.GREEN);
            
            frameTop.setAlwaysOnTop(true);
            frameBottom.setAlwaysOnTop(true);
            
        }
        
        public static void enable(){
            frameTop.setVisible(true);
            frameBottom.setVisible(true);
        }
        
        public static void disable(){
            frameTop.setVisible(false);
            frameBottom.setVisible(false);
        }
        
        
        public void handleMove(NativeMouseEvent e) {
            frameTop.setSize(screenWidth, e.getY() - 10);
            
            frameBottom.setSize(screenWidth, screenHeight - e.getY() - 10);
            frameBottom.setLocation(0, screenHeight);
    
        }
    }
    Not sure if Graphics2D would be a better approach for example.

    Again, any ideas or advice would be greatly appreciated.

    Cheers

  4. #4
    robc3129 is offline Member
    Join Date
    Sep 2013
    Posts
    6
    Rep Power
    0

    Default Re: Letterbox screen mask

    Just another thought on this one... Is there any way you are able to harness hardware acceleration using Java rather than have the CPU responsible for the rendering of jFrames etc? I wonder if this would get rid of the lagging that i'm experiencing?

    Any other thought would be very much appreciated!

    Cheers

Similar Threads

  1. BufferedImage red mask
    By Szinek in forum AWT / Swing
    Replies: 0
    Last Post: 06-06-2013, 09:11 PM
  2. Input fewer characters-mask?
    By Feilin in forum AWT / Swing
    Replies: 0
    Last Post: 02-10-2012, 01:50 AM
  3. Creating a mask for animation
    By micah11 in forum New To Java
    Replies: 2
    Last Post: 10-25-2010, 04:31 AM
  4. How to mask password characters
    By Roselicious in forum New To Java
    Replies: 4
    Last Post: 04-16-2010, 02:26 AM
  5. How to Mask input string
    By nmc.091 in forum New To Java
    Replies: 1
    Last Post: 02-23-2009, 03:49 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •