You have to use two class java.awt.Graphics and java.awt.Graphics2D to do this. It is used to load mouse event in your program. In following program I have create mouseCickEg class to do this. I also have use two variable to decide assign height and width for creating mouse event. I have use getContentPane() to add all these information into one panel.
Code:
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class mouseCickEg {
public static void main(String[] args) {
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame fsw = new JFrame("Test");
fsw.setAlwaysOnTop(true);
Component csw = new JPanel() {
@Override
public void paintComponent(Graphics gws) {
Graphics2D g2ws = (Graphics2D)gws.create();
g2.setColor(Color.graysw);
int wsw = getWidth();
int hsw = getHeight();
g2sw.fillRect(0, 0, wsw,hsw);
g2ws.setComposite(AlphaComposite.Clear);
g2ws.fillRect(w/4, h/4, w-2*(w/4), h-2*(h/4));
}
};
c.setPreferredSize(new Dimension(350, 350));
fsw.getContentPane().add(csw);
fsw.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fsw.pack();
fsw.setVisible(true);
com.sun.awt.AWTUtilities.setWindowOpaque(fsw,false);
}
}
Bookmarks