How To Make Green Selection Box To Move Around
Feb 16, 2014
I'm making a simple game where there's a 10x10 grid and you can move around a selection box and you can move around. I've been trying to make the green selection box to move around but it won't move! I only have right movement in the code but it won't work so far. Here are the classes that have to do greatly with each other.
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.KeyEvent;
import java.awt.image.BufferStrategy;
import java.util.Random;
public class Game extends Canvas implements Runnable{
private static final long serialVersionUID = 1L;
[Code] ....
I also tried an approach where you click with the move and it snaps to a tile grid but that didn't work either.
View Replies
ADVERTISEMENT
Oct 27, 2014
I am having trouble making my image move to a certain position in a certain amount of time which is set inside a text file. I was wondering what I'm doing wrong and what I'm missing.
import java.io.*;
import java.util.*;
import java.io.FileReader;
public class Animator {
EZImage HP;
[code]....
View Replies
View Related
Oct 1, 2014
How to make shapes move at same time when user enter up it should move up. It works for rectangle but i don't know how to move the others like that. (btw i am new to java). How can i do that?
import javax.swing.JFrame;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import javax.swing.JComponent;
import java.awt.geom.Ellipse2D;
[Code] .....
View Replies
View Related
Nov 12, 2014
I first need to draw this exact shape, which later I will have to make it move anti-clockwise, but for now, how to draw this thing:
First thing I can think of is drawArc, but not so sure...
View Replies
View Related
Feb 18, 2015
How do I make the file reader object move to the next line if there is no more input on the line. Here is my text and output file as you can see that my text file column cuts off on the 2nd line after 70. I want to read that next line which is 100 into my labs variable however its reading it into my final exams variable. I'll also post the code but I didn't think it was necessary.
textfile:
100908095
1008070
10070
output:
Labs Projects Tests Final Exams
100908095
1008070100
70
[import java.util.Scanner;
import java.io.*;
public class MyGrades
{
public static void main (String[] args) throws IOException
{
int lab, project, test;
int finalExam;//Par and Player values
[Code]...
not sure if I code wrapped it correctly
View Replies
View Related
Mar 27, 2015
can a keyevent in java make the space ship and the laser too ?
View Replies
View Related
Jan 6, 2015
I have two classes LightController & Circle. I need to use the LightController class to do the following:
Creates an instance of Circle with a diameter of 50 and a colour of OUColour.GREEN and assigns this new circle to the instance variable light.
Sets the xPos of light to 122.
Sets the yPos of light to 162.
I am struggling to write the correct line of code to set the colour to green and set diameter to 50.
Code for the two classes below.
import ou.*;
import java.util.*;
/**
* Class LightController
* This class uses the Circle class, and the Shapes window to simulate a disco light, that grows and shrinks and changes colour.
*/
public class LightController
{
/* instance variables */
private Circle light; // simulates a circular disco light in the Shapes window
private Random randomNumberGenerator;
[Code] ....
View Replies
View Related
Feb 23, 2014
I need to write up a code that will print the lyrics of the Green Bottles song. So it will ask the user to input a number and it will use that number to print the lyrics and then count down from that number. For example, user enters the number 5, the program will run and display:
"5 green bottles, hanging on the wall
5 green bottles hanging on the wall
and if one green bottles should fall
there will be 4 green bottles hanging on the wall
4 green bottles, hanging on the wall...." and so on.
So far I have managed to write a code that will display the number that is entered but I cant figure out how to subtract the number by 1 to continue it. My code so far:
import java.util.Scanner;
public class SomeJavaCode
{
public static void main(String[] args)
{
System.out.println("How many bottles to start with?");
[Code] ....
How to code it so that it substracts the number and repeats the rhyme till 0.
View Replies
View Related
May 22, 2014
I have a requirement like in a Rich datatable, and i have placed two links up and down in one of the column of each row, here i wanted to swap rows (move up/ down ) the rows when i click the link on a perticular row. is it possible with jsf/ java script?
View Replies
View Related
Jan 9, 2014
I am trying to move a JLabel in a JPanel, but can't seem to make it work. I can't provide a compiling code, but a few fragments. I have a JLabel [] array. i want to move with the mouse elements of this array. Let's say i want to move JLabel[i]. I implemented this:
Java Code:
static int labelY;
static Point labelX;
static Boolean flag = false;
jLabel[i].addMouseListener(new MouseAdapter(){
public void mousePressed(MouseEvent evt){
labelY=evt.getY();
[Code]...
I used the bool flag because i can't make changes to the label when it is inside an anonymous class. I also tried using setLocation but that did not work also. I don't get any errors when compiling. But when i run it and try to drag the JLabel[i] i get a long list of errors:
Java Code:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at puzzle.hw$1$2.mouseDragged(hw.java:276)
at java.awt.Component.processMouseMotionEvent(Unknown Source)
at javax.swing.JComponent.processMouseMotionEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
[Code]...
View Replies
View Related
Jan 30, 2014
I noticed it is a huge success to have the backgrounds of games move and the character just move up and down and dodge obstacles.How Do I make a background that scrolls horizontally to the left? I know how to keep the character in place with up and down to move, but not sure how to go about making the background move with obstacles.
View Replies
View Related
May 29, 2014
I was just trying to figure out why when I hold down a movement key, that my character doesn't move. It only moves if I continuously press the movement key. Here is my code:
package game;
import java.awt.*;
import TileMap.TileMap;
import Handlers.Keys;
public class Player {
private double x;
private double y;
[Code] .....
View Replies
View Related
Oct 8, 2014
I am new to Java programming and i am using BLUEJ to create some basic objects etc.
I have 3 circle objects (individual) and i am wanting to use "slowMoveHorizontal" method to move these 3 objects about 50px to the right.
So far, everything works BUT the issue is that they do NOT move together simultaneously. They move on a ONE BY ONE basis.
View Replies
View Related
Mar 27, 2014
I have created a authentication servlet as follows :
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
/* Connexion la base de donnees */
try {
Class.forName("org.postgresql.Driver");
System.out.println("Driver O.K.");
[code]...
I just want to know how can i move to another jsp page from my servlet.
View Replies
View Related
Feb 5, 2015
there are two classes here. I need to put the max and min methods should be in the tester class, but I have tried moving it to the tester class and it will not comply. When I run I get a list of errors of "Error:(43, 9) java: illegal start of expression
Error:(43, 16) java: illegal start of expression
Error:(43, 22) java: ';' expected
Error:(43, 41) java: '.class' expected
Error:(43, 52) java: illegal start of expression
Error:(43, 51) java: not a statement
Error:(43, 53) java: ';' expected
Error:(57, 9) java: illegal start of expression
Error:(57, 16) java: illegal start of expression
Error:(57, 22) java: ';' expected
Error:(57, 41) java: '.class' expected
Error:(57, 52) java: illegal start of expression
Error:(57, 51) java: not a statement
Error:(57, 53) java: ';' expected"
package A808;
public class FuleTesterV1
{
public static void main(String[] args)
{
String titleLines;
titleLines = "Yearly Gas Mi Calc | Assignment 8.08";
String TitleLines;
TitleLines = "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
[code]....
View Replies
View Related
Dec 11, 2014
I'm having some trouble with figuring out how to move along a doubly linked list for an assignment. The program is supposed to be a simple board game simulation. Here is what I have so far:
Space.java:
public class Space
{
private String name;
public Space next;
public Space previous;
public Space(String name)
{
this.name = name;
[Code]...
I seem to have been able to get all the other methods working properly, but I am pretty stuck on how to do the movePlayer. Specifically because it is passing an integer, but my objects are of type Space and Boardgame.
View Replies
View Related
Jan 23, 2014
I am just trying to understand during a drag and drop how can I transfer the actual object instead of just creating a new one. I believe I am close but I cannot nail down where I am going wrong. Here is my code I am using to test this.
First/Main:
Java Code:
package main;
import javax.swing.SwingUtilities;
public class Main {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable(){
[Code] ......
When I drag the JPanels it just copies and makes a new one. I tested this by having a sysout send to the console a private int that I set during the initial creation of the object.
View Replies
View Related
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
Jun 25, 2014
Below are three classes. The first and second create car objects and the third is the main method. My goal is to move two cars across the window. When I compile and run the program both cars are generated however they will not animate. I am moving them with threads but I cannot seem to find why the cars will not move.
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JComponent;
public class CarComponent extends JComponent {
private Car car1;
private Car car2;
[Code] ....
View Replies
View Related
Jan 24, 2015
I'm using Dr.Java and doing a numbershifter lab. I have to create a random array of number from 1-10. Then move all of the 7s to the front of the array. The order of the other numbers is not important as long as all numbers follow the group of Lucky 7s. Files needed Numbershifter.java and numbershifterrunner.java. All data is random.I have done the following:
public class NumberShifter
{
public static int[]makeLucky7Array( int size)
{
int [] newRay = new int[size];
for( int i=0;i<newRay.length; i++)
{
newRay[i] = (int)Math.round(Math.random()*10+1);
[code]....
It's adding to many 7s in the front of the array.
View Replies
View Related
Aug 17, 2014
I have a program which require to navigate a circle with for buttons, Up, Down, Right, and Left. How can i do that?
Here's my code:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package moveobject;
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class MoveObject extends Applet implements ActionListener
[Code] .....
View Replies
View Related
Aug 5, 2009
I've been trying to make an image rotate in a panel. I did it. But also i want the image to make a translation.
Here is the code i tryed at paintComponent() :
//////////////////////////
Graphics2D g2 = (Graphics2D) g ;
AffineTransform at = new AffineTransform() ;
// at.rotate ( angle in radians ) ;
at.rotate( this.getAngulo(1, 1) ) ;
g2.drawImage(imgemFlecha, at, this);
/////////////////////////////
I cant change image x,y doing this drawImage(). I want to make that change.
View Replies
View Related
Feb 18, 2014
I'm trying to get my animation for my java game to move along the edges of my device. Once it hits the edge I would like it to turn and keep moving along the edges. I'm sure this is easier than I'm making it but I can't find much on this. Right now my animation moves right and goes right off the screen until the app is closed and restarted.
This is my code so far:
package com.pjf.animation;
import java.io.IOException;
import java.io.InputStream;
import android.content.Context;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
[Code] .....
View Replies
View Related
Oct 3, 2014
public class TicTacToeGame {
public static void main(String[] args) {
char [][] board = new char [3][3];
displayboard(board);
int count = 0;
boolean loop = true;
[Code] ....
I also try with check if the move is vaild but no luck with that.
View Replies
View Related
Apr 7, 2014
I have a class that implements JComponent and draw a rectangle and if a key pressed(for example UP) I want to draw it up, and then when down key pressed to draw it down... But I want not only to disappear, but somehow to move, so the user can see the rectangle moving...
View Replies
View Related
Apr 11, 2014
I am try to move 2 ball at same time in different position but only one ball is display.
Here is my code I used two class one extends JPanel and another for JFrame
package usageThread;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JPanel;
public class ball extends JPanel implements Runnable {
[Code]...
View Replies
View Related