Showing posts with label invisible. Show all posts
Showing posts with label invisible. Show all posts

Java invisible cursor

Complete source code below will show you, how to create invisible cursor in java.

************************************************************************
COMPLETE SOURCE CODE FOR : MakeCursorInvisible.java
************************************************************************


import java.awt.Toolkit;
import java.awt.Cursor;
import java.awt.Point;
import java.awt.Image;

import javax.swing.JFrame;

public class MakeCursorInvisible
{
//Create an empty byte array
byte[]imageByte=new byte[0];

Cursor myCursor;
Point myPoint=new Point(0,0);

//Create image for cursor using empty array
Image cursorImage=Toolkit.getDefaultToolkit().createImage(imageByte);

public MakeCursorInvisible()
{
//Create cursor
myCursor=Toolkit.getDefaultToolkit().createCustomCursor(cursorImage,myPoint,"cursor");

JFrame frame=new JFrame("Put your cursor into me");

//Set cursor for JFrame using created cursor(myCursor)
frame.setCursor(myCursor);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300,300);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}

public static void main(String[]args)
{
MakeCursorInvisible mci=new MakeCursorInvisible();
}
}


************************************************************************
JUST COMPILE AND EXECUTE IT
************************************************************************

How to know when a component has been made invisible or visible ???


In this example, we use button as component.

*************************************************************************
COMPLETE SOURCE CODE FOR : HowToKnowWhenComponentVisible.java
*************************************************************************


import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

import java.awt.event.ComponentListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

import java.awt.FlowLayout;

public class HowToKnowWhenComponentVisible
{
JFrame a=new JFrame("CLICK HERE");
JFrame b=new JFrame("FRAME TO STORE JBUTTON NAME'S MONSTER");

JButton c=new JButton("VISIBLE");
JButton e=new JButton("INVISIBLE");
JButton d=new JButton("MONSTER");

public HowToKnowWhenComponentVisible()
{
ComponentListener cl=new ComponentAdapter()
{
public void componentHidden(ComponentEvent evt)
{
JOptionPane.showMessageDialog(null,"MONSTER IS INVISIBLE");
}

public void componentShown(ComponentEvent evt)
{
JOptionPane.showMessageDialog(null,"MONSTER IS VISIBLE");
}
};

d.addComponentListener(cl);
b.add(d);

ActionListener al=new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
if(evt.getSource()==e)
{
d.show(false);
b.repaint();
}

if(evt.getSource()==c)
{
d.show(true);
b.repaint();
}
}
};

c.addActionListener(al);
e.addActionListener(al);
a.setLayout(new FlowLayout());
a.add(c);
a.add(e);

a.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
a.setSize(400,100);
a.setVisible(true);

b.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
b.setSize(400,100);
b.setLocation(400,400);
b.setVisible(true);
}

public static void main(String[]args)
{
HowToKnowWhenComponentVisible myObject=new HowToKnowWhenComponentVisible();
}
}


*************************************************************************
JUST COMPILE AND EXECUTE IT
*************************************************************************

RELAXING NATURE VIDEO