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
ADVERTISEMENT
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;
[Code] ....
View Replies
View Related
Apr 5, 2014
I am trying to detect the collision between a moving Jbutton and stationary Jbuttons using Rectangle Intersection.
When I run the program I am getting a NullPointerException on line 'msg1.setBounds(new Rectangle(320,50,400,50));'.
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class gamePanel01 extends JPanel implements KeyListener {
character ch1 = new character("Hero");
//Global Variables
JButton blocker01;
JButton blocker02;
[Code]...
View Replies
View Related
May 14, 2014
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();
[Code]...
View Replies
View Related
Mar 22, 2014
I have a text file that has contents as follows:
testing1,true,0,0.0,0,0.0,4.0,0.0,0.0,0.0,0.0
test2,true,0,0.0,0,0.0,4.0,0.0,0.0,0.0,0.0
I am trying to read only the first item in each list using a comma as a delimiter using the following code.
public String[] pList() {
ArrayList<String> names = new ArrayList<String>();
String word;
try {
String path = P_FOLDER + P_FILE;
[Code]....
View Replies
View Related
Aug 4, 2014
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.
View Replies
View Related
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
Oct 2, 2014
I need to make a program that does stripes, checkerboard, and double diagonal. I can not get the stripes to work?
import java.util.Scanner;
public class AsciiArt {
public static void main(String[] args){
int pattern;
Scanner input=new Scanner(System.in);
System.out.println("Choose one of the following patterns by pressing the corresponding number");
System.out.println("1) Stripes");
[Code] ....
View Replies
View Related
Jul 24, 2014
The area of a square is stored in a double variable named area . Write an expression whose value is length of the diagonal of the square. Do I use math.sqrt?
View Replies
View Related
Feb 7, 2015
Coding (must follow pseudocode algorithm provided) for comparing characters of a word to a puzzle board char[][].
I've gotten the horizontal and vertical searches to work, but I'm having a difficult time figuring out how to search diagonally.
Here's the search algorithm format I have to use:
for each guess word
for each letter of the puzzle
for each letter of the guess word
check for diagonal match
if found, add word to list, break to next guess
I'm assuming there should be a +1 horizontal offset after I find the first letter, but every index I've bumped has caused me to screw up my array bounds. I'm missing something.
Here's the algorithm I'm using for diagonal search. This same algorithm worked for vertical search (minus the offset of course)
//diagonal search
for(String word : guessWords) {//for each guess word
int letterCount = 0;
int index = 0;
for(int j=0; j<grid[index].length; j++) {//for each puzzle letter
[Code] ....
View Replies
View Related
Nov 21, 2014
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..?
package com.example.crazysellout.UserSide;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
[Code] ....
View Replies
View Related
May 5, 2014
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,
[Code]....
View Replies
View Related
Sep 10, 2014
Write a program that accepts the line number from the user and prints only that particular line from the Floyd triangle.
Example:
Input: 2
Output: 2 3
Input: 3
Output: 4 5 6
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
Oct 15, 2014
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;
[code]...
View Replies
View Related
Oct 20, 2014
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?
View Replies
View Related
Apr 12, 2014
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?
View Replies
View Related
Dec 8, 2014
how to read file line by line ? Namely my input file I want to read look as follow:
AAA 1, 1
12 222 12
AAA 2, 2
11 122 11
My output file should look as follow:
1, 1, 12
1, 1 222
1, 1, 12
2, 2, 11
2, 2, 122
2, 2, 11
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
{
[Code]....
View Replies
View Related
Dec 12, 2014
I am checking how to do following task.
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?
View Replies
View Related
Apr 12, 2014
obstacleX = (int) (obstacleX - 0.1);
if(obstacleX <= 0){
obstacleX = 600;
}
repaint();
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....
View Replies
View Related
Sep 17, 2014
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
}
}
View Replies
View Related
Apr 21, 2015
in order to speed up my application I want 'paintComponent(Graphics g)' to only write the visible area in my viewport. I can not find how to get that Rectangle from my JScrollPane.
View Replies
View Related
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
Jan 30, 2014
So I've been getting back into Java and downloaded eclipse back onto my laptop. However when I go to make a simple rectangle into a JFrame, the frame will pop up but no rectangle will be shown. Here is my main class, which sets up the JFrame...
mport javax.swing.JFrame;
public class Frame{
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setTitle("I hope this fucking works");
frame.setSize(400,400);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
[code]....
View Replies
View Related
Apr 13, 2014
Is there a way to simply slap a rectangle into a JPanel (make it appear) with out creating an inner Class or helper Method, all within "Main"? And if not, why?
Making a JFrame is easy.
Adding a JPanel is a snap.
import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class TheJFrame {
public static void main(String[] args) {
// TODO Auto-generated method stub
[code]....
View Replies
View Related
Nov 14, 2014
MyGraphics worked before I added a background but, even now when I take the background away it isn't showing up.
package com.snow.game;
import javax.swing.*;
import java.awt.*;
class MyGraphics extends JComponent { //creating a class for graphics
public void draw(Graphics g){
//calling Graphics making a new graphics (g) now you can use it to make objects
g.drawRect(10, 10, 50, 50); //Draws a rectangle
[Code] ......
View Replies
View Related