Matrix Icon / Button Movement
Apr 30, 2015
I'm working on making a game in JAVA. To be brief, the game is on a 6x6 matrix called "blocks[][]". The game has two players and the objective is to capture the enemies pieces by moving your piece onto there's. The players do this by moving one piece per turn either forward/backward (Vertically) or right/left (horizontal) movements. Essentially checkers without jumps.I'm not very far into the development process here. So far I have the game board created and the pieces load by clicking the "Start" button (handled by the refresh function). However I'm having a few problems... Namely moving the pieces effectively at the moment.
Right now there's a lot to do:
(1) - Implement a turn system,
(2) - Only allow a player to click their pieces (I've a validation function already in place to only permit valid moves [horizontal/vertical only]),
(3) - getting the pieces to actually "move" what I mean by this is a player selects the piece they want to move, then they select the spot they want to move to and the icon I have placed on the button is supposed to be added to the new square and the icon for its previous position is to be made null.
Please see the "actionPerformed" section to see exactly what I'm trying to do and hopefully as well see what I'm missing as to why it is not working at the moment... Also see under the Refresh function where I commented out the for loops to add the pieces. I did this because it was resulting in an ArrayOutofBounds error so I just wrote each spot out manually where I wanted them to start.
/* Ghosts *
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
import java.util.Random;
import javax.swing.JButton;
import javax.swing.border.*;
import java.io.*;
[code].....
View Replies
ADVERTISEMENT
Jan 30, 2015
So I have got a button and there is this property assigned to it:
button.setIcon(new ImageIcon("srcimage.jpg"));
The icon is not displayed in full, as it is larger than the button. What property can I use to resize the icon? I have tried few and it did not work.
View Replies
View Related
Dec 5, 2014
java program that will determine if the matrix is a lower or upper triangular matrix. I only need to use java.util.Scanner;.
View Replies
View Related
Feb 11, 2014
I have been working on this mouse movement code that detects which direction the mouse moves in hope to use it in a game. The only problem is that I can not figure out how to make it move to the other side of the screen so I could continue turning to the right or left without having to stop. How would I actually get the x and y coordinants of the mouse to change?
PHP Code: if(x == xscreen){
//set x to 0
}else if(x == 0){
//set x to xscreen
}else if(y == yscreen){
//set y to 0
}else if(y == 0){
//set y to yscreen
} mh_sh_highlight_all('php');
View Replies
View Related
Jan 23, 2014
First, I have a figure that moves around the screen. It uses keylisteners and just subtracts or adds pixels. However, I notice the movement is not smooth at all. It is very rigid and laggy movement. How can I make it smoother movement?
Second, you get three lives in the game. The lives are subtracting correctly, but I want the game to say "GAME OVER" on a dialog box. How would I get this to happen? My JFrame and my life int are in separate classes. I know I should use an if statement, saying if lives are at or less than zero, open the box, but how do I open the box?
Third, I want to display the time on the screen. I have a swing timer, but how do I put it on the screen? DrawString is not working for me.
Fourth, I want to set an icon for the game, the code is running, but not doing anything.
Java Code: frame.setIconImage(Toolkit.getDefaultToolkit().getImage("/Users/MW/Downloads/petericon.jpg")); mh_sh_highlight_all('java');
View Replies
View Related
Feb 13, 2015
I'm relatively new to Java, I'm trying to create a text based game, like those old ones where you type "north" or "east" to move as such, and "look" to inspect the area. My only problem thus far has been trying to figure out just how I should... "structure?" the movement. As in, what's the best overall way to approach this? I've tried making a new method for every area and just passing a variable called "location," but along with passing the inventory and stat arrays, it's just become messy. Or is this a good way to do it? I have a separate method for when the player enters something, but then how will it know which description to give when the player types "look?"
View Replies
View Related
May 28, 2014
I am new to DreamInCode! I was creating a game using OpenGL (and slick for textures).
Using Vector3f, I make coordinates to where my camera is camera'ing (and rotation).
It was working... until I modified something. I only added shaders. When I took the shaders off I think I might of accidentally deleted something. Nonetheless the code looks perfect to me.
On the method "input()" everything runs. No errors are thrown anywhere. I have syso'd the hell outa my code. It shows no signs of breaks. I can, however, move elements I put into my program. I am 100% sure that no other class is breaking my game (soon to be).
What you should look out for: I am not really sure about the glLoadIdentity()'s and glMatrixMode(). I am, knowing a good part of, thinking it could be gluViewPort....
My problem: Can't move my camera even tho it was working before.
package com.Hydroque.OpenGlTest;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.util.glu.GLU.gluPerspective;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
[Code] ....
View Replies
View Related
Jun 16, 2014
I am working on replicating this project: [URL] ....
What is wrong with the moveSnake method and the for loop within it?
View Replies
View Related
Aug 31, 2014
I just started to learn Java. In my program, I created a GRect(paddle) and I would like to move it on the x axis whenever the mouse is moved.
import acm.graphics.*;
import acm.program.*;
import acm.util.*;
import java.awt.*;
import java.awt.event.*;
public class BreakoutClass extends GraphicsProgram {
/** Width and height of application window in pixels */
private static final int WIDTH = 400;
private static final int HEIGHT = 600;
[code]....
In this case, whenever the paddle reaches the right edge of the screen, it doesn't move off the windows, but it stops moving (even if you move the mouse).
View Replies
View Related
Aug 18, 2014
how I would go about having a moving sprite on a page, such as a virtual pet kind of thing. I've tried searching for it through the years and I've tried it with what I know on my own, but things just act up every time. Either:
A.) The sprite moves (respondent to key strokes, of course), but leaves a trail of its image behind itself.
B.) The background image writes, but for some reason the second image does not write, or is lost behind the background.
I'm sure these are simple issues for most of you, but I've tried going about this for a while now with no luck. What I'm trying to do I'm trying to write a virtual pet game, and I would eventually love to make it move around randomly like an A.I. that's pathfinding, but I've got ideas about that, just I need to know how to make it move period first, everything else I think I could figure out on my own.
View Replies
View Related
Oct 30, 2014
I need the following key controlled ellipse to leave a trail behind that vanishes after 10 frames. Also, I need to create a random moving ellipse not related to the preexisting one. How to separate the two ellipses ...
Current code:
boolean left, right, backward, forward;
boolean SPEED;
PVector pos = new PVector(680, 400);
void setup() {
size (680,400);
fill (0 ,0,0);
frameRate(100);
noCursor();
[Code] .....
View Replies
View Related
Apr 13, 2014
I'm working on this space invaders game and I've been stuck trying to get the alien spaceships to move down in one group. The way we have to design the game is we have to implement at least these 3 classes. These classes are GameData,GamePanel, and Animator. GameData is all the action figures/models in the game. GamePanel draws all game action figures/ models on the screen. Animator updates periodicaly action figures positions,sizes, colors etc. I can get the aliens to move right but once they hit the end of the canvas I cannot figure out how to get them to move as a group down and then begin moving left. I tried to add alien objects to the GameFigures list and then have the update method in the Alien class be responsible for moving the alien ships, but I couldn't figure out how to make it work. So then I made an alienFigures list in the GameData class and I still cannot figure out what to do. Here is the GameData class
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
[code]....
View Replies
View Related
Mar 25, 2014
I've been creating a digital clock using Java, and have made the mouse cursor invisible after a set period of time (40-seconds) and had the thought to make it visible again if mouse was moved.
Here's the code that makes it invisible:
ActionListener mouseTimeout = new ActionListener() {
public void actionPerformed(ActionEvent e) {
setCursor(blankCursor);
}
};
/* Make mouse cursor disappear after 40 seconds */
Timer mTimeout = new Timer(40000, mouseTimeout);
mTimeout.start();
And here is what I have so far for making it visible again:
MouseMotionListener mouse = new MouseMotionListener() {
@Override
public void mouseDragged(MouseEvent e)
{
}
@Override
public void mouseMoved(MouseEvent e)
{
}
};
I have tried using "setCursor(DEFAULT_CURSOR)" but NetBeans says that it "cannot find symbol" .....
View Replies
View Related
Jan 26, 2015
I made a kind of maze game that includes the class keylistener and orients a object, i can't find where the program tracks this object (where its x and y coordinates are). So now my object can move freely through all walls and i want it to bounce back or at least something to happen when the object reaches a wall.
I want to find a way to limit my objects movement and because i cant find where the coordinates or variable for this object is i cannot limit its movement
View Replies
View Related
Mar 7, 2014
My OrderCalculator class is throwing an exception. The input from my HourPanel that is supposed to add to my OrderCalc is cooperating.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.text.DecimalFormat;
public class OrderCalculator extends JFrame
{
private JobPanel jobs;
private HourPanel rate;
[Code] .....
View Replies
View Related
Sep 4, 2014
How to catch the event when table view's column are re-positioned. Basically when the column is re-positioned from 1 position to 5 position , i want to do update the db.
View Replies
View Related
Feb 15, 2014
So I'm in the middle of creating a model program with voxels. I want to be able to see how the model looks like when I'm in for example my documents (not inside the real program). I want it to show an image of the model, just like a png file shows its image. I've tried looking around, but I've only found threads about changing exe files icon.
Image example:
So, is this possible in Java or do I need to use c/c++ (with JNA) to make this possible?
Or is it not possible at all?
View Replies
View Related
Feb 23, 2014
Recently I have been working on an executable launcher. I tried to get the executable icons and set them on the JButtons. Still there are some problems. Here is a part of the code:
try {
button[i].setIcon(FileSystemView.getFileSystemView().getSystemIcon(new File(getConfig("path." + (i+1)))));
}
catch (NullPointerException ex) {
}
Here the getConfig() method is already defined to get a string in a "properties" file. However, the icons are very small and they don't fill the entire button.
How can the icon fill the entire button (for example, having a custom size of 48x48, or automatically filled the button)? The frame will not be resized.
Here is the whole code...
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.io.*;
import java.io.File.*;
[Code] ....
View Replies
View Related
Aug 15, 2001
Any way to resize an ImageIcon when placing it on a Button so that I don't have to physically rezize the image file?? I am writing an Application, not an applet, so the getImage method won't work.
View Replies
View Related
Dec 2, 2014
how to display a jpg image on a through a Jlabel. I am sure it is a simple error but I am still new to GUI's. line 31 to 35 you can see the ImageIcon and file wrapped in the JLabel. I verified its in the correct location and file name, but usually fails (i thought) when it is not correct.
Java Code:
import java.awt.BorderLayout;
import java.awt.Color;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
[code]....
View Replies
View Related
Sep 8, 2014
how to change my jar file's icon with an image?
View Replies
View Related
Oct 20, 2014
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.ImageIcon;
[Code] .....
I want the Jbutton Button1 icon to change when i click it howerer i am getting the error can not find symbol for the code in the actionPerformrd method.
View Replies
View Related
Nov 12, 2014
I have a problem I must solve and could not find an answer after a couple weeks of research, so here I am. I have created a custom Table Cell Renderer than extends DefaultTreeCellRenderer. The mission of this renderer is to set the branch icons depending on conditional statements. There are 3 conditions, and each one should render a different icon. These conditions must be tested against all branches in the tree. This means that using something like setOpenIcon() and setClosedIcon() will not work since it seems as though these methods set all branches to a specific icon (I could be wrong about that though). Below is the code for my custom. I made comments so it is easier to understand what I want to happen and what is not happening.
/**Custom Cell Render that will set the icons for the tree branches and the leafs*/
private TreeIconCellRenderer extends DefaultTreeCellRenderer{
public Component.getTreeCellRendererComponent(JTree tree, Object value,boolean selected,boolean expanded, boolean leaf, boolean row, boolean hasFocus){
//Get defaults in case there is no need to renderer
[Code] ...
What I really need to know is why the renderer is not differentiating between the leaves and branches. The logging statements I have added confirm that the branch block of code does not execute.
View Replies
View Related
Feb 12, 2015
Why the label wont show the file. The file is located within the project.
View Replies
View Related
Apr 27, 2014
Need to know where can I get archive for all kind of .gif icon.
View Replies
View Related
May 21, 2013
JFrame frame = new JFrame();
frame.setIcon("aaa.ico");
JDilaog dialog = new JDialg(frame, "dialog" , true);
so the dialog has its owner frame, which is neccessary but i want the dialog has another icon ,or remove the icon on the dialog how may i do ?
View Replies
View Related