Mouse Clicked Error - Selecting Card?

May 27, 2014

What it's supposed to do: This code is supposed to see if the clicked card is selected. If it's not, select it and show the player where it can move / attack. If it is selected, then find out what card the player clicked on. If he clicked on the card that was already selected, deselect it. If he clicks on a friendly card (same playerID), then select that card. If he clicks on an enemy card (different playerID), attack that card. If he clicks on a tile, move it to that tile.

The problem: However, line 24-58 give me a bit of a problem. Right now, it works fine BECAUSE lines 46-58 are commented (which also means the unit can't move). If I uncomment those lines, the unit becomes able to move, however, lines 34-46 cease working...

Java Code:

@Override
public void mouseClicked(MouseEvent e) {
mainloop: for (int i = 0; i < Main.cards.size(); i++) {
Card c = (Card) Main.cards.get(i);
if (Card.cardSelected == null) {// Contains / Is not selected
if (c.contains(e.getX(), e.getY())) {
Tile.reset();
Card.reset();
Card.cardSelected = c;

[Code] ....

View Replies


ADVERTISEMENT

Swing/AWT/SWT :: Icons Should Drag Starting At Point Where Mouse Originally Clicked Down

Apr 23, 2014

I am working on a simple app that should emulate a desktop with some icons that you can drag around. I was instructed to use the MouseListener and MouseMotionListener. The icons should drag starting at the point where the mouse originally clicked down on it (ie not dragging from the top right corner).

I am drawing my icons to a jpanel, and I seem to be having two problems:The hitboxes are offThe icon is being dragged from the top right corner, despite having setup up a mouse offset at the beginning of the drag..Here are the relevant classes, the Desktop.draw() method is being called from my DrawPanel

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Desktop implements MouseListener, MouseMotionListener{
static DesktopIcon[] icons;

[code]...

View Replies View Related

Swing/AWT/SWT :: Window To Submit Data Freezing When Created Inside Mouse Clicked Event

Feb 18, 2014

I'm trying to right a GUI in swing, and as part of my program, I want to open a secondary window out of the main window when a mouse clicks on the main window. Then, once I click a button on the secondary window, I want that window to close and submit data to the main window (like an info form). I have almost figured out how to do this, except for one problem. By putting a variable inside my form window called "ready," and then in my main window running a loop that constantly checks if ready is true and doesn't proceed until its true, I can create the form window, modify the values in it (currently just one value called "difficulty" that's modified by a jSlider), and then when i click the "begin" button, ready is changed to true, the form window closes, and the main window can proceed. However, when I try to put the while loop checking the ready variable inside a mouseClicked method in the main window, the form window freezes when it opens, and you can't see any of its content or modify it in any way (you can't even close it).

Here is my code:

//form window class
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class formWindow extends JFrame {
private JTextField instructions1;

[Code]...

View Replies View Related

Trading Card Game - Each Card Can Be Moved Around Like Chess Pieces

May 10, 2014

So I'm making a trading card game and each card can be moved around like chess pieces. So far, I've made the cards simple rectangles and detect if clicks are made within that rectangle and then move them appropriately, but I'm not sure if that's the best solution.

View Replies View Related

GUI When Selecting Check Box

Jul 9, 2014

I am having an issue with my swing gui. I dynamically create tabs with information (textfields, checkboxes, combo boxes) and when I select the checkbox it disables or enables a textfield. Now when I select the checkbox it seems to resize everything, specifically my textfields from say 9 columns to probably one. I"m a little unsure why it is doing this but I have a feeling it may be an inheritence issue.

My code is below for my generation of the tabs and of the rest of the information on the gui. The gui is an inner rid layout with a top and bottom pane that are both gridbaglayouts and an outter pane as well. I am thinking I am missing something in the grid layout setup that is causing this.

private void initComponents() {
jTabbedPane1 = new javax.swing.JTabbedPane();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
getContentPane().setLayout(new java.awt.GridLayout(1, 0));
pack();

[code]....

View Replies View Related

How To Populate JTable By Selecting ComboBox Value

Sep 25, 2014

How can I populate the jTable in my form by selecting value from combo box. And remember I have database as well.

View Replies View Related

Hashmaps - Selecting Keys / Values

Apr 22, 2014

I'm learning Java using BlueJ, I have made a class that has a HashMap of (String, String) that contains an the make of a car and the model.

I want a method to return a collection of all the keys that satisfy a condition, like if someone wants to find what make a certain model is. I know it requires a loop, just not too sure how to write the loop to satisfy the condition.

View Replies View Related

JavaFX 2.0 :: Re-selecting Item From ListView

May 14, 2014

I have a selection listener attached to a TreeView as shown below
 
treeView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<TreeItem<Pair<VideoSourceType, String>>>() {
   @Override
   public void changed(ObservableValue<? extends TreeItem<Pair<VideoSourceType, String>>> observable, final TreeItem<Pair<VideoSourceType, String>> oldValue, final TreeItem<Pair<VideoSourceType, String>> newValue) {
        // do something
       treeView.getSelectionModel().clearSelection();
   }
};
 
What I want to do is to "do something" and then clear the selection so that it can be selected again. However, I cannot re-select the same item from the TreeView until I first select a different item.

View Replies View Related

LWJGL - Selecting Specific Region Of Image

Jan 20, 2014

I want to render a specific region of an image in LWJGL,

View Replies View Related

Random Card Generator

Mar 16, 2015

I've been trying to get a card generator working, but hells bells nothing is easy in java (unless you already the correct answer) trying to figure out the correct way to apply a method you don't understand is like being asked for the German word for banana in Spanish class.

import java.util.Random;
import java.util.Scanner;
class jacktest
{
public static void main ( String[] args ) {
Random r = new Random();

[code]....

my next step might be using object (hammer >=computer)=watch telly instead.

View Replies View Related

Matching Drawn Card To Its GIF In ArrayList?

May 4, 2015

I'm creating a card game and I'm having trouble getting a card gif to display. A card is drawn from an 52 card deck arraylist, and I then need to match that drawn card with the similarly named gif in an arraylist of card gifs, to display the gif on a card GUI. I have put my game, card, deck and graphical class below:

Card -
public class Card {
public String number;
public String suit;
public Card(String n, String s) {
number = n;
suit = s;

[Code] ....

The arrayList of card gifs (which contains all 52 gifs for the cards) is in the graphical class and my arrayList that contains the deck of cards in textual form (that I've imported from a textfile) is in deck. The names of the gifs in the gif arraylist are the same as the card names in my textual card arraylist (for example, 3h.gif is 3h in my card arraylist), so I believe I can use a .equals statement to match the card that has been drawn to the gif.

Here is what the gifs look like in their folder, which is an arraylist in my graphical class :

Here is what the drawn card looks like after the textual card arraylist has been shuffled:

The brown card in that image isn't the displayed card that has been drawn, it's just a graphical deck that I put in, I can't get the card that has been drawn on the GUI to display on the actual card frame, as you can see.

View Replies View Related

Card Game War Comparing Rank

Oct 30, 2014

I am making the card game War, I have gotten fairly far without a huge snag but I have been working on this. I need to compare 2 cards to find the larger of the 2. I have a function that will do that, but it is comparing the wrong numbers. The function is comparing their index values but I need it to compare the card value. The card value is found at rank(card).

import java.util.Random;
import java.util.List;
import java.util.ArrayList;
import java.util.Deque;
import java.util.ArrayDeque;
import java.util.LinkedList;
import java.util.Collections;
 
[Code] ....

View Replies View Related

Random Bingo Card Generator

May 26, 2014

I'm trying to create a program that will be able to generate random Bingo cards. This is what I have so far.

Java Code:

import java.util.Random;
public class BingoCard
{
private int[][] card;

public BingoCard(Random random)
{
card = new int[5][5];
for (int c = 0; c < 5; c++)

[code]...

The problem with this program is that even with the checkForDuplicateValues method, which checks for duplicate values of a column and replaces the values, it still prints out bingo cards with duplicate values!

View Replies View Related

Implementing A Card Game In JAVA

Apr 19, 2015

I am facing with a JAVA code needed for my assignment.We are implementing a Card Game.. There is a Card Class which i have not included in the code below .We have a Dec class that has various arrays..

privateCard[] masterPack >> Is a master Pack that is initialized once and has all the 52 cards.

private Card[] cards >> Is the array that has the card values from masterPack array.

My problem is :

After I called the Deck object D1, it goes to the Deck COnstrucutor OK.It then populates the values of masterPack as per the allowmasterPack method.Then it stores the values of masterPack into cards array in the init method..I get an exception when line below is executed..

cards[pack * 52 + k]= masterPack[k];

I get a java.lang.NullPointerException error..

public class debug
{
public static void main(String[] args)
{
int pack = 1;
Dec D1;
D1 = new Dec(pack);

[oode]...

View Replies View Related

Java Application - What Certain Card To Be Validated

Jun 19, 2014

I have situation where i have hard coded values

this is my use case

I have a table called card which got list of card ,now in my java application i got validation which what certain card to be validated e,g mastro, visa, amex etc now i have problem when i create new card its throwing error because the new card is not in the hard coded values, the new card is not affected by the validation. How to approch this ....

View Replies View Related

Prepaid Card - How To Call A Constructor In Main

Jul 3, 2014

I am trying to call a constructor from PrepaidCard class in my main method, but I am not sure how to proceed.

As seen below, both the PrepaidCard constructor and the setCardID method have the ability to set the card ID.

Java Code:

public class PrepaidCard {
public PrepaidCard(String id, int token) {
cardID = id;
tokenBalance = token;
} public void setCardID(String id, int token) {
cardID = id;
tokenBalance = token;
}
} mh_sh_highlight_all('java');

Now in this block of code, I can successfully pass the id and token value by calling the setCardID method from the PrepaidCard class.

Now I would like to call the PrepaidCard constructor from the PrepaidCard class to pass the id and token value, instead of using the setCardID method.

Java Code:

public class PrepaidCardTest {
public static void main(String[] args) {
PrepaidCard card2 = new PrepaidCard(id, token);
System.out.print("Enter Card2 cardID: ");
id = input.nextLine();
card2.setCardID(id, token);
}
} mh_sh_highlight_all('java');

How to call the PrepaidCard constructor from the PrepaidCard class, to successfully pass the id and token value, in my main method?

Specifically how to modify or replace this line of code so that it can correctly call the PrepaidCard constructor?

Java Code: card2.setCardID(id, token); mh_sh_highlight_all('java');

View Replies View Related

Change Frame And Focus In Card Layout

Feb 18, 2014

I'm nearing the final development stages of my first game, but have run into a problem. I've constructed 4 different levels and allow the user to select the level they want to play from a central JPanel in a Card Layout system. My problem is that once a level is completed, I can't switch the JPanel which is displayed to start the next level, since I don't know how to access the original JPanel which acts as a driver for the other panels.

MainFrame.java

Java Code:

import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Font;

[Code] ....

View Replies View Related

JRE :: Could Not Reserve Enough Space For Card Marking Array

Jan 6, 2015

# java -d64  -Xms1024M -Xmx2048M -version

Error occurred during initialization of VM

Could not reserve enough space for card marking array ...

View Replies View Related

Design Class - How To Organize Classes For UNO Card Game

Mar 20, 2014

I'm currently taking a computer program design class which has done a lot for my understanding of how to organize classes, but isn't giving me challenging enough assignments and I don't believe it's going to be covering interfaces and abstract classes, which is a shame. So I've been digging into these topics myself and decided to work on my own program (an Uno game program) that would utilize everything we've been learning and give me some practice with GUIs.

My current plan:

Have an abstract UnoCard class that determines the basic properties/methods common to all cards. Create a class for each card type extending from UnoCard, which would be - the generic card (number and color), action cards (skip, reverse, draw two), and special cards (wild, wild draw four, and blank).

Two enums, one for color, one for rank (which includes the numbers, as well as the action and special card ranks (reverse, wild, exc.) ).

A deck class would have an ArrayList <UnoCard> property and it's constructor would initialize a fresh deck.

A hand class that also has an ArrayList <UnoCards> where it gets said cards from the deck class.

A discard pile class, which contains the cards discarded and the current card in play.

A "board" class (haven't figured out a better name for it yet) which would determine/keep track of the number of players/hands, the turn order, the locations of the cards, and the winning condition.

Area of confusion and concern I'm having:

From what I've read, I want to avoid circular dependency. So if that's the case, when a card type effects the state of a "hand" or the turn order or really anything else, then in what class do I place the method(s) that effect that? If I place it in the specific card class, wouldn't that create a circular dependency? So would it be better then to have the hand class figure out what can be done with a specific card and what that specific card effects (which wouldn't that hinder the cohesion of the class?)?

I was also thinking a possible solution might be to have the non-generic card types contain methods that return values as apposed to manipulating higher level classes, such as a boolean drawCards which returns true if cards need to be drawn, false otherwise (same for skip, reverse, exc.).Then maybe the board class can determine what to do if those values are true or false (which actually seems more convoluted since only one value would be allowed to be true at any given time).

The other solution I was considering is to have a single UnoCardRules class, which serves the sole function of providing methods to determine the effects of each card, that way each card class can only worry about defining the card's state.

View Replies View Related

5 Card Stud Game - Constantly Repainting Screen

Apr 11, 2014

I am currently making a 5 card stud game for my Java Programming class at my highschool. I am deciding to go a little above expectations and make my poker game a little more fun than just comparing a few cards. However I want there to be text that is changing on my screen, but the repaint() is not the most reliable way to make the screen update, I am wanting a way for have the program constantly update the screen so that if I do something like someLabel.setText("Text"); then the text will update automatically whenever it is changed.

Here is my declarations and main/constructor method

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Random;
public class FiveCard extends JFrame implements ActionListener {

[Code] .....

Here is the method addMainPage, which is called in the constructor. Whenever the enterButton is pressed, the actionListener directs it to loadBoard();

I use GridBag Layout, so to skip through all of the constraints

public void addMainPage() {
for (int i = 0; i < 4; i++) {
players[i] = new Player();
}
Icon cardBackImage = new ImageIcon("back.gif");

[Code] .....

Game intro is a method that changes the text of a label every second using .setText(), however it does not work because the enterButton is pressed, then after loadBoard() and gameIntro() is ran, it repaints the frame with the board objects and the gameIntro's final .setText() command.The action listener is simple...

public void actionPerformed(ActionEvent e) {
if (e.getSource() == enterButton) {
players[0].setName(playerNameField.getText());
loadBoard();
}
p.repaint();
}

View Replies View Related

Deck Card Game - Creating Classes For Code

May 17, 2014

I created the below code and it works fine. It is a deck card game. I just want to divide my code into classes so that it seems more organized.

Java Code:

package getimage;

import java.awt.BorderLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Collections;
import javax.swing.*;

[code]....

View Replies View Related

How To Go From One Method To Another When Jbutton Is Clicked

Apr 2, 2014

Is it possible to go from one method to another when a jbutton is clicked?

View Replies View Related

How To Know JButton Is Clicked In Another Class

May 26, 2015

I have two classes one is called main.java another is called Gui.java

in gui.java, will create a JFrame and some component.here is some code in main.java.

Java Code:

public static void main(String[] args){
while(true)//will always loop once user close the window
Gui gui = new Gui();
gui.setVisible();
if()//at here need to determine button in Gui.java is press or not to process the user input
{
String fromUser = gui.Jusertxt.getText();
}

} mh_sh_highlight_all('java');

what is the code need to use to know Button in Gui.java is clicked or not? i try use method to return true value, but in not working.

View Replies View Related

Random Shuffle Array Of Card Objects Which Does Function Of Deck

Oct 26, 2014

I have to random shuffle an array of Card Objects which does the funcion of a deck. Heres the code:

Java Code:

public void barajear(){
int j;
for (int i=0;i<52;i++){
j=Baraja.random(51);
if (this.mazo[j]==null){
this.mazo[j]=this.arreglo[i];
}else{
--i;
}
}
} mh_sh_highlight_all('java');

so bassically theres an array called "arreglo" which has the cards in order and the function "random" its an rng of numbers from 0 to 51.what i'm trying to do it's to take the cards from the ordenated array and put them randomly in the other but only if it's empty.(the array "mazo" has alredy been initialized with null).it worked at first, but now, after compiling succesfully i tried to run it and the cmd just...

View Replies View Related

Play A Sound When Button Is Clicked?

Mar 20, 2014

im trying to play a sound when button is clicked. here is the following code

InputStream in;
try {
in = new FileInputStream(new File("failure1.wav"));
AudioStream audios = new AudioStream(in);
AudioPlayer.player.start(audios);
} catch (Exception e) {
}

just wondering why it does load;

i do get the warning

warning: AudioStream is internal proprietary API and may be removed in a future release
AudioStream audios = new AudioStream(in);
warning: AudioStream is internal proprietary API and may be removed in a future release
AudioStream audios = new AudioStream(in);
warning: AudioPlayer is internal proprietary API and may be removed in a future release
AudioPlayer.player.start(audios);

View Replies View Related

How To Get Data Inside Table Row When That Row Is Clicked

Dec 19, 2014

I am using netbeans swing to do my little project . I have one table which is populated by data from a database. I also have another table which should be populated when a user selects a certain row in the first table.Both table have only one column. The logic is when a user selects on row 1,the data in that row should be obtained and should be used to search for certain entities in the database which are returned and used to populate table 2.So after a user selects row1 and decides to select row2 the second table should be updated accordingly. I have attached the java file

/*
* 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 UI;

import java.awt.CardLayout;
import java.sql.SQLException;
import java.util.logging.Level;

[Code] ....

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved