Moving Object In A Frame - Code Not Working

May 7, 2014

I have made a code that should allowed me to move an object in a frame, using the arrow keys. But I don't know why, is not working.

package joc;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.ImageIcon;

[Code] ....

View Replies


ADVERTISEMENT

Moving Oval Around The Frame

Feb 3, 2014

I'm trying to understand and learn Java for GUI but I'm stacked around a project. I had done some other "test app" but on this, I can't figure out what I had done. I can't move my circle around the panel.... Where I had made some errors?

Main class
package main;
// imports
import javax.swing.JFrame;
import java.awt.Dimension;
public class Main {
public static final int WIDTH = 320;
public static final int HEIGHT = 240;
public static final int SCALE = 2;

[Code] .....

View Replies View Related

Error While Moving The Tiles In Frame

Jan 17, 2014

I was following a tutorial on how to make a game when i suddenly got an error concerning moving tiles. i get this error when i tried to use a and d to move:

Exception in thread "Display" java.lang.ArrayIndexOutOfBoundsException: 48600
at com.cherno.graphics.Screen.render(Screen.java:44)
at com.cherno.Game.render(Game.java:124)
at com.cherno.Game.run(Game.java:87)
at java.lang.Thread.run(Unknown Source)

I do not get the error while using w or s but the tiles are still not moving when pressing them.

I have three classes at work here.

The main, Game.java;

package com.cherno;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferStrategy;

[Code] .....

View Replies View Related

Moving Object In Y Axis

Jul 10, 2014

I just have one problem with a "car" program in java. The objective is to move the car in the direction it is facing. Moving forward in the normal position (when the angle is zero) means moving in the x-axis. Choosing to turn the car function (for example: 90 ) and then using the forward function should move up or down the car in the y-axis. However the y-axis is not working.

Car2 Demo.rar
JPGMoveforwardfunction.jpg

View Replies View Related

Moving Object In Java?

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

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

When Code Runs - Images Are Not Showing Up In Frame

Apr 27, 2014

I'm using the book "How to Program in Java 9th Edition". The following is code from that book. I'm using eclipse. When the code is run the images are not showing up in the frame. The images are located in the directory with the java file and I have tried using the fully qualified image locations with no success. I've looked around on the web but can't see any reason why this code won't work. The code compiles and no errors are reported.

// Fig. 9.13: LabelDemo.java
// Demonstrates the use of labels
package Fig9_13DisplayTextImagesWithLabels;
import java.awt.BorderLayout;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JFrame;
public class LabelDemo

[code]....

View Replies View Related

Graphics In Game - How To Draw Object Or Get It Into The Frame

Apr 23, 2014

I am trying to create this snake and input it into the next window that is opened when the play button is pushed but how to draw this snake or get him into the frame and i have looked all over google.

import javax.swing.*;
import javax.swing.Box.Filler;
import java.awt.*;
import java.awt.event.*;
public class SnakeObject extends JFrame
{
public SnakeObject()

[Code] ....

View Replies View Related

Size Of Frame In Gaming Code - Full Screen Mode

Feb 17, 2014

Basically the code is for a game which is displayed in a window. The statement if(false) //full screen mode is confusing me a little. How does this if work? it doesn't seem to be testing for anything so how does it ever get set to full screen mode? Is the if even needed? why not just code windowed mode?

public class Window extends JFrame{
private Window()
{
// Sets the title for this frame.
this.setTitle("My test");
// Sets size of the frame.
if(false) // Full screen mode

[Code] .....

View Replies View Related

Code For OCR Scanner Not Working As Applet

May 18, 2014

I need to make a scanner (that has a built in ocr) output some content to a browser. I haven't gotten to the browser yet, but the code works when I run it as an application. With the scanner, I received Java code that makes the scanner take a picture, then read from it and output it back to the console. I added a few lines to make it an applet:

Java Code:

import gx.*;
import pr.*;
import java.applet.*;
public class DocScan extends Applet {
/**
*
*/
private static final long serialVersionUID = 1L;

[Code] .....

I am using Eclipse as an IDE. Right now my goal is to simply make the scanner "flash". I know that the output is to the console and I will not see anything from it in an applet, but it should still flash.

When I run this code as an application, it works. The scanner takes a picture and then it outputs what it has read to the console.

When I run this code as an Applet, the applet starts and does nothing. It just stays there with no errors of any kind (at least that's what Eclipse is showing me).

I read that I should allow the applet access, so I edited:

Java Code:

c:program filesjavajre8libsecurityjava.policy mh_sh_highlight_all('java');

And added this at the end:

Java Code:

grant {
permission java.security.AllPermission;
}; mh_sh_highlight_all('java');

Which should allow applets full access. However, there is no change - the applet still launches and does nothing. Why is the code not working when I run it as an applet?

View Replies View Related

Servlets :: Email Sending Code Is Not Working?

Mar 20, 2014

package signup;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates

[Code].....

View Replies View Related

Cipher Code - Encryption Test Cases Not Working

Oct 1, 2014

I have following Cipher Code and test for it. But I am getting following exception.

Java Code:

java.lang.IllegalStateException: Cipher not initialized
at javax.crypto.Cipher.checkCipherState(Cipher.java:1672)
at javax.crypto.Cipher.doFinal(Cipher.java:2079)
at com.anjib.util.CipherUtil.encrypt(CipherUtil.java:67)
at com.anjib.util.CipherTest.testEncryptDecrypt(CipherTest.java:23) mh_sh_highlight_all('java'); Java Code: public class CipherUtil {
private static Logger log = Logger.getLogger(CipherUtil.class);

[Code] ....

View Replies View Related

Pythagorean Theorem Program - Code Isn't Working When Written In OOP Style

Feb 11, 2014

I'm attempting to make a simple Pythagorean Theorem program (A squared + B squared = C squared) but am running into problems when I write it as object oriented. The darn thing works when written as a simple process, but that isn't Java now is it? Here's the simple:

public class PythagoreanTheorem extends ConsoleProgram {
public void run() {
println ("Finding C from A and B.");
double a1 = readDouble("Input A: ");
double b1 = readDouble("Input B: ");
double aSq = (a1*a1);
double bSq = (b1*b1);
double cSq = (aSq + bSq);
double c = Math.sqrt(cSq);
println ("C = " + c);

[code]....

View Replies View Related

Working With Gregorian Dates And Object Date?

Feb 10, 2014

I have two classes - a reservation class & a main class. Essentially, I want the user to enter two dates: an arrival and departure date. From the two dates, I will do a calculation (num days & price). I am having trouble finding a way to let users enter the (preferably in int, but that wasnt working),use getTime() to convert it from a calender to a date object. Then I want to use the dates to do a calculation. In addition, my constructor is being funky.

package hotelreservation;
import java.util.Date;
import java.util.Calendar;
import java.math.*;
//import java.text.*;
public class Reservation

[code]...

View Replies View Related

Why Boolean Equals (Object) And HashCode Not Working

Jul 17, 2014

Here is my code the whole program is working correctly but the Boolean equals and the has code and it is a requirement for the assignment. Why it is not working.

I know there are issues with the code I am new with java and was struggling so I have to clean my code up before I submit the assignment but for right now I have the out put the way I want it except the Boolean and hash code methods always output that the rectangles aren't equal even when I know they are and it outputs the not equal statement twice??

import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.util.Scanner;

[Code] ....

View Replies View Related

Object Contains Manipulation Code?

Mar 9, 2014

"Object contains data and code to manipulate that data."

Is the statement right ?? as far as i know object only contains copy of instance variables.

View Replies View Related

Code To Move Object In Grid

Aug 22, 2014

Working with some code that displays the random movement of an object such as Move 1: (0,1) Move 2: (10,99)?

I need these methods in the class

void initialize( int xPos, int yPos)
void moveLeft()
void moveRight()
void moveUp()
void moveDown()
int getXPosition()
int getYPosition()

View Replies View Related

Java Code Can Get At The Address Of Some Object Or Other Datum

Mar 17, 2015

I wanted to ask is there any way that Java code can get at the address of some object or other datum? I've found this useful a few time with certain high performance C# libraries that I've developed.

Also does Java have the equivalent of C#'s "fixed" buffers? which are inline contiguous arrays of primitives (like Chars or Ints etc).

View Replies View Related

Running Piece Of Code Inside String Object Possible?

Nov 7, 2014

i need to run a piece of code which is inside a string object..is it possible?if so how?

View Replies View Related

Project Is Working On JFrame - But Not Working On JApplet

Apr 10, 2014

I am developing an application to share my client screen with server, it is working well on swing. But i want to develop as web application, i am trying to using applet. But i am facing the fallowing problem..,

1) The Applet screen also open and project also running well on server mechine. But unable to see the client screen on the server.

2) The problem may be to display the JDesktopPane or JInternalFrame.

My working Server Code extends withe JFrame..Java Code:

package remoteserver;
import java.awt.BorderLayout;
import java.awt.Container;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import javax.swing.JApplet;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

[code]....

View Replies View Related

Moving A Map In A Game

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

Timer - Why Does Square Not Moving

Sep 7, 2014

Why does my program write that i have problem in Timer?

public class Ball extends JPanel implements ActionListener {
Timer timer = new Timer (3, this);
int x = 0, y = 0, aX = 2, aY = 2;
public void PaintComponent(Graphics g){
Graphics2D g2 = (Graphics2D) g;

[Code] ....

View Replies View Related

Swing/AWT/SWT :: Moving Image Left Or Right

Mar 11, 2014

I can't find any resource on the net about a simple Java code just to move a gif image left or right. I've already accomplished the up, down, and center and they're working fine, thus, I'm still struggling with moving the image left or right. Here's the code.

public class MoveIt extends Applet implements ActionListener
{
private Image cup;
private Panel keypad;
public int top = 10;
public int left = 10;

[Code] ....

I remember in Visual BASIC it's easily achieved by NameOfImage.left = NameOfImage.left - 10 to move left and NameOfImage.left = NameOfImage.left + 10.

View Replies View Related

Class Is Moving Extremely Slow

Dec 8, 2014

I'm currently taking a computer science class but the class is moving extremely slow and I'm not learning much, so I've started to program on my own. The most recent project I've done is a tic tac toe game, and I'm looking for something else to do now. I can do with an increased difficulty from this project, but not extremely difficult.

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.lang.reflect.Array;

[code]...

View Replies View Related

Application Crashes When Moving From One View To Another

Jun 6, 2014

So I've been working on a music player in android studio and I've created two java classes. One for Main Start Screen(StartScreen.Java) and one for the main player (player.Java). I have an onClicl event associated with a button as shown below.

public void onclick(View view) {
Intent detailIntent = new Intent(this, main_player.class);
startActivity(detailIntent);
}

The code for the second Java Class is as below. There is nothing in the java class as for now.

package com.example.musicplayer.app;
import android.app.Activity;
import android.os.Bundle;
public class main_player extends Activity {
protected void onCreate(Bundle savedInstanceState) {

[Code] .....

Where is the actual mistake because the app works fine until i click the button that is suppose to take me to the main player screen?

View Replies View Related

Moving Rectangle In Diagonal Line

Jul 24, 2009

I am just trying to move a rectangle in a diagonal line. When the applet pops up, the rectangle is there but doesn't move. If I drag the sides of the applet to make it bigger or smaller the rectangle will redraw itself and move, but I want it to move without touching the window.

Java Code:

package javaapplication3;
import java.applet.Applet;
import java.awt.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Random;

[Code] .....

Why does it only repaint when I resize the window?

View Replies View Related







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