When I add the first car only, it puts it in the correct spot and I can move it correctly. However when I attempt to add another car, the image of the second car repaint itself onto the first one, and the second car is not functioning at all (not moving)...
I am creating the rush hour game. I am using the cars and trucks as Jlabel. I have created a 6x6 grid using GridLayout and I need to place the cars or trucks into the grid. I know how to place into a grid a Jlabel that takes only one cell. But how do you place a Jlabel that takes up more than one cell? For example, the cars occupy two cells on the grid, and the trucks 3 cells
I managed to retrieve data, and set data in my own ways in which I like. But my problem is, if the file does not contain anything (fully empty), when I try to use my
set("", ""); method, it only sets the last one that is called.
I managed to retrieve data, and set data in my own ways in which I like. But my problem is, if the file does not contain anything (fully empty), when I try to use my
I decided to write a small Java program to experiment around with BorderLayout, because I'm developing a Java game and I need to have 2 objects placed in a single JFrame at the same time, and everyone I asked said I need BorderLayout to do that.Before you answer: Also, is using BorderLayout the best option for adding multiple video game oriented objects such a sprites to a JFrame?
So the Java program I wrote is supposed to place a JButton on the JFrame and ALSO place a graphic component (a rectangle in this case). The problem is, only the button shows up, as can be seen in the image link below: URL....
Here is the code:
**main.java** --> The main method class + JFrame/JPanel/JButton constructor import java.awt.BorderLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; public class main {
I am trying to make a puzzle game in java.I have made it successfully.But the problem is,when it starts its already solved.I want it to start unsolved so the user can solve it.My code is:
I have a simple Word Program here called PuzzleGame.java. It works perfectly but I wanted to add some bells and whistles to it. So I want to be able that if the user selects the same letter more than once a message comes up letting the user know that "That letter has already been selected, try another letter."
I am certain that if would go in the 'else' of the 'if( )' that I am providing.
import java.util.Scanner; public class PuzzleGame { public static void main(String[] args){ String secretPhrase = "BIG JAVA"; String guesses = " ";
[Code] .....
I am thinking maybe after the else in this if statement.
if(guesses.indexOf(secretLetter)== -1) { System.out.print("-"); notDone = true; } else { //something here. I am not sure how to go about it. System.out.print(secretLetter); }
I have been working on a program that takes in a 2d array (there is a method to convert to 1d as necessary) and uses it as an 8 puzzle, which the program then solves (if it is solvable) using the A* Search algorithm, outputting each solution move. It needs error checkers/traps/exception handlers, and be able to create an 8 puzzle from user input, create an 8 puzzle from file input, and create an 8 puzzle from file input and then output to another file the solution move sequence. I have gotten nearly everything done except for implement the algorithm itself and the methods for handling input from files or output to files (the input/output file methods are a minor problem that I can probably solve fairly easily, I just want to be able to test the a* with the puzzle created from user input first.
I have taken several cracks at it, but I am not really good with Java in this type of situation and this is hurting me a lot. I have put in a method to determine if a puzzle is solvable, but the A* algorithm still eludes me. I understand the concept of the algorithm, you have a heuristic function, a cost function (each move equals 1 in this case), and you add the two together to get f(n), choosing the move that will get you the closest to your goal (best first search basically). here is what I have so far that works:
import java.io.File; import java.io.IOException; import java.util.Queue; import java.util.Scanner; public class Puzzle { public static void main(String[] args) throws IOException {
[Code] ....
I have it outputting things to make sure all that works already, I have all the error handlers, but I think that before I can even implement the A*search algorithm, there may be something else I need. Conceptually, I understand I need Nodes, States and Stacks, and Queues (I think, I am not sure about this), but with the way my code has been made so far, I am not sure how to implement those and then implement them with the A* algorithm. What I should do next? I have looked at the code of other uses of A* algorithm(that is how I found out I might need Java data structures like queue and stack and list), but I am not sure exactly where to go to from where I am.
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
I have i am trying to implement tooltip through javascript, like when we click on an image link tooltip should be displayed and it should have close button/ close image to close that tooltip.like the same way i will have multiple images on page, when ever i click on the images all tooltips should be displayed on the page when ever i want to close that then only it should close through close button on tooltip.can we do it through java script or will go for jquery.
I'm very new to Java, and I am creating a program that takes multiple user input to create one face. I have a class for the eyes, nose, lips, and headshape. For some reason, my program is not drawing the graphics. ***for question purposes, I have only included my head shape class and my test class****
my "test" class:
import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JPanel; public class FaceTest { public static void main(String[] args) { String head = JOptionPane.showInputDialog("Would you like a circle, square, rectangle shaped head?: ");
I am working on a text based adventure game. (This is NOT OOP at all) The problem comes in at my second if statement inside my loop, it is not adding 1 to my array locations[] it keep printing location[0] then a 1 at the end. Not really sure what is going on here. I would like it to when I type "Go north" it adds 1 to locations[]
E.G locations[0] Go north locations[1] go north locations[2] package com.PenguinGaming; import java.util.Scanner; public class Game{
I'm really struggling adding JLabels to my GUI. The code is giving no errors but the JLables aren't showing up as I think I've done something else wrong. Here's my method for adding the JLabels:
public void showGraphics(){ for(int i=0; i<message.length(); i++){ if(message.charAt(i) == '#'){ JLabel localLabel = new JLabel("test label"); getContentPane().add(localLabel); } } }
I think the problem might be to do with how the rest of the GUI is setup and the fact that I haven't specified where to add the JLabel just that I'm adding them.
The serializable class ImagePanel does not declare a static final serialVersionUID field of type long public class ImagePanel extends JPanel{ ^^^^^^^ ^ ^^2 problems (1 error, 1 warning) mh_sh_highlight_all('java');
im basically just trying to put the image inside the GUI and centre the text underneath it. Which is hard to believe since the text is above the image in the code .
I have a supermarket checkout line where i have a list of available products on the left and then a basket on the right with the products in. The products are listed in an array, here is the product class
public class Product { private String name; private double weight; private double price;
[Code] ....
with getters and setters excluded, and the list these are put into
public class productList extends DefaultListModel { public productList (){ super(); } public void addProduct (String name, double weight, double price, int code){ super.addElement(new Product(name, weight, price, code));
i have the price for each product to be displayed in a text field with the following code
addBasketItem = new JButton(); getContentPane().add(addBasketItem); addBasketItem.setText("Add >");
[Code] ....
defaultCheckoutList contains my available items and defaultMainList is the basket, with mainTillPrice being the jtextfield.
This works to get the price however it just replaces each time i make a new entry with the price for the next item, i want a total of the price of all the items i have added, but not sure how.
I want to be able to check that the data for the ID is limited to a certain collection of characters formatted in a certain. For example, I may wish to limit it to 5 lowercase letters or numbers, or a combination of both. How could I do this?
Here is my program. I have to add the outputs from variable 'done' together. It seems to not work inside or outside the loop.
//A program that will find the last/check digit of a Book ISBN number.
import java.util.*; public class ISBN { public static void main(String[] args) { Scanner kb = new Scanner(System.in); System.out.println("Enter the ISBN number>"); String isbn = kb.nextLine(); //Even though the ISBN code is a number,
I wanted to create a interface with buttons ofshapes and type of transformation where user first select a shape, the shape will appear and user will have to click on the buttons on resize, reflect, rotate or skew to transform to shape. How can i do the coding? such as adding listeners to the shapes?