How To Make Line To Follow Rectangle When Moving Or Rotating
Oct 18, 2014
After i draw line between 2 fixed points on two different rectangles i need to rotate them. The problem is that my line is not updated, it stays on the same x1,y1 x2,y2. How to make line to follow rectangle when they are moving or rotating? I wrote some example code to demonstrate this.
Object that i want to draw:
[public class Object {
private int xPos;
private int yPos;
private int width;
private int height;
float xDistance = 0f;
float yDistance = 0f;
double angleToTurn = 0.0;
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.
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
I am trying to only allow the user to input numbers. But I need to enter a number twice before it moves to the next line statement and also skips a line when i enter th number a second time.
How can I go around fixing this.
My code for this is
case 1: do{ Event event = new Event(); out.println("Please Enter the name."); event.setEvent(input.next()); input.nextLine();
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.
I need to do a rectangle using boolean array where true elements are the borders of the rectangle, and false elements are the inner space. I imagine that the first and last rows and columns must give the true element,
public class Functionality { public static boolean[][] rectangleArray(int n, int m){ boolean[ ][ ] matrix = new boolean[n][m]; for(int i = 0; i <matrix.length; i++){ for(int j = 0; j < matrix[i].length; j++){
I've started creating a simple game in Java, but I'm still a beginner, so now I'm stuck. I wanted to make moving character by fast alternating arrow keys, but I don't know how. I can make a boolean variable, which disables moving by pressing the same key again, but the player can just hold the key and character is still moving. I thought about changing position of character when the key is pressed, instead of increasing speed, but then the movement wouldn't be smooth. I think this may sound incomprehensible, so I will add a link to game like an example of what I mean.
I've started creating a simple game in Java, so now I'm stuck. I wanted to make moving character by fast alternating arrow keys, but I don't know how. I can make a boolean variable, which disables moving by pressing the same key again, but the player can just hold the key and character is still moving. I thought about changing position of character when the key is pressed, instead of increasing speed, but then the movement wouldn't be smooth. I think this may sound incomprehensible, so I will add a link to game like an example of what I mean.
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;
I have a java program which rotates a rectangular polygon. My program is having a problem. As soon as it starts rotating, it shrinks. The polygon is rotating perfectly though. I am trying but unable to figure out the cause.Main class which has an infinite loop (game loop) to rotate polygon continuously :-Java Code:
I wanted to write a method which gets a buffered image as parameter, rotates it 90 degrees clockwise around its top left corner, and then returns it. This method will be call from another method which then draws the rotated image on a rather large background which consists of many other images.
Here is the code I have so far:
public static BufferedImage rotate(BufferedImage img) { int w = img.getWidth(); int h = img.getHeight(); BufferedImage newImage = new BufferedImage(width, height, img.getType()); Graphics2D g2 = newImage.createGraphics(); g2.rotate(Math.toRadians(90), w/2, h/2); g2.drawImage(img,null,0,0); return newImage; }
This method does rotate an image 90 degrees, but when the calling method recieves this image and displays it on the bigger frame, parts of the rotated image is cut. I think because the frame holding the returned image is not big enough. I've tried playing around with the code a lot, chaging the sizes of different images, and trying AffineTransform features, but I have had no luck.
I am having a problem rotating a shape I am using the transformation rotation matrix and don't seem to be getting the results I expected. Now I know a lot of programmers will just tell me to use the Graphics2D rotate(theta) Method.But I would like to create this ability through writing the code.
I have wrote this class who read from text line by line and save the words in fileOnTable.. Now i don't know what to read in ReadOffer to save the words in object offers and return this.. One more question.. What JUnit test can write for this code..?
My requirement is to find the line number using multiline string. Here I need to extract the string between FROM and where clause(from the below string) and need to find the line number in the file
SELECT HL.LOCATION_ID,HPS.PARTY_SITE_ID,HCAS.CUST_ACCT_SITE_ID INTO LN_SITE_LOCATION_ID,LN_LOC_PARTY_SITE_ID,LN_CUST_ACCT_SITE_ID FROM HZ_LOCATIONS HL, HZ_PARTY_SITES HPS,
If I want to read my file line by line and when it hits a certain value from that point it should start deleting the lines until the tag ends.Just curious will my code actually work at the moment or not because it goes through so many times then goes straight back to the variable declarations at the start of the method and never hits the console print line.
public void removeEnvironment(){ //declare variable to environment id String environmentID = "Environment id"; String lines = null; boolean lineFound = false; boolean end = false;
I'm creating a program that searches a txt file for a given string, then return the number line and the line itself. However, my testFile class isn't detecting my searchWord methods.
The searchWord and recursiveSearch is written in a java class called BasicFile
public List<String> searchWord(String key) throws Exception { LineNumberReader lnr = new LineNumberReader(new FileReader(f)); return recursiveSearch(lnr.readLine(), key, lnr); } public List<String> recursiveSearch(String currentLineText, String key, LineNumberReader lnr)
[code]....
Is it because I'm using a list instead of a string?
I'm doing an assignment for uni and have come across a small hiccup. What I'm trying to do is scan in a text file and read "commands" for it line by line, E.g:
Student Mary 12345 19 Student Joe 12346 19 Change Joe 19 20 Change Mary 19 20
So that lines that begin with the word "Student" indicate that I should create a new student file with that name, student ID, and age.
"Change" indicates that I should be changing the specified student's current age to the new age etc.
What I'm currently doing is something along the lines of this:
Scanner input = new Scanner(new FileReader(args[0])); String[] line; while (input.nextLine().startsWith("Student")) { line = input.nextLine().split("s+");
[Code] ....
The problem I'm having is that every second line seems to be getting skipped (because I'm calling nextLine() so much?) but I can't think of a way to "peek" at the first word of each line without advancing past it. Is there any way of doing this?
I think the lines need to be stored in ArrayList, then I would like those lines to write to csv file, but how on read I can construct such output file? This is my code for reading file
public ArrayList readFile(String filename) { try {
01. pickup the selected text file and read the line by line and output the text in to visual text pane.
what i did:.
01. I wrote code that read the text file and output in to jave console/ also some of the interface.
the code read txt file:
Java Code:
String fileName = "C:/Users/lakshan/Desktop/lawyer.txt"; File textFile = new File(fileName); Scanner in = new Scanner (textFile); while(in.hasNextLine()){
[code]....
so it will read any text file dynamically and output to the text pane in interface. I think scanner code must be execute after the select the file from the browser and set the scanned result in to variable. then later out put the var as string in some jswing component?
Thats my code, and the rectangle (ObstacleX is the X cordinate for the rectangle) goes fine on the first few times across the screen, then starts to go hyperspeed....
I have to do the following: A bounding rectangle is the minimum rectangle that encloses a set of points in a two-dimensional plane. Write a method that returns a bounding rectangle for a set of points in a two-dimensional plane, as follows:
public static MyRectangle2D getRectangle(double[][] points)
The Rectangle2D class is defined in Programming Exercise 10.13. Write a test program that prompts the user to enter five points and displays the bounding rectangle's center, width, and height. Here is a sample run:
Enter five points: 1.0 2.5 3 4 5 6 7 8 9 10.The bounding rectangle's center (5.0, 6.25), width 8.0, height 7.5
This is my code so far, taking in account that Rectangle2D is already done in a previous problem.the thing is that i don't know if i have to erase public static void or do i leave it or how do i start it?
package theboundingrectangle; import java.util.Scanner; public static MyRectangle2D getRectangle(double[][] points) public class TheBoundingRectangle { public static void main(String[] args) { // TODO code application logic here } }