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
ADVERTISEMENT
Mar 19, 2015
Okay, gotta be able to move the image when a key is pressed. When I test it, the image moves, but leaves the old image behind.
package Game;
import java.awt.Component;
import javax.swing.JOptionPane;
public class Game
{
private Grid grid; //holds the grid used to store and display images
private int userRow; //keep track of which row the user-controlled image appears in
private int msElapsed; //keep track of the total amount of milliseconds that have elapsed since the start of the game
[Code] ....
Here is what I was given on instructions:
Complete the handleKeyPress method. Write the following line of code in the handleKeyPress method to check for a key press:
int key = grid.checkLastKeyPressed();
If the user pressed the up arrow (key == 38), move the user's image up one row (unless the user is already in the top row). Likewise, if the user pressed the down arrow (key == 40), move the user's image down one row (unless the user is already in the bottom row). Either way, make sure to update userRow.
Movement of the image can be accomplished by changing the value of userRow. Study how the initial image is displayed in the game constructor, then
Set the current image location to null
Update userRow to the new location and,
Set the image in the new value of userRow.
You should be able to move the user image up and down, and you should be prevented from moving the image off the screen.
View Replies
View Related
Apr 1, 2014
I am writing code for a simple java game. The problem I am running into is that I have a moving icon (J button) that is controlled using the keyboard (arrows) and I also have stationary icons (J button). Is there a way to keep the moving icon from passing over the stationary icon? I would like the stationary icon to act like a wall.
View Replies
View Related
May 24, 2015
I am trying to make a simple platformer game in Java. When I try to move the character I made it only moves over then immediately back
import java.awt.event.KeyEvent;
public class UCC
{
private int xLoc;
private int yLoc;
private int xSpeed;
private int ySpeed;
private double gravity;
private int size;
[code]....
View Replies
View Related
Jan 27, 2015
Just run the following code and move the mouse next to the text of the button and you will see exactly what I am talking about. Any way to prevent this continuous flash?
import java.awt.Dimension;
import javax.swing.JButton;
public class GUI {
public static void main (String[] args) {
javax.swing.JFrame frame = new javax.swing.JFrame();
javax.swing.JPanel panel = new javax.swing.JPanel();
[Code] .....
View Replies
View Related
Jan 8, 2015
The game is too have two players, each user clicks a button and two dices will roll, if a user rolls a double they win.
firstly I have started with two imageview's and a button I am trying to randomise two images by clicking one button I have managed to randomise one image in one box but I am struggling to randomise both image views here is my code so far.
import java.util.Random;
import android.app.Activity;
import android.os.Bundle;
[Code]....
That code is only generating a random dice image in one of the image views I have hit a brick wall
View Replies
View Related
Jul 22, 2014
I've been at this for a while and I would like to make the Camera in my game follow the player and I know the way to do this would be to move the map and not the player. How would I do this if my map is rendered from a text file using for loops. Here is my code for the map.
package Game;
import java.awt.Graphics;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class Map {
[Code] .....
View Replies
View Related
May 27, 2014
I have been working on this function and i can't get it to work. It's a little bit complicated so let me first explain what this is about:
1. As a little exam in my studies i have to program a halma console game with KI an stuff.
2. Everything is finished and works except for the Move-Calculation.
3. A Move is a Move from Field a to Field b which a player can perform in one round based on the game rules (Careful: We are not using the standard halma rules, we use different ones).
4. Class Move consists of the Starting Cell where the Figure before the Move stands and a target Cell where the figure will stay on at the Move end. It may include an Array of serveral Cells, the stop cells which the figure passes from start -> target since several jumps can be performed in one Move.
Valid Examples for Moves:
a -> b (From Field a to Field b)
d -> f through g,h,i (From Field d to Field f through the Field g,h,i
My Move Calculation where all possible Moves are calculated for a given figure consists of 2 parts. An expand() function which will generate all possible moves (works perfectly) and a jumpFix() function which isn't working properly.
Example:
After expand() I'm getting something like that:
a -> b
b -> c
c -> d
s -> t
This is however not finished, because the first 3 Moves are actually 1 Move. Because the player can Move from a -> d in one turn because those 3 are consecutive Move. The fixed Move would look like that:
a -> d through b,c
jumpFix() is also perfectly working for that situation, however there is one specific situation when it doesn't work. Let's say we have this situation.
a -> b
b -> c
c -> d
b -> e
e -> f
f -> g
s -> t
Then the only valid jumpFix() output would be:
a -> d through b,c
a -> g through b,e,f
s -> t
However i can not get it to work yet. Note: It definitely needs to be iterative, not rekursive else i would get an StackoverflowError.
This is my current Code of jumpFix():
Java Code:
/**
* Takes a look into all calculated moves and finds those which should be seen as one move, but are still considered to be more than one move (several jumps in one move)
*/
public static List<Move> jumpFix(List<Move> moves) {
Set<Move> result = new HashSet<Move>();
Set<Move> remove = new HashSet<Move>();
int lastSize = -1;
// repeat action until no moves could be merged
while (lastSize != remove.size()) {
[Code] ....
How to implement the special case where a Move splits into 2 or more branches and jumpFix() able to handle this case.
View Replies
View Related
Sep 1, 2014
I'm trying to create a Texas hold'em Poker application. A rough idea of it would be similar to those poker games on the playstore e.g. Zynga Poker, however it will be a simplified version, more of a home-based application, for a small group of friends. This way, we can get to play poker on the go with each other, like a private table on the go. Anyway, right now how do I get started?
1) How should I even start this project? Do I start the GUI for the application first? Start designing the applications with photoshop? I figured I need a skeletal guide to start and follow.
2) How do I connect all the players together to a table? I know I could use my phone as a Server, where the rest could connect to mine. But I'm not sure what I should research on. Also, as I'm working towards a "Portable, On the go Application". So I would like to work this more based on 3G/4G networks.
3) Database, I would like something to keep a record on the buy-in, winnings & losings so we can keep track of it. However, if the server was my phone. When I turn off the server, would the database be gone? Maybe I might be able to save it on a notepad in a folder on my phone? I think this is possible.
View Replies
View Related
Feb 21, 2014
Basically I have a program that paints a simple object image. There are 5 of these objects altogether and different classes and methods have been set up to do this and this works correctly. The program currently also asks the user if they would like to change the colour of this object shape, and which shape they would like to change (user inputs a number 1-5) then the program will change the colour of this shape.
But the new task is for the user to input a number (1-5) to which shape they would like to MOVE position of. Hhow this would be done? Would there need to be different methods for changePositionX, changePositionY? The user needs to input the X and Y co ordinates and then this will move the selected shape to its NEW position in the current JFRAME.
View Replies
View Related
Jan 13, 2015
I have a class that works only when in the default package. If I move the class to a package I receive UnsatisfiedLinkError.
This is the class in the default package(this works fine):
[code]
public class CsharpConsumer {
private native int reigsterAssemblyHandler(String str);
public CsharpConsumer() {
String dir = System.getProperty("user.dir");
System.load(dir+"dllscardJNICsharpBridge.dll");
int reigsterAssemblyHandler = reigsterAssemblyHandler(dir+"dllscard");
}
}
[/code]
If at the top of this class I add "package DLLUtils;"
the error is "Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError:
DLLUtils.CsharpConsumer.reigsterAssemblyHandler(Ljava/lang/String;)I"
I tried a lot of things but none solved the problem. I must move the class to o package because I cant "import CsharpConsumer;" from default package.
View Replies
View Related
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
View Related
Jan 18, 2014
I have been following a 2d side scroller tutorial in java and have got the basics working, I changed the code a bit to make it so that the tiles and background are always moving, this worked as i intended.Within the character class:
if (speedX < 0) {
centerX += speedX;
}
if (speedX == 0 || speedX < 0) {
bg1.setSpeedX(0);
bg2.setSpeedX(0);
[code]....
I wanted a way to make it so that if the character moves left, the tiles + background move slower. I am having issues with variable scope and setters/getters. Within the main game class, I have the code:
case
KeyEvent.VK_LEFT:
character.moveLeft();
character.setMovingLeft(true);
break;
How can i include an if statement within the tile class that reads whether the character is moving left (determined from a keyPressed event in the main game class) and adjusts the speed of the tiles accordingly?I want to write something to the effect of:
if (setMovingLeft = true){
speedX = bg.getSpeedX() * 3;
tileX = tileX + speedX - 1; << changed from - 4
View Replies
View Related
Aug 4, 2014
I'm learning about the printf command, and when I have it, it is not letting me ad an input. Here is my quick little program:
import java.util.Scanner;
public class TestingPrintF {
public static void main(String[] args) {
// Create a Scanner
Scanner input = new Scanner(System.in);
[Code] ....
The first section works good, but when i move down to the second part it just automatically finishes without letting me enter a phrase.
View Replies
View Related
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
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
Mar 26, 2014
I am trying to .wav file using java eclipse ..
[B]import java.io.* ;
import sun.audio.*;
public class AudioDemo{
public static void main(String[] args)
throws Exception
[Code] ....
And I am getting the following errors ...
Exception in thread "main" java.io.FileNotFoundException: E:pppp.wma (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at AudioDemo.main(AudioDemo.java:10)
View Replies
View Related
May 31, 2014
I'm programming a game in Eclipse using Java for Android. I was wondering if any good example of a Health bar using Images. All I can find is people using the progress bar, but i feel that's unprofessional looking.
My goal is to layer 2 images. 1 being the frame of the health bar, 1 being the value of the health bar. I figured it would be something like moving the value health bar image few pixels over depending on the variable of health.
View Replies
View Related
Apr 21, 2015
I'm trying to finish this game of hangman for java in the program eclipse. Currently when I run the program I get this in the text field:
in randomword
in string2Array[Ljava.lang.String;@22998b08
v
i
d
e
o
g
a
m
e
s
New Game
Enter a letter: s
s
???????????
After I try entering a letter it doesn't prompt for the user to enter another, nor does it change the ? mark when the user guesses correctly.
Here's the code :
import java.util.Scanner;
public class Hangman {
int NUMBER_STRIKES = 7;
int strikes = 0;
String userguess= " ";
private ArrayFunctions func = new ArrayFunctions();
String currentWord;
[Code] ....
View Replies
View Related
Jan 22, 2014
I made just a simple hello world class and i can not seam to make eclipse run it in any way not even the console.
View Replies
View Related
Oct 26, 2014
I am following a tutorial to write a 2d game from scratch in java but when I compile and run my code the application (JFrame) doesn't come up on my screen, it just runs for a second and terminates itself for some reason.
package com.thecherno.rain;
import java.awt.Canvas;
import java.awt.Dimension;
import javax.swing.JFrame;
public class Game extends Canvas implements Runnable{
private static final long serialVersionUID = 1L;
[code]....
View Replies
View Related
Aug 15, 2014
im wanting to create a console gui that opens with my program game and people can type stuff in it to run commands as well as a debug option to show when errors happen and have a command to list all availble command.
View Replies
View Related
Apr 18, 2014
I wondering how could i randomize a number 2 with 90% and 4 with 10% , with java eclipse?
View Replies
View Related
Jan 10, 2015
it will shows this kind of error
com.microsoft.sqlserver.jdbc.SQLServerException: The connection to the host localhost, named instance sqlexpress has failed. Error: "java.net.SocketTimeoutException: Receive timed out". Verify the server and instance names, check that no firewall is blocking UDP traffic to port 1434, and for SQL Server 2005 or later verify that the SQL Server Browser Service is running on the host.
at com.microsoft.sqlserver.jdbc.SQLServerException.ma keFromDriverError(SQLServerException.java:171)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.g etInstancePort(SQLServerConnection.java:3174)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.p rimaryPermissionCheck(SQLServerConnection.java:937 )
at com.microsoft.sqlserver.jdbc.SQLServerConnection.l ogin(SQLServerConnection.java:800)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.c onnect(SQLServerConnection.java:700)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.conne ct(SQLServerDriver.java:842)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at jdbc.JdbcSQLServerConnection.main(JdbcSQLServerCon nection.java:25)
View Replies
View Related
Oct 28, 2014
I've got a problem in Eclipse. The below code is a part of my program, used for (re)starting a new game. The 'public static int' statement gives the error 'This method must return a result of type int'..
public static int playAgain(){
boolean validInput = false;
do {
System.out.println("Would you like to play a game? Please answer 'yes' or 'no'.");
String playAgain = input.next();
[Code] ....
View Replies
View Related
Nov 1, 2011
I'm developing a JavaEE system with several applications on a Weblogic AS (10.3.5) using Eclipse indigo with OEPE plugin. I turned my computer off, turned it back on, started the eclipse, and all of a sudden I get class-path errors all over the place (didn't change a thing).
Now let me get this straight:
1. Say I have an application with one EAR project that contains an EJB project and an EJBClient project (both in the deployment assembly).
2. I have written a new regular Java project, and I want to use it in both the EJB and EJBClient projects (it needs to be visible to them).
3. As far as I know, I can simply add this Java project to the EAR project's deployment assembly, and it will be visible to the EJB and EJBClient projects.
4. This has been working for me so far, but now I get class-path errors and I have to add this Java project to the build path of each project.
How should I set the class-path when using JavaEE technology in Eclipse?
View Replies
View Related