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


ADVERTISEMENT

Change Frame And Focus In Card Layout From External Class / Trigger

Feb 18, 2014

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;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

[code]....

View Replies View Related

How To Get Keyboard Input Without Focus On The Frame

Jan 29, 2015

so i'm working in a chat program and i'm trying to make it so that you are able to open another tab yet still be able to chat.

right now the client that the user download uses the keyadapter to get the keyboard input, but whenever the user un-focus the chat window, the keyadapter no longer gets the keyboard input.so is there another way i can get the keyboard input? so it doesn't matter what window you are focused on, you get the keyboard input either way?

View Replies View Related

Write A Java Application To Display Layout Of Information In Typical Business Card Order

Jun 25, 2014

ABC is a company that designs and prints personal business cards. The company has asked you to write a Java application to display the layout of the information in a typical business card order. Data items in a typical business card include the customer's name, address, city, state, postcode, home phone number, and work phone number.

Write, compile, and test a Java class that displays these data items in a command window. Alternatively, you could also create it using a dialog box. Please include appropriate comments in your class.

Please named your class BusinessCard(LIM).java. (eq. BusinessCardLIM.java)

View Replies View Related

Swing/AWT/SWT :: How To Change Jbutton Color While It Is In Focus

Jan 27, 2013

refer to this code~

import java.awt.GridLayout;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.Color;
import javax.swing.JButton;

[Code] ....

View Replies View Related

Allow User To Change And View State Of Credit Card With Menu Driven Program

Apr 20, 2015

I am new to OOP, i am not sure if this is the correct approach or not. Write a class named CreditCard that has (at least) the following member variables:

- name. A String that holds the card holder's name.
- cardNumber. A field that holds the credit card number.
- balance. A double that stores the current credit card balance.
- spendingLimit. A double that stores the spending limit of the card holder.
- Bonus: additional fields that you can think of.

In addition, the class should have the following member functions:

- Constructor. The constructor should accept the card holder's name and card number and assign these values to the object's corresponding member variables. The constructor should initialize the spending limit to $2,000 and the balance to $0.
- Accessors. Appropriate accessor functions should be created to allow values to be retrieved from an object's member variables.
- purchase. This function should add the amount specified as a parameter to the balance member variable each time it is called.
- increaseSpendingLimit. This function should add 500 to the spendingLimit member variable each time it is called.
- payBill. This function should reset the balance to 0.
- Input validation: Whenever a credit card number is modified, verify that it is of reasonable length.

Demonstrate the class in a program that creates a CreditCard object and allows the user to change and view the state of the credit card with a menu driven program.

View Card Information.

- Purchase an Item: ask the user the purchase amount and increase the card balance accordingly.
- Pay Bill: call payBill method to set the balance to 0.
- Increase Spending Limit: ask the user how much the spending limit should be, and call the increaseSpendingLimit function the appropriate number of times.

[CODE]

import java.io.*;
import java.util.Scanner;
public class CreditCard
{
Scanner input = new Scanner(System.in);
//data members
private String holderName;
private int cardNumber;
private int accountBalance;
private double spendingLimit;

[Code] ....

View Replies View Related

Swing/AWT/SWT :: Change Location Of Component Using Grid Bag Layout

Jun 13, 2014

How to change the location of a grid bag positioned component after it's already been added to the layout earlier?

Example is if I want component 1 to change from row 1 to row 2.

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

Swing/AWT/SWT :: Can Mig Layout Work As Border Layout

Jun 1, 2014

I want to add only one button in a JFrame by using Mig Layout, dock south as BorderLayout.South does . Is it possible?

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

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 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

JSF :: Focus The First Element?

Apr 4, 2015

I'm creating a simple login screen and I need to focus on the first field "login" after I click a submit button, so when the page return. I tryed using JS :

window.onload = function() {document.forms[0].elements[0].focus();};

but it not worked. I need a solution if possible without using JS. I'm using raw JSF implementation without PrimeFaces or anything else like this.

View Replies View Related

How To Focus At One Component

Feb 23, 2014

I want to focus at a JTextField, how to do that? Can setfocusable work?

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

Who Keeps Track Of Which JComponent Has Focus

Aug 31, 2014

I have two JFrames: frame1 and frame2. frame2 currently has focus, and I want to determine which component of frame1 would have focus if I were to switch focus to frame1, hopefully without actually temporarily changing focus.

Is it the KeyboardFocusManager who keeps track of which element in each frame has focus? Or does each container itself keep track? How does Java figure out which element in a frame gets focus when I switch to that window?

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

Swing/AWT/SWT :: How To Customize Focus Traversal Through Tab Key

Apr 29, 2014

I'm facing a problem in controlling the focus traversal mechanism inside a jframe...as i want the focus to travel from top to bottom by pressing tab key regularly , but it travels left to right and then top to bottom through the textfields... The form looks like
textfield1 textfield4

textfield2 textfield5

textfield3

The focus travels from 1 to 4 , 2 to 5 and then rests at 3. but i want it to be like from 1 to 2 to 3 and then 4 and 5....

View Replies View Related







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