Faulty Mouse Point Detection?

May 26, 2014

So I'm making buttons for a game I'm making. The graphics work, at least to the extent that I don't have to fix them yet. However, click detection is a bit iffy. For example pressing where the black line is in the first picture below, triggers a response. Now obviously that point is not on the button. I have tested the buttons bounding box by drawing a rectangle around it, using it's getBounds() method (which is also used for click detection) and it draws a perfect rectangle around it. So then I tested the mouse click points and it turns out that even though the button is placed at y = 100, at the black line, the mouse point is also equal to 100... Now, why that is happening, especially because, if I place the button in the top left corner, the mouse detection correctly detects the top pixels and there is no offset...

View Replies


ADVERTISEMENT

Center Is Determined By Location Of Point Where Mouse Is Pressed

May 6, 2014

The goal is to desplays circles (max of 30) of fixed radius = 20, with the rightmost circle drawn in blue and left most circle in red and the rest are in white. The center is determined by the location of the point where the mouse is pressed. the number of circles is equivalent to number of mouse has been pressed_ the circles will be drawn only when you push the "draw" button.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.JPanel;
public class CirclePanel extends JPanel {
private final int WIDTH = 500, HEIGHT = 300;
private final int RDIUS = 20;
private final int MAX = 30;

[code]...

View Replies View Related

Swing/AWT/SWT :: Icons Should Drag Starting At Point Where Mouse Originally Clicked Down

Apr 23, 2014

I am working on a simple app that should emulate a desktop with some icons that you can drag around. I was instructed to use the MouseListener and MouseMotionListener. The icons should drag starting at the point where the mouse originally clicked down on it (ie not dragging from the top right corner).

I am drawing my icons to a jpanel, and I seem to be having two problems:The hitboxes are offThe icon is being dragged from the top right corner, despite having setup up a mouse offset at the beginning of the drag..Here are the relevant classes, the Desktop.draw() method is being called from my DrawPanel

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Desktop implements MouseListener, MouseMotionListener{
static DesktopIcon[] icons;

[code]...

View Replies View Related

Constructs And Initializes A Point With Same Location As Specified Point Object

Jun 5, 2014

I was reading the oracle java tutorial under: URL....Here's the code for the Point class:

public class Point {
public int x = 0;
public int y = 0;
//constructor
public Point(int a, int b) {
x = a;
y = b;
}
}

and in the Rectangle class you have the following constructor:

public Rectangle(Point p, int w, int h) {
origin = p;
width = w;
height = h;

If we create a new Point object like this:

Point originOne = new Point(23, 94);

and then a new Rectangle object like this:

Rectangle rectOne = new Rectangle(originOne, 100, 200);

Will that set originOne to point to the object Point at (23, 94). just want to make that this is the meaning of this statement: Point(Point p)Constructs and initializes a point with the same location as the specified Point object.

View Replies View Related

Object Motion Detection

Mar 25, 2014

Any examples for object detection or motion detection program..

View Replies View Related

Face Detection On Camera?

Sep 3, 2014

I want to do face detection on the camera.

View Replies View Related

Directed Graph Cycle Detection

Jan 4, 2015

I have some problem checking if a directed graph has a cycle or not. So I have a given rooted directed graph, and find if there at least one existing cycle.

For example, I have to input the Root Node, followed by a number of nodes, the nodes in the graph, number of edges, and the adjacency list representing the edges. Each entry in the adjacency list contains a pair of nodes. The ordering of the nodes in the pair represents the direction of the edge. An entry A, B means that there is an edge from A to B. Nodes in each pair is separated by a space. One input per line.

And the output should display whether the directed graph has a cycle or not.

Sample input:

A //Root Node
6 //Number of Nodes
A //Nodes in Graph
B
C
D
E
F
6 //Number of edges
A B //Adjacency list representing the edges
B C
C D
C F
F E
E B

Output:
Cycle!

Graph Representation:

Based on the illustration above, the graph has one cycle. The cycle exists in nodes B, C, F and E.

View Replies View Related

Object Collision Detection - Character Freezes

Dec 2, 2014

I don't understand why when I collide into my objects my character freezes. Such as if I collide into collision() I can go left and right but, not up and if I collide into collision2() I freeze in all places but, if I collide into the bounds I made I can still go in all directions without problems. The xa and ya are still being set to 0.

package com.questkings.game;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.event.KeyEvent;

[Code] .....

View Replies View Related

Pong Game - Y Axis Collision Detection

Jan 28, 2014

I have made a "Pong" game and how to check if the ball has hit the top or the bottom of a paddle, however I do know how to check if it has hit the left or right side:

Java Code:

if((BALL.getX() >= LEFT_BAT.getX() && BALL.getX() <= LEFT_BAT.getX() + LEFT_BAT.getWidth()
&& BALL.getY() >= LEFT_BAT.getY() && BALL.getY() <= LEFT_BAT.getY() + LEFT_BAT.getHeight())
&& (BALL.getX() >= RIGHT_BAT.getX() && BALL.getX() <= RIGHT_BAT.getX() + RIGHT_BAT.getWidth()
&& BALL.getY() >= RIGHT_BAT.getY() && BALL.getY() <= RIGHT_BAT.getY() + RIGHT_BAT.getHeight())){
BALL.increaseDX();
BALL.setDX(-BALL.getDX());
} mh_sh_highlight_all('java');

It seems as though I would use the same code for checking the top or bottom.

View Replies View Related

Video Game - Collision Detection Class?

Apr 30, 2014

I use eclipse as my IDE. I have decided to make my own video game and somebody had sent me a class that could be used for collision detection. The problem with the collision detection class was that it made a box around an object and if something else had touched the object, the collision detection would work. My problem with this class is what happens when i want to use circles? I cant have a box drawn around it. Then it wouldn't work as i would want. Is there a pixel perfect collision detection class out there I can use? It'll be useful in my journey to become successful in computer science! By the way this is in the java language.

View Replies View Related

Space Invaders Game - Collision Detection

Apr 19, 2014

I'm working on a space invaders game and I'm having problems with collision detection. My main issue is I'm having problems getting what the y value of the "missile" is as it goes up towards the top of the game. I have tried for many hours and tried to look at other people's space invaders game in an attempt to figure out how to figure out my problem. Also I'm not sure if I have the code for my collision detection in the correct spot. Right now I have the code in the keyPressed method. Below is the code for the main and missle classes ...

import java.awt.Color;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.Iterator;

[Code] ....

View Replies View Related

Servlets :: Feature Detection - Determine Browser Type

Apr 22, 2014

I need to be able to detect IE 9, IE 10, IE 11 and the latest from Firefox and Chrome. The old method using the user-agent string is unreliable and not recommended. There is a different approach called, "Feature Detection". But I need to know what features to test to determine the browser. I can write it myself, or if there is a handy dandy API using feature detection already written that would be OK too.

View Replies View Related

Collision Detection Using Rectangles - Player Sometimes Passes Through The Tiles

May 19, 2014

I have already tried every possible way for removing this bug but all failed. The problem is that sometimes my player passes through the map tiles, i mean, the algorithm is like -- if not colliding, move in required direction; else if colliding, move in opposite direction. But sometimes the second condition fails i dont understand why.

private void movement(){
left=bindObject.getLeft();
right=bindObject.getRight();
up=bindObject.getUp();
down=bindObject.getDown();
bindObject.setColliding(colliding);

[Code] .....

Where bindObject is a class which contains key bindings of following keys:-

left arrow key (when pressed) , left arrow key (when released),
right arrow key (when pressed), right arrow key (when released),
up arrow key (when pressed), up arrow key (when released),
down arrow key (when pressed), down arrow key (when released)

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

How To Restart A Loop At A Certain Point

Jun 8, 2014

I made a blackjack code in java and I need to find a way to replace the place where I added a system.exit with a way to ask the user if they'd like to play again and restart the loop, keep in mind that I don't need the program to restart as I'd like to keep the value of their chips considering if they've won or lost.

Secondly, because it is a blackjack code, when it deals the cards, I would like for it to also print out K, Q or J but still consider it the number 11. Can I make an Ace count as 1 and 11?

One last question, is there anyway to add the suits of the cards such as (clubs, spades etc.) but the actual signs and if the signs aren't possible at all then the letter ('C', 'S', 'H', 'J') will have to do I guess.

import java.util.Scanner;
class Blackjack {
public static void main(String[] args) {
Scanner scan = new Scanner (System.in);
Scanner num = new Scanner (System.in);
System.out.println("Welcome to Blackjack!");

[code]....

View Replies View Related

Floating Point Vs Integer

Jan 31, 2014

how the data is stored in float. It seems like the range would be greater because it stores scientific notation rather than plain value, whilst integer arithmetic performance is better. float should be used to store bigger values and integer should be used for speed when values are smaller. As an example, I want to have cubic volumes ranging from about a handful to cargo ship. So float would be necessary for that.

View Replies View Related

Mouse Movement Code

Feb 11, 2014

I have been working on this mouse movement code that detects which direction the mouse moves in hope to use it in a game. The only problem is that I can not figure out how to make it move to the other side of the screen so I could continue turning to the right or left without having to stop. How would I actually get the x and y coordinants of the mouse to change?

PHP Code: if(x == xscreen){
//set x to 0
}else if(x == 0){
//set x to xscreen
}else if(y == yscreen){
//set y to 0
}else if(y == 0){
//set y to yscreen
} mh_sh_highlight_all('php');

View Replies View Related

Decimal Point On Jtextfield

Apr 26, 2014

designing a program which allows you to buy stuff from the jframe with 10x items each with different pricing, so once you click the image button the cost of that is displayed in the textfield, ive been trying to set the jtextfield to a decimal point but have not been able to so far,

if (source == jBSofa) {
System.out.println("Sofa");
{
dTotal = dTotal + 599.99;

jTotal.setText(Double.toString(dTotal));
DecimalFormat myFormatter = new DecimalFormat("#####.#");
String output = myFormatter.format(dTotal);
a visual aspect of it.

View Replies View Related

Mouse Listener For Two JPanels

Jan 6, 2015

The program i am creating consists of two JPanels (currently) and one canvas. The canvas is in the center of the JFrame, while flanked by JPanels where both have 13 buttons each.

To paint a simple picture, my program will draw letters on the middle canvas when a button is clicked.

I created my own buttons that implement the ActionListener interface , so when a button is clicked it will display its character in the console. But my question is, How do you implement the listener to draw something on the Canvas when the button's are clicked?

View Replies View Related

Point Coordinates - X Y Pair

May 8, 2014

What are the x- and y-coordinates of the Points referred to as p1, p2, and p3 after the following code executes? Give your answer as an x-y pair such as (0, 0). Recall that Points and other objects use reference semantics.

PHP Code:

Point p1 = new Point();
p1.x = 17;
p1.y = 9;
Point p2 = new Point();
p2.x = 4;
p2.y = -1;
Point p3 = p2;
p1.translate(3, 1);
p2.x = 50;
p3.translate(-4, 5); mh_sh_highlight_all('php');

P1:

P2:

P3:

My guesses were: P1:(20,10) //Correct

P2:(50,-1) //Incorrect

P3:(0,4) //Incorrect

View Replies View Related

JavaFX 2.0 :: How To Set Mouse Position

Jun 19, 2014

How can I set a new Mouse position ?

Is there any class that represent the Mouse ...

The cursor class is without this ability ...

View Replies View Related

Swing/AWT/SWT :: Adjusting Size Of Box With Mouse

Oct 16, 2014

I'm running the code below which compiles ok using latest version of Java and on Sublime. The problem when it complies the output screen is blank and I can only see the text by adjusting the size of the box with my mouse - and then it colours in black. Code and screenshot below. Is there something wrong with the paint/graf part of the code?

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class BackArray extends JFrame {
int store[] = {2,6,4,8,34,67,19,99,10,12,89,68,45,37};
int xcoord = 100;
boolean firsttime=true;

[code]....

View Replies View Related

Dragging Mouse To Draw A Line

May 16, 2014

I'm doing a exercise for dragging mouse to draw a line. I found a code to do this, but I don't know something in the code. example array Shape in the code.

import java.awt.AlphaComposite;
import java.awt.BasicStroke;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;

[Code] ....

View Replies View Related

Counting Mouse Button Clicks?

Jun 6, 2011

It complies an runs, but the textfield ends up being as big as the entire frame, and when I click the button, nothing happens.

import java.awt.event.*;
import java.applet.*;
import java.awt.*;

[Code].....

View Replies View Related

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

How To Cast Floating Point Number To Int

Jan 7, 2015

the output of this:

int x = (int) 24.6;

View Replies View Related







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