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


ADVERTISEMENT

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

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

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

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

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

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 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

How To Determine Size Of Table

Jul 6, 2014

Can be :

results = null;
results = new double[2];
results = new double[50];
results = new double[100];

How determine size of this table : System.out.println("table size=",???);

View Replies View Related

How To Determine Value After Nested For Loop

Oct 12, 2014

int count = 0;
for (int x = 0; x < 3; x++)
for (int y = x; y < 3; y++)
for (int z = y; z < 3; z++)count++;

What is the value of count after the code segment is executed?

The answer is 9, but I don't really understand how this answer was derived.

View Replies View Related

How To Determine Value After Nested For Loop

Oct 12, 2014

int count = 0;
for (int x = 0; x < 3; x++)
for (int y = x; y < 3; y++)
for (int z = y; z < 3; z++)
count++;

What is the value of count after the code segment is executed?

The answer is 9, but I don't really understand how this answer was derived.

View Replies View Related

JSP :: How To Determine Username (Website Visitor)

Jul 17, 2014

Is there a way to tell the login name of a visitor to a website?

View Replies View Related

How To Determine If Classes Use Comparable And Comparator

Apr 13, 2015

Which of the following classes uses Comparable and Comparator?

QueueTreeSetStackPriorityQueue

In the above question, what does 'uses' mean? Does it mean do above classes implement Comparable and Comparator?

I know that in order to compare any two elements stored in one of the above classes, we need to make the elements' class to implement one of these - either Comparable or Comparator.

View Replies View Related

Nested If / Else - Cannot Determine Logical Mistake

Jan 5, 2015

The title says already where my difficulties are. I forgot to say, the "S" printing part works, but why the others doesn't. To make it more clear:

java Monoton 1 3 3 4 & java Monoton 1 3 4 1

=> nothing (my output)

I forgot to notice, with 1 3 3 4 as parameters it jumps out at if (b < c), which is expected. but it jumps out of the whole if instead just run the else part. that's the essence of my problem.

The Exercise:

=> The program should print the following letters;

S, if every number is true bigger than the before,

M, if every number is bigger or equal than the before,

N in the other cases

Examples (from the exercise)

=> java Monoton 0 1 2 4

S

=> java Monoton 1 3 3 4

M

=> java Monoton 1 3 4 1

N

The Exercise should done without the use of logical operators or other combined requirements.

Java Code:

public class Main {
public static void main(String[] args) {
int a = Integer.parseInt(args[0]);
int b = Integer.parseInt(args[1]);
int c = Integer.parseInt(args[2]);
int d = Integer.parseInt(args[3]);

[Code] .....

View Replies View Related

Algorithm That Determine Ancestors And Descendants

Dec 16, 2014

I have a problem with this example. I don't understand what should I do. Data on family relationships are contained in two tables.

Table 1 has a column Child and Mother,
Table 2 - Child and Father.

Formulate algorithm that determines: all the descendants of a person X, all the ancestors of a person X. Write a program implementing the algorithm.

View Replies View Related

Determine All Of Perfect Squares Between 1 And 100 - Precision Error?

Mar 26, 2015

I am teaching myself Java and am trying to write a function that will determine all of the perfect squares between 1 and 100 but am running into a problem...

Here's my code:

package sqrroot;

public class SqrRoot {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
double sroot, rerr;
int count = 0;
for(double num = 1.0; num <= 100.0; num++){

[Code] ....

and here is the output:

run:
0.0
1.0 is a perfect square.
0.0
4.0 is a perfect square.

[Code] ....

There are 49 perfect squares between 1 and 100.
BUILD SUCCESSFUL (total time: 6 seconds)

Which is clearly wrong. Is there something wrong with my code or is this due to inherent imprecision in the double type or the Math.sqrt function?

View Replies View Related

Servlets :: Determine Which HttpSession Attribute Value Changed?

Feb 15, 2015

I'm looking to figure out if it's possible to do the following:

HttpSession session = request.getSession();
session.setAttribute('name', 'Jane_Doe');
// more code here
session.setAttribute('name', 'John_Doe');

Obviously, you can use the HttpSessionAttributeListener to determine which attribute has changed. However, it doesn't return the new value but rather the old one.

You can use the HttpSessionEvent listener to determine when a session object has been changed.

Is there a way you can determine when a session object changes (and it does NOT occur when the setAttribute method is called...) and determine the updated key:value pair?

View Replies View Related

Allowing User To Determine When A Program Is Stopped?

Nov 8, 2014

I was tasked with building a program that counts vowels in a phrase or word. I have this working properly, but the problem arises in the next situation. Here is my code:
 
Scanner userInput = new Scanner(System.in);
int userDecision;
String Choice;
String Phrase;
int vowelCount = 0;
System.out.println(" This program will count the number of vowels in it.

[Code] ....

As you can see, I used a 'for' statement to declare how long the program should run. However, I need the user to be able to say when it ends. For example, at the end of the program it must say "There are ______ number of vowels in your word. Please press '1' to run the program again, or any other number to exit."

I understand a do-while loop is needed here, but every time I try and create an adequate loop with no logic errors, I either break my existing code, or the program does not work correctly.

Basically, my question is, what is the best way to perform this task? Is a do-while loop necessary, or is there a better way?

View Replies View Related

Way To Determine Class Of A Random Anonymous Object?

Jun 20, 2014

Wanted to know Is there any way to determine the class of a random anonymous object?

View Replies View Related

Determine Positive And Negative Values Have Been Read

Feb 4, 2015

The program work somehow, but it can't count the first input when user key in.

import java.util.Scanner;
public class DetermineValues {
public static void main( String[] args ) {
int sum;
int minus;
int data;

[code]....

View Replies View Related

Determine If There Is Path From One Vertex To Another - Why Is This Returning False

Dec 7, 2014

This method pretty much determines if there is a path from one vertex to another. When I check to see if there is a path from 5 to 2 (which there is) it return false. However, when I create a driver method, it return true (which it should). Why? It should never reach outside of the else because the condition is met, right???

Here is the graph:

0 1 2 3 4 5
------------
0| 0 1 1 0 0 0
1| 0 0 0 0 0 0
2| 0 0 0 1 0 0
3| 1 0 0 0 0 0
4| 0 0 1 0 0 1
5| 0 1 0 1 0 0

Path: 5 points to 1 and 3 (1 does not have a path to anything). 3 points to only 0. 0 points to 1 and 2. Thus there is a path from 5 to 2.

Here is the code without the driver (the one that is returning false, even tho it should be true)

public boolean existsPath(int x, int y){//x = 5, y = 2
stack.push(x);//mark x as visited
if(x == y){//path found
stack.removeAllElements();
return true;

[Code] ....

View Replies View Related

Control Rectangle And Determine Where It Moves - Key Presses

Mar 11, 2014

I am writing a program where i am trying to control a rectangle and determine where it moves, everything is working fine it is moving but i am trying to figure out how to change direction using the "WASD" keys. This is what I have and I am not sure why its not working.

Java Code:

addKeyListener( new KeyAdapter() {
public void keyReleased(KeyEvent event) {
for (MoveableShape creature : creatures) {
if (((Creature)creature).isPlayer()) {
if (event.getKeyCode() == KeyEvent.VK_W) //up

[Code] ....

View Replies View Related

Determine If User Input Is Fibonacci Number Or Not

Oct 20, 2014

Part A: While Loop Program

Write a program that detects Fibonacci numbers. Prompt the user to input a positive integer. Upon input, the program will determine if the number is either a Fibonacci number or not. If a Fibonacci number, then the order of the number in the sequence must be output. If not a Fibonacci number, then the Fibonacci numbers above and below it (including their order in the sequence) must be output. Once it finishes, the program will prompt the user for a new number. The program will exit if the user enters a string (such as “quit”) instead of an integer. Use the sample output file, fib-seq-det.txt, to view a sample session

This is my project, I wrote a programs that tells you if the input number is a fibonacci number or not. For some reason it only works for some Fibonacci numbers but not all of them.

import java.util.Scanner;
public class While
{
public static void main(String[] args) {
System.out.println("Welcome to the Fibonacci Sequence Detector
");
Scanner in = new Scanner(System.in);
System.out.print("Please input a number for analysis: ");
int input = in.nextInt();

[Code] ....

View Replies View Related

Nested For Loops - Determine If Inputted Integer Is Even Or Odd

Sep 29, 2014

So I cant figure out why my output for my for loop isn't working properly. So the output for the square comes out right but the for loop isn't working properly for the H. I have tried to figure it out and it should go to the next line but its not.

import java.util.Scanner;
public class Random
{
public static void main(String [ ] args)
{

[Code] ....

Output

Enter a positive odd integer: 5

Square:
*****
* *
* *
* *
*****

H:
* *

View Replies View Related







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