Draw 3 Rectangles In Different Spots / Move Elements In Order So They Do Not Cross

Apr 9, 2014

I made a small aplication which draws 3 rectangles in different spots(0,0 , 50,50 , 100,100)

Am I used an KeyListener + ActionListener, to make them move in the let's call it box.

How can I do in order that those 3 elements do not cross, so you can always see them, they don't collapse into each other?

Java Code:

package matrixmoveelements;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;

[Code] ......

View Replies


ADVERTISEMENT

Draw Rectangle If Key Pressed - Move Elements

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

Copying All Elements In Array A To B Sorted In Ascending Order

Apr 7, 2014

How do u copy all the elements in an array eg A into another array eg B? This is the question:

An array A contains integers that first increase in value and then decrease in value,

For example, 17 24 31 39 44 49 36 29 20 18 13

It is unknown at which point the numbers start to decrease. Write efficient code to code to copy the numbers in A to another array B so that B is sorted in ascending order. Your code must take advantage of the way the numbers are arranged in A.

This is my program:

This is the error message:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
at java.lang.System.arraycopy(Native Method)
at Quest30.CopyAndSortArray.main(CopyAndSortArray.jav a:16)

View Replies View Related

Input 10 Integer Elements In Array And Sort Them In Descending Order

Jun 13, 2014

How to input 10 integer elements in an array & sort them in desc. order using the bubble sort technique.

View Replies View Related

Class Defined Under Another Class - Sorting Elements In Reverse Order

Jul 4, 2014

I have never seen a class defined under another class ....

class pe{
static class pqsort implements Comparator<integer>
public into compare(Integer one,Integer two)
return two-one;
}
}

First I want to know how class pqsort is defined under class pe ....

And how the comparator used in this example is sorting elements in reverse order

View Replies View Related

Declare Array Of 50 Elements Of Type Double - Print Output 10 Elements Per Line

Feb 5, 2015

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class array
{
public static void main(String[] args)

[Code] ...

Is there a way to write this, where, alpha is one array.

Write a program that declares an array "alpha" of 50 elements of type "double". Initialize the array so that the first 25 elements are equal to the square of the index variable and the last 25 elements are equal to three times the index variable. Output the array so that 10 elements per line are printed.

If I have an array of 50 integers, can I break that to read in lines of 10?

View Replies View Related

Extract Higher-order Bits Of Random Number In Order To Get Longer Period

Mar 1, 2014

One of the random number generators in Java extract the higher-order bits of the random number in order to get a longer period.

I'm not sure if I understand how this is done. Suppose that the random number r = 0000 1100 1000 1101. If we extract the 16 most significant bits from r; is the new number r = 0000 1100 or r = 0000 1100 0000 0000?

View Replies View Related

Binary Tree Post Order / Inorder And Pre-order Traversal

Jan 26, 2014

Any link to the accurate explanation of binary trees in java?

View Replies View Related

Two Rectangles Overlap

Oct 27, 2014

the thing with this program is that instead of it having preset variables, I want to prompt the user to enter values of the two rectangles. I don't know how to use the scanner in this case, or even if I should use the scanner.

class MyRectangle2D {
//declare the variables
private double x, y;
private double width, height;

[code]...

View Replies View Related

Creating A Diagonal Cross?

Oct 3, 2014

I need to create a diagonal cross however I can not figure out how to do the upper left side of it.

Currently I am getting

0*
1--*
2---*
3 *--*
4*-----*

I want to get it to look like

0*------*
1 *--*
2----*
3 *---*
4*------ *

( I replaced spaces with -) So far I have

System.out.println("Input a size(must be larger than 1: )");
size=input.nextInt();
if (size>1) {
for (x=0;x<size;x++){
System.out.println("");

[Code] ....

View Replies View Related

How To Make 2 Rectangles In Same Window

Oct 2, 2014

My goal is to make 2 rectangles in the same window. so far I have this.

import javax.swing.JComponent;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
public class BoxComponent extends JComponent

[Code] ....

After running the program I get one rectangle, the red one. If I take the code out for the red rectangle, I only get 1 blue one. What am I missing?

View Replies View Related

Determine If Rectangles Cover Each Other

Oct 22, 2014

[URL] .... This is a link to the credentials that need to be met.

/* Constructors, getters and setters that will determine if the rectangles cover each other.*/

import java.util.Random;
import java.lang.Math.*;
class Rectangle{
   int width = 50;
   int length = 50;
   int x = 90;
   int y = 90;
  
[Code] ....

View Replies View Related

Add Elements To 2D Array Without Losing Elements

Jan 12, 2015

I am trying to make a 2d array that keeps track of comparison counts. what I have so far works ok but writes over the previous elements with 0. can't seem to find where I am re-initializing the previous elements.

//this is one of my fill sort arrays

public void fillSelectionArray(int index, long countSum) {
//rand = new Random( );
//for ( int i = 0; i < listsize; i++) {
selectionList[ index -1] = countSum;
// }

[Code] ....

I know I am missing something just not sure what.

View Replies View Related

Cross-site Scripting (XSS) In Search Box

Aug 13, 2014

I need fixing an issue in the search textbox in one of the jsp's. I was informed that cross site scripting can be done in the textbox and I kept the below code in my jsp to fix the issue:

Java Code:

searchTerm = request.getParameter("search");
searchTerm = searchTerm.replaceAll("<", "<").replaceAll(">", ">");
searchTerm = searchTerm.replaceAll("[^A-Za-z0-9 ]", "");
searchTerm = searchTerm.replaceAll("eval((.*))", "");
searchTerm = searchTerm.replaceAll("["'][s]*((?i)javascript):(.*)["']", """");

[Code] ....

Now, after applying the above code, the cross site scripting can be done and the problem is that the search can't be done using the textbox and all the time will display none results.

View Replies View Related

Number Generating Road Cross

Dec 8, 2014

The program I'm supposed to create generates a random number between one to ten. Then the program is to ask me if I wish to cross the road.

If you choose to cross, the outcomes for 0-2 are "You crossed safely."

For 3-5, 75% of the time it should say "RIP you got run over", and 35% of the time it should say "You crossed the street."

For 6-8, 60% of the time it should say you made it.", and 40% of the time it should say "You died". For 9-10, it should say "RIP".

So far I have gotten the random number generation part working,

import java.util.Random;
public class test4 {
public static void main(String[] args) {
Random random = new Random();
for(int i =0; i < 1; i++){
int num = random.nextInt(10) + 1;
System.out.println("The number of cars on the street are: " + num + "
Do you wish to cross the road?");
}
}
}

View Replies View Related

Drawing Rectangles From Array List

Nov 13, 2014

The program is where you will click anywhere in the jframe and it will draw a new rectangle. I have altered the code given to us but the problem that I am having is the fact that when I click the rectangle will always be connected to the upper left hand part of the jframe, no matter where I click. The program should create rectangles of the same length and width wherever you click. Here is what I have. I believe I have to change something in the addRectangle method, but nothing that I have tried works.

Java Code:

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import javax.swing.JComponent;
import java.util.ArrayList;
public class RectangleComponent2 extends JComponent

[Code] .....

View Replies View Related

Calculate Auto And Cross-correlation From A File

Oct 30, 2014

I have to calculate auto and cross-correlation from a file, like this:

Rxx(n)= 1/N* SUM[from k=1 to N-n]((x(k)-x(mean))*x(k+n)-x(mean))

and after

Rxy(n)= 1/N* SUM[from k=1 to N-n]((x(k)-x(mean))*y(k+n)-y(mean))

I've 600 x an y,
k = the numbers of x (N is the last one)
n = 0....N-1

View Replies View Related

Fixing Cross-site Scripting In Search Box

Aug 13, 2014

fixing an issue in the search textbox in one of the jsp's. I was informed that cross site scripting can be done in the textbox and I kept the below code in my jsp to fix the issue:

searchTerm = request.getParameter("search");
searchTerm = searchTerm.replaceAll("<", "<").replaceAll(">", ">");
searchTerm = searchTerm.replaceAll("[^A-Za-z0-9 ]", "");
searchTerm = searchTerm.replaceAll("eval((.*))", "");
searchTerm = searchTerm.replaceAll("["'][s]*((?i)javascript):(.*)["']", """");
 
[code]...

Now, after applying the above code, the cross site scripting can be done and the problem is that the search can't be done using the textbox and all the time will display none results.

View Replies View Related

Calculate Auto And Cross-correlation From A File

Oct 26, 2014

I have to calculate auto and cross-correlation from a file, like this:

Rxx(n)= 1/N* SUM[from k=1 to N-n]((x(k)-x(mean))*x(k+n)-x(mean))

and after

Rxy(n)= 1/N* SUM[from k=1 to N-n]((x(k)-x(mean))*y(k+n)-y(mean))

I've 600 x an y,

k = the numbers of x (N is the last one)
n = 0....N-1

already calculated mean, and I've tried the following (but it doesnt work):

String sor;
int i=0;
while ((sor = br.readLine()) != null) {
String [] adatok =sor.trim().split(",");

[Code] ....

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

Java Servlet :: Prevent Cross Site Script In URL

Jan 12, 2015

If some one add script in my URL, I want the script not pop up, we have tomcat 6 [URL] .....

View Replies View Related

Applets :: Drawing Ovals And Rectangles In JApplet With Two Separate Buttons

Apr 15, 2014

I'm not exactly sure what the draw button is supposed to do specifically, all i know is that it is supposed to draw both rectangles and ovals. The problem I am having is that when ever I click Draw Rectangle, it draws rectangles jusst the way I want but when ever I click Draw Oval, the program keeps drawing rectangles. I've tried repaint and clearRect methods but I did not manage to get them to work. I'm not sure what the problem is right here, I just cannot get it to work. Is there anything you guys can see that might be causing this? It's always good to have a different person look at it then myself. Also, I'm trying to implement a boolean for draw oval but I don't know where to put the if then.

public void init() {
length = new JTextField(10);
width = new JTextField(10);
btnDraw = new JButton("Draw");
btnClear = new JButton("Clear");
btnDrawRectangle = new JButton("Draw Rectangle");
btnDrawOval = new JButton("Draw Oval");

[Code] .....

View Replies View Related

Prime Numbers - Find N From List That Is Not Crossed And Cross Out All Its Multiples

Jun 20, 2014

the prime numbers from 1 to 2500 can be obtained as follows. From a list of the numbers of 1 to 2500,cross out al multiples of 2 (but not 2 itself). Then, find the next number (n, say) that is not crossed out and cross out all multiples of n (but not including n).

Repeat this last step provided that n has not exceeded 50 (the square root of 2500). The numbers remaining in the list (except 1) are prime. Write a program which uses this method to print all primes from 1 to 2500. Store your output in a file called primes.out.

View Replies View Related

Display And Resize Multiple Rectangles Independently - Using Objects From ArrayList

Jan 13, 2014

I have a code to resize a single rectangle. I would like to display and resize multiple rectangles independently and according to my research on the net, the best way is to use an arraylist. So I modified the code in this sense, except ...when I run the code, the rectangles appear good but impossible to resize. I think the problem comes from mousePressed, Released, Dragged and Moved methods. When I use the mouse to resize the rectangle, nothing happens. The code does not interact with the arraylist, and therefore with rectangles it "contains". Resizing is my main class, the MouseAdapter is in the Resizer class (below).

Resizing component;      boolean dragging = false;      // Give user some leeway for selections.     
final int PROX_DIST = 3;      Path2D.Double selectedPath;        public Resizer(Resizing rz) {         
component = rz;          component.addMouseListener(this);         
component.addMouseMotionListener(this);     

[Code] .....

View Replies View Related

Implementing Methods - Draws Ovals Or Rectangles On Screen And Can Change Fill / Outline Color Of Shape

Oct 5, 2014

The following class is part of a homework assignment:

package event;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import model.Model;
import shapes.Rectangle;
import shapes.Shape;

[Code] .....

I have to implement the methods for what is happening if on some panel the action selected are Remove/Move/Change/Resize (Draw is already implemented).

The Applet in question draws ovals or rectangles on the screen and you can change the fill-color and outline-color of the shape. All this works already. I have dabbled with the move-method, but am not going anywhere.

View Replies View Related

2D Tile Game Lag (Caused By Loop) - Rendering All Tile Rectangles

Jan 18, 2014

So the following is my code for the Terrian Generation of my game, however the way i have it rendering all the tile rectangles as opposed to just rendering whats visable on my JFrame causes lots of lag.

These are the variables and Rectangles inside _TerrianGen.class

//CHUNK
static int chunkx =2048;
static int chunky =2048;
 
//RECTANGLES
public static Rectangle[][] tile = new Rectangle[64][64];
static int[][] blockType = new int[64][64];
//0=Grass 1=Dirt 2=Stone 10=Brick 11=Coal 12=Iron 21=Gold 22=Diamond -1=null

This is the Init() code

for (int x =0; x < chunkx-32; x+=32){
for (int y=0; y < chunky-32; y+=32){
tile[y/32][x/32] = new Rectangle(x, y, 32, 32);
blockType[y/32][x/32] = -1;

[Code] ....

View Replies View Related







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