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
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;
how the Java-compiler manages the lifetime of objects. Aren't the variables a, b and, therefore, the objects A(i),B(i) destroyed after each iteration of the loop? Why then does the toString-method print out A(4), B(4) after finishing the for-loop?
Code:
public class mainClass { public static void main(String[] args) { C a = new A(0); C b = new B(0); for(int i=0;i<5;i++){ a = new A(i); b = new B(i); } System.out.println(a+" "+b); } }
'm working on a program that is to act as an inventory for a book store. There are two classes (Store and Book), and numerous methods which you will see in my code. The program is supposed to read in an inventory from a file which contains 10 books (each row in the file represents a book with an ISBN number, the price of the book, and the number in stock)and store this file into an array of type Book[]. There is then to be another method to process a purchase interactively. The Store class is also to keep a count of how many books were sold at the time of closing and also how much was made that day.
I'm having some difficulty figuring out how I should set up the purchase processing method though. I've written out how I think it would be set up (not too familiar with the terminology, but I think it would be called pseudo code?) I'll include that now along with a few other notes.
public Book[] purchase(String isbn, double price, int copies) { int itemsSold; double totalMade; Scanner input = new Scanner(System.in); System.out.println("Please enter the ISBN number of the book you would like to purchase: ");
[Code] ....
So basically here's what needs to be accomplished with this portion of code:
1.Ask the user to enter the ISBN number of the book they'd like to purchase. 2.Search the array for the object that contains that ISBN. 3.If the ISBN isn't found in the array, display a message stating that we don't have that book. 4.If the ISBN is found but the number of copies is 0, display a message saying the book is out of stock. 5.If the ISBN is found and the number of copies is greater than 0, ask the user how many copies they'd like to purchase. 6.If the number they enter is greater than the number of copies of that book in the array, display a message stating that and ask them to enter another quantity. 7.Once the purchase is complete I need to update the array by subtracting the number of copies of that particular book that was purchased. 8.Print the updated array. 9.Display a count of how many books were purchased, and how much money was made from the purchase.
I know that code has a lot of holes in it, but I'm just trying to get everything together and figure out how to do each step.
The part I'm stuck on right now is trying to figure out how to search the array to first see if the ISBN that was entered is in the array, and then to find the number of copies of the book with that ISBN number.
In case it will visualize what this array looks like, here's a print out of the array from a sample run I just did.
I am learning JAVA and understanding some of its specific oddities. For example I notice that JAVA loves instances but not variables.
In Python: x = 1 y = 2 print(x,y) yields (1,2)
then I do y = x and print getting (1,1)
This makes sense to me since x and y are variables and thats how variables work. In JAVA I notice this script:
public class TESTRUN { public static void main(String[] args) { int x = 0; int y = x; System.out.printf("x = %d, y = %d %n", x, y); x = 9; System.out.printf("x = %d, y = %d", x, y); } }
This yields: x = 0, y = 0 x = 9, y = 0
So I get that JAVA doesn't understand variables? Or only takes instances of variables? Is there any way to yield a true variable or you always have to update variable relationships?
I'm doing this assignment in which i have to write some products in csv file...but as u can see in csv file two products are same "Cooking Oil"..so any method that can add two same product's quantity and their amount and write them in file
import java.util.*; import java.io.*; public class SalesbyTransactionMonth{ private static final String fileName = "Data.txt"; private static final String fileName1 = "sales_by_trans_month.csv"; String line = "";
I have an assignment in which I have to design a method where I add an object at any given position in an array and shift the elements already in the array to make room. For example I have a collection class which holds trading card objects. So I wish to add a new trading card to this collection at a specified index or position with out deleting the current object already stored in the array . All this has to be done without the use of array lists, vectors or any abstract data types besides arrays . My question is how do I accomplish this . Say I wish to add a new trading card in position 4 the new card is added to my array and the card currently in position 4 gets moved to position 5 and the card in position 5 gets moved to 6 etc. The maximum amount of cards my collection can hold is 100. How would I add my trading card object to the specified position without overwriting what is currently there and shifting all other elements?Here is my current code.
public class CardCollection { public BaseballCard [] collection; final int MAX_CARDS = 100; public CardCollection() { collection = new BaseballCard[MAX_CARDS]; } public CardCollection(BaseballCard[]c)
[code]...
position refers to the position in the CardCollection and not the position inside the array.
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?
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)
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;
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.
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;
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 = "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
I was doing a project in a usual Java Application, but now maybe I have to use some tools that are contained in javafx.scene.media.MediaPlayer so I wonder if can it all work? Will javafx methods and such works?
I have to use javafx.scene.media.MediaPlayer beacuse I have to create a very simple audio player (one jbutton and one jcombobox).
The question states: Design a class named LinearEquation
for a 2 x 2 system of linear equations:
ax + by = e
cx + dy = f
Where
x =
ed − bf/ad − bc
y =
af − ec/ad − bc
The class contains:
- Private data fields a, b, c, d, e, and f. - A constructor with the arguments for a, b, c, d, e, and f. - Six get methods for a, b, c, d, e, and f. - A method named isSolvable() that returns true if ad−bc is not 0. - Methods getX() and getY() that return the solution for the equation.
Write a test program that prompts the user to enter a, b, c, d, e, and f and displays the result. If ad − bc is 0, report that "The equation has no solution."
I believe that my program is correct because I am able to compile it and get no errors, however I have no clue how to display the information for x and y or display this equation has no solution if ad-bc=0.
Java Code:
import java.util.Scanner; public class Exer911 { public static void main(String[] args){ // Create a scanner system to hold the numbers for each variable Scanner input = new Scanner(System.in); // Prompt the user to enter a number for each of the variables
I am currently working on a project where I need to return data from a database over RMI to a client who requests it. Some of the fields in the Data Object can not be seen by the client so I need to create another object to send over the network instead. The method I use is this...
public static SerializableObject createSerializableObjectFromDataObject(DataObject dataObject){ SerializableObject serializableObject = new SerializableObject(); serializableObject.setField(dataObject.getField()); serializableObject.setAnotherField(dataObject.getAnotherField()); return serializableObject; }
Is there a better way of doing this? I am creating many subclasses DataObject which all require this static method to be implemented and I can't push it into the superclass because each one needs custom behaviour.
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.
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.
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);