Change Mouse Cursor In Java

Feb 24, 2014

I decided to change the mouse cursor based on the theme of the game. This is the code that I wrote for the declaration of the cursor:

ImageIcon imageIcon = new ImageIcon ("cursor / cursor.gif");
Image img = imageIcon.getImage ();
Toolkit t = Toolkit.getDefaultToolkit ();
Cursor cursor = t.createCustomCursor (img, new Point (0,0), "cur");
this.setCursor (cursor);

Having to click on different JButton in the menu of the game, a few screens later, I have to manage something in particular, such as determining the point of clicks that allows the action to take place?

In particular I would like to change the point of hotspots. The size of 136x163 is cursor.gif

Image - TinyPic - Servizio di hosting d'immagini, condivisione immagini & hosting di video gratuito

As you can see in the image I want to create the point of hotspots in the red dot of the image. How should I do to pass the correct coordinates in Point?

View Replies


ADVERTISEMENT

Getting Name Of Component For Mouse Cursor Position?

Nov 4, 2014

I am developing an application where blind person can interact with computer i have completed the part where computer responds as per command given by user.The part where i am stuck is i want to give voice feedback as user moves the curser for example if mouse is on d drive then user should get feedback that its d drive....i want to do it for whole windows ...

View Replies View Related

Make Mouse Cursor Visible On Movement

Mar 25, 2014

I've been creating a digital clock using Java, and have made the mouse cursor invisible after a set period of time (40-seconds) and had the thought to make it visible again if mouse was moved.

Here's the code that makes it invisible:

ActionListener mouseTimeout = new ActionListener() {
public void actionPerformed(ActionEvent e) {
setCursor(blankCursor);
}
};
/* Make mouse cursor disappear after 40 seconds */
Timer mTimeout = new Timer(40000, mouseTimeout);
mTimeout.start();

And here is what I have so far for making it visible again:

MouseMotionListener mouse = new MouseMotionListener() {
@Override
public void mouseDragged(MouseEvent e)
{
}
@Override
public void mouseMoved(MouseEvent e)
{
}
};

I have tried using "setCursor(DEFAULT_CURSOR)" but NetBeans says that it "cannot find symbol" .....

View Replies View Related

Swing/AWT/SWT :: Replacing Regular Writing Cursor For System Mouse Pointer When Hovering JTextField?

Apr 23, 2015

When I hover over a JTextField, I want to change the writing cursor from this to the system regular mouse pointer. How could I do it?

View Replies View Related

How To Change Color Of Cursor

Jan 17, 2014

I'm programming in school using Netbeans and we've just started with graphical programming (i.e JPanel, JClass, JFrame). This is my first assignment and the purpose of this program is that when you press the mouse you will fill 4 circles with diffrent colors. I've managed to draw 4 circles with diffrent colors but I want my cursor to change color simultaneously. Here's my code so far ....

//Java klass "Klick"
public class Klick {
//Medlemsvariabler.
private int x = 0;
private int y = 0;
private int r = 1;
public int antal = Rityta.antalKlick;

[Code]...

View Replies View Related

Change Cursor On Mouseover A Rectangle

Jan 13, 2014

I want that the cursor change when the mouse is over one of the rectangles. Rectangles are displayed but nothing happens when the mouse is over.

class Resizing extends JPanel {
java.awt.List myGuiList = new java.awt.List();
java.util.List<Rectangle> paths = new ArrayList<Rectangle>();
public Resizing() {
paths.add(new Rectangle(100, 100, 75, 50));
paths.add(new Rectangle(200, 100, 75, 50));

[Code] .....

View Replies View Related

Change Cursor On Mouseover A Rectangle

Jan 13, 2014

I want that the cursor change when the mouse is over one of the rectangles. Rectangles are displayed but nothing happens when the mouse is over.

class Resizing extends JPanel {
java.awt.List myGuiList = new java.awt.List();
java.util.List<Rectangle> paths = new ArrayList<Rectangle>();
public Resizing() {
paths.add(new Rectangle(100, 100, 75, 50));
paths.add(new Rectangle(200, 100, 75, 50));

[Code] ......

View Replies View Related

Getting Mouse Click Method To Change Previous Object Properties?

May 19, 2014

I am having trouble with a mouse click method. In short I have a hexagon grid, and every time I want to click on one particular hexagon I want the color of the hexagon to change to blue(by default the color is grey). This part works, but when I go to click on another hexagon I want the color of the previous hexagon to change back to grey while at the same time changing the color of the current hexagon clicked to blue. So in other words, I only want one hexagon blue at a time. How might I do this?

I have a hexagon class for one particular hexagon, and a hexmap class for multiple hexagons. I know I should probably be handling mouse clicks in the hexmap since it deals with the whole thing. But I cannot say something like hexagon.setColor within a mouselistener in that class(it gives me a lot of issues). Here is some of my code :

public class Hexagons()
public Hexagons(HexMap theMap, int mapRow, int mapCol, int width, int height) {
this.map = theMap;
this.row = mapRow;
this.col = mapCol;
this.width = width;
this.height = height;

[Code] ....

View Replies View Related

Java Game In Eclipse Mouse Not Moving

Apr 24, 2015

try to make a game in this code i am trying to make the basics i have made a mouse it should move the game code is

import java.applet.Applet;
import java.awt.*;
public class Game extends gameLoop {
public void init()
{
setSize( 854 , 480);
Thread th = new Thread (this);

[code]...

View Replies View Related

Java Swing - Mouse Over To Highlight Desktop Icon

Jul 7, 2014

When we place the mouse cursor over an desktop icon it will get highlighted. How can I achieve this through java swings?

View Replies View Related

Java 2D Drawing Application - Shape Should Be Drawn As Mouse Is Dragged

Nov 4, 2014

Java 2D Drawing Application. The application will contain the following elements:

a) an Undo button to undo the last shape drawn.

b) a Clear button to clear all shapes from the drawing.

c) a combo box for selecting the shape to draw, a line, oval, or rectangle.

d) a checkbox which specifies if the shape should be filled or unfilled.

e) a checkbox to specify whether to paint using a gradient.

f) two JButtons that each show a JColorChooser dialog to allow the user to choose the first and second color in the gradient.

g) a text field for entering the Stroke width.

h) a text field for entering the Stroke dash length.

I) a checkbox for specifying whether to draw a dashed or solid line.

j) a JPanel on which the shapes are drawn.

k) a status bar JLabel at the bottom of the frame that displays the current location of the mouse on the draw panel.

If the user selects to draw with a gradient, set the Paint on the shape to be a gradient of the two colors chosen by the user. If the user does not chosen to draw with a gradient, the Paint with a solid color of the 1st Color.

Note: When dragging the mouse to create a new shape, the shape should be drawn as the mouse is dragged.

Java Code:

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.Point;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;

[Code] ....

Missing things for the code check boxes for color gradients, line width and dashed.

View Replies View Related

JavaFX 2.0 :: Set Busy Cursor For A Scene

May 15, 2014

My problem is simple. Just set busy cursor on a scene. The scenarios is like this: I have simple application with a button on it. When I click the button, I will:

1. Set mouse cursor to BUSY
2. Do some work
3. Set mouse cursor back to DEFAULT.
 
I search the web and found some sample codes to set cursor. But they don't satisfy my need. So I wrote a simple application:
 
public class MainFormApp extends Application {
  @Override
  public void start(Stage stage) throws Exception {
       stage.initStyle(StageStyle.DECORATED);
        Pane root = new Pane();
        root.setPrefSize(500, 300);
        Button btn = new Button("Click me");       

[Code] ....
 
When I run application and click the button, cursor does not change to BUSY. I also tried to use Platform.runLater() but no luck.

View Replies View Related

Invalid Operation At Current Cursor Position

Sep 30, 2014

I have now slowly moving on the learning Database Connectivity.Found a simple example on one site and tried to execute it, Creating a database, connecting to it and displaying the output.

I am getting trouble with recordset in displaying all the records in the badabase. It displays the very first record correctly but if I try to enclose it in while(rs.next()) loop, it generates an error message saying "Invalid operation at current cursor position".

package database_console;
import java.sql.Statement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.ResultSet;

[code]....

View Replies View Related

Color Memory - How To Make Cursor Appear In Each Guess Box

Dec 7, 2014

This is my code. It is running great until I enter in the final color and hit enter. I get an Array Index out of bounds error, which I show at the bottom. I have fiddled with it, by moving the all answers correct into an if..else statement, hoping it would fix it. Needless to say, it didn't work.

Also, I am trying to figure out how to make the cursor appear in each guess box. It does in the first one, but after I hit enter, I have to click in the box each time to get one.

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class RobertMaloneChapter17 extends JFrame
{
//final variables to set the width and height of my frame

[Code] ....

My Errors:

Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 5
at RobertMaloneChapter17$Listener.actionPerformed(RobertMaloneChapter17.java:67)
at javax.swing.JTextField.fireActionPerformed(JTextField.java:508)
at javax.swing.JTextField.postActionEvent(JTextField.java:721)

[Code] ....

View Replies View Related

JavaFX 2.0 :: How Add Text At Cursor Position In HTMLEditor

Jun 13, 2014

I know how add new button to HTMLEditor, and I want set to my button action to paste some text in the current cursor position.

//HTMLEditor html;//String IMAGE_URL = "http://...";Node node = html.lookup(".top-toolbar");
if (node instanceof ToolBar) {   ToolBar bar = (ToolBar) node;  
ImageView graphic = new ImageView(new Image(IMAGE_URL, 32, 32, true, true));  
Button myButton = new Button("", graphic);  bar.getItems().add(myButton); 
myButton.setOnAction(new EventHandler<ActionEvent>() {  
@Override   public void handle(ActionEvent arg0) {  
//needs code  
}   });}

View Replies View Related

JDBC :: CLOBs - Retrieve Set Of Records Via Ref Cursor

May 21, 2015

I am working on a Java program that calls a stored procedure in an Oracle 11.2g database and retrieves a set of records via a ref cursor. The program follows the standard Connection/CallableStatement/ResultSet pattern. A ResultSet object is used to access and iterate through the returned cursor, processing each record in turn.
 
One of the database fields returned in the cursor is a CLOB, which I'm retrieving using the NClob class's getNClob() method. Two other methods - length() and getSubString() are then used to get the length of the CLOB and copy of it off to a String object respectively.
 
The problem is that these latter two method calls are relatively slow, taking around 80ms to complete for modestly sized CLOBs of, say, around 10KB in size.
 
Is this the most efficient way to access a CLOB and retrieve its contents? If so, is there anything I can do, to make it run faster?

View Replies View Related

JDBC :: New OJDBC 7 12.0.1.2 Maximum Cursor Limit Exceeded

Mar 5, 2015

We are running a set of unit tests using the latest ojdbc 7 driver and the highest open cursor keeps going up, until it hits our 300 limit, then throws the cursor limit exception. If we run these tests using ojdbc 12.0.1.1, the highest open cursor stays at 17 and doesn't cause this exception.
 
The query used to monitor these cursors is below:

SELECT  max(a.value) as highest_open_cur, p.value as max_open_cur FROM v$sesstat a, v$statname b, v$parameter p WHERE  a.statistic# = b.statistic#  and b.name = 'opened cursors current' and p.name= 'open_cursors' group by p.value

Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
Java 8 version 31

View Replies View Related

How To Change File Permission In Java

Jun 26, 2014

How to change file permission in java....

View Replies View Related

Change Java Security Settings

Dec 8, 2014

I have made a very simple Java applet.

<HTML>
<BODY>
<CENTER>
<APPLET CODE="HelloWorldApp.class" WIDTH="862" HEIGHT="512"></APPLET>
</CENTER>
</BODY>
</HTML>

But when i try to open it i get the message: Application Blocked. Click for details.

- The list i see doesn't work
- If i click Ignore nothing happens
- If i click reload nothing happens

When i read and search the net i have to change my java security settings. The security setting are HIGH and i cannot change that.But i can fill in an Exception Site List...The hello.html file is on my NAS : file:///X:/Lantronix/hello.html..I fill this in the exception Site list -> I get a message that it is a security risk to add this location.

View Replies View Related

Incremental Change To Existing Java Program

Aug 8, 2014

I would like to make an incremental change to an existing Java program. And the program has been installed on the user's machine. Now I only want to do an incremental download (to minimize the download time) to update the program.

View Replies View Related

Java Program That Calculates Change For A Cashier

Jul 23, 2008

Its just two problems:

1.Write a Java Program that calculates the change for a cashier. The program requests the cost of the item. The user then types in the cost. The program then outputs the cost of the item including the sales tax (use 6% as the sales tax value). The program next requests and recieves the amount tendered by the customer. Finally, the program outputs a summary of all figures, including the amount of change due to the customer. Name the program as Change.java.

This program has the following attributes and methods:

double cost;
double tax;
double payment;
double getCost();
double getTax();

[code].....

2. Create a java program named Numbers whose main() method holds two integer variables. Assign values to the variables. Pass both variables to methods named sum() and difference(). Create the methods sum() and difference(); these compute the sum and difference between the values of two arguments, respectively. Each method should perform the appropriate computation and display the results. Name the program as Numbers.java.

View Replies View Related

Swing/AWT/SWT :: Code Prevent Cursor From Moving When Inside A Cell Of JTable

Jun 24, 2014

Tried creating a simple sample but all works as expected.

The following code prevents the cursor from moving when inside a cell of a JTable.

public void keyPressed(KeyEvent e) {
if ( (e.getKeyCode() == KeyEvent.VK_KP_LEFT) || (e.getKeyCode() == KeyEvent.VK_KP_RIGHT)
|| (e.getKeyCode() == KeyEvent.VK_RIGHT) || (e.getKeyCode() == KeyEvent.VK_LEFT) )
{
//Do nothing
e.consume();
}
}
});

When editing a cell, the existing code would use the right/left cursor keys to move from cell to cell as opposed to from character to character when editing a cell. I planned to override the functionality by tossing in the above code as a test to see if it stops the functionality before I override it.

After placing in the above code, the above functionality no longer occurs, but now the cursor moves within the cell as I wanted which is to move from character to character instead of cell to cell. Its great it works, but it really shouldn't. Essentially the default behavior has been restored when it should have really disabled the left/right keys.

I assume there is some underlying class someplace that is doing something to affect the behavior. Since a sample can't be provided I am wondering in what scenarios would the e.consume() restore default functionality?

View Replies View Related

Why Cannot Change Size Of TextField In Java For Calculator Application

Jan 13, 2014

package name;swing library found in javax called to use the graphical contents.

import javax.swing.*;
//creating the contents for the calculator
public class calc {
JButton btn1= new JButton("1 ");
JButton btn2= new JButton("2");
JButton btn3= new JButton("3");

[code]....

I have tried different sizes for the 'TextField' but when I change the size, the position changes instead of the size itself.

View Replies View Related

Directly Change Java Code Using User Input

Nov 16, 2014

I'm quite new to java programming, but eager to learn. I was wondering how to change actual java code, using user input. For example:

Java Code: int x = 0;
// Start the program and enter 3
// Now the code is
int x = 3 mh_sh_highlight_all('java');

View Replies View Related

Creating Cursor For A Game That Moves Square By Square - Removing Trailing Images

Aug 31, 2014

I'm trying to create a cursor for a game that moves square by square. While it will move to the next square, though, it leaves the image of the previous cursor on the last square it was on.

As a visual explanation, this is what the program looks like on launch:

This is what it's suppose to look like after you press the right arrow key once (made by forcibly changing launch coordinates):

And this is what it actually looks like after you press the right arrow key once:

Here is the code for the program:

package cursortest;
import javax.swing.*;
import java.awt.*;
import javax.imageio.*;
import java.io.*;
import java.awt.event.*;
public class CursorTest extends JPanel implements KeyListener{

[Code] ......

I'm fully aware that I could just use g.clearRect on the area and remove it for sure, but I know for a fact I shouldn't have to as I have another program I made a long time ago that tried to do something similar without needing to resort to that.

View Replies View Related

Set Background In Mouse Adapter

Sep 9, 2014

import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;
 import java.awt.BorderLayout;
import java.awt.Color;

[Code] .....

Isn't changing my backgrounds in my MouseAdapter I keep getting these errors:

at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)

[Code] ....

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved