Java in-game components

I have always wanted to create a game in java but I will not use Swing components for obvious reasons. Thus I have decided to create my own in-game components. Many will be simple like buttons, checkboxes and so on. I have some questions before starting that hopefully somebody can help me with. Does it make sense to create panel/container components or layout managers? The reason I ask is because the components will only be in-game, does it make sense for all the components to be positioned on an x-y grid and nothing else? What about updating the GUI, would you recommend that active rendering should update all the components or should it repaint the components whenever necessary like AWT/Swing does? Also if anybody has done this kind of thing before, I would like to know what you have done if at all possible. I appreciate any sort of help, thank you.

Well, I did "reinvent the wheel", for two reasons : the fullscreen mode did not support awt components when I first tried to use it and I hate round looking buttons which turn out to be rectangular when you click them. You can find the gme and the source code for which I created my library here (still a lot to do but hotseat games work. The source code is contained in the download. the graphics library is in the subdirectory mk/graphics) :
http://sourceforge.net/projects/bloodbowlleague/
In this library, nothing has to be rectangular, especially buttons. If you want an animated sprite to be a button, no problem, just assign the sprite to one ore more button states of the button it represents (so it works a bit like swing I guess). I used containers, for several reasons. Most importantly, it is a good way to group displayed objects and to change the state of whole groups. The container class can easily be extended to a popup menu class or something similar. But my containers are not rectangular either. They don't even have an area. Since I didn't need moving objects to interact with the mouse yet, I use a different mechanism for containers : every time the mouse moves, the container sets a "contains" flag for every object it contains (some of the "contains()" methods of my objects take some time to execute, and I don't want to redo all checks for every frame). Only these objects will receive events, display tooltips and determine how the mouse gets displayed. If I wanted to add moving buttons, I'd add an interface between the container and the class that handles the animation, and every time an object moves, the animation class will tell the container about it so the container can recheck the state for this single object.
Another thing I used where generic constructors for nearly all display objects. Every parameter is either an object or is encapsuled in some wrapper class. It is possible to set default objects for the constructors and to use displayed objects as parameters for the constructors. This way it is possible to generate similar objects with a minimum of parameters, namely only the original object (if any) and the parameters you want to change and you can give them in any order you want (unless one parameter would undo the changes made by previous parameters and you don't want that, of course).
Well, I hope at least the stuff about containers was helpful. Have a look at the library, especially the classes XComponent, XImage and XContainer, if you want to see how I did things.

Similar Messages

  • A problem with my Java Scrabble game

    Hello
    I am making a Java Scrabble game for a school assignment and I have a problem with the following:
    The number of players is input by the user (2 to 4) and i need to create a number of arrays based on the number of players. These arrays must have 7 playing pieces at all times until the "bag" of pieces has less pieces than those required to replace the ones a certain player just used (in wich case the bag would give that player all of it's remaining pieces and, from this point on, the player arrays would not necessarily need to have 7 pieces).
    this is my procedure to take a piece from the bag:
         public Piece takePiece()
              if (this.pieceCounter > 0) {
                   Arrays.sort(this.pieces, 0, this.pieceCounter);
                   int i = this.generator.nextInt(this.pieceCounter);
                   Piece p = this.pieces;
                   this.pieceCounter--;
                   this.pieces[i] = this.pieces[this.pieceCounter];
                   return p;
              else
                   return null;
    this is my Piece class:
    public class Piece implements Comparable {
         private int scorePiece;
         private char letterPiece;
         public Piece(char letterPiece, int scorePiece)
              this.scorePiece = scorePiece;
              this.letterPiece = letterPiece;
         public int scorePiece()
              return scorePiece;
         public String letterPiece()
              return letterPiece();
         public String toString()
              return letterPiece+ " " + scorePiece;
         public int compareTo(Object a)
              Piece piece= (Piece) a;
              return (int) letterPiece - (int) piece.letterPiece;
    }Thanks in advance for your help

    Ok, if i create a Players class and do this in Main class:
         if(nPlayers >= 2 && nPlayers <= 4)
              Players arrayPlayers[];
              arrayPlayers= new Players [nPlayers ];
              for(int i=0 ; i < nPlayers ; i++)
                       arrayPlayers[i] = new Players ();
              }My Players Class should contain something like this:
             // Array of 7 that contains Pieces...
         Piece[] pieces= new Piece[7];how can i get pieces from takePiece(); (Class Bag) and put them in the pieces arrays until takePiece(); returns null?

  • Open Source Java 3D Game SDK

    On http://sourceforge.net/projects/java3dgamesdk/ you can find
    an Open Source Java 3D Game SDk. It usese no native classes.
    Features:
    - Starting in full/window screen
    - Invisible Mouse Cursor
    - Game Mouse (Cursor stays centered on the screen) and Keys
    - Loading of 3D Milkshape3D Models
    - Animating of them

    c'est bien merci...

  • Java Swing Database Components

    Heloo guys!
    Anyone knows where to download Java Swing Database Components??

    http://www.jars.com/utilities/libraries/resource.php/28653
    http://sourceforge.net/projects/jsdbc/
    create your own rather.

  • Java BluePrints AJAX Components in MyEclipse

    Hi,
    I wanted to know how to use Java BluePrints AJAX Components in MyEclipse IDE. I want to use Auto Complete Text Field in particular. Is it possible to use those components in MyEclipse? Any suggestion is appreciated.
    Thanks.

    I am unable to get the Blueprints AJAX Components it
    Failed from tools/update center and am in need of the
    autocomplete text field. Where you following these steps? http://developers.sun.com/prodtech/javatools/jscreator/learning/tutorials/2/ajaximportcomponents.html
    In what way did it "fail". What error message did you get? What where the symptoms that it failed?

  • How I can play java script game

    Hello,how I can use java script games, such a chess

    Go here: http://htmlchess.sourceforge.net/demo/example.html or http://valil.com/chess/chess_include.html on your iPad.
    Those JavaScript chess games work fine on the iPad. There are others if you Google for "Javascript chess game", but as PogoPossum said, you'll find better ones in the AppStore.

  • CRM Application Server Java and Portal components on same Java stack

    Hi Team,
    We are currently performing solution design and want some information on CRM install.
    Want to know if there is any restriction  for installing CRM Application Server Java and Portal components on same Java stack(With same SID). Also want to know if SAP WEB UIF 7.0 can work similar to that of Portal for CRM applications?
    Any information around this would be appreciated.
    Thanks

    Do You have any servlets or filters defined using annotations? Maybe one of these servlets/filters catches the '/login' request first. I have very similar solution and it works fine. Also, how do You check that the servlet under '/login' url pattern isn't invoked?

  • Simple java pathfinder game

    Hi
    Is any1 willing to make me a simple java pathfinder game in return for some money? details will be given on request...

    Sod off and do your own homework.

  • Ending Java War game with while loop

    How would i go about ending a java war game witha while loop. I want the program to run until all of the values of one of the arrays of one of the players split decks has all null values.

    GameObject[] theArrayInQuestion;
    // populate array somehow or other
    void methodWithLoop() {
       while(arrayNotNull(theArrayInQuestion)) {
       // do stuff
    boolean arrayNotNull(Object[] array) {
      int len = array.length;
      for(int i = 0; i < len; i++) {
        if ( array[i] != null ) {
          return true;
      return false
    }

  • Java 3d game

    Hi,
    I hav made first person shooter in java, but a perso with no java sdk can play it. When i put it as an applet in java it doesnt work. Plese help
    How do i paly a java 3d game on a acomputer wiht no sdk?!?

    el--davido wrote:
    an applet that i want to put into a web browser. It contains a .obj file and its saying i dont not have permission to load it when i open it using the browser.
    I jus need it to run on a computer with no sdk, in any form, browser applt or a normal appletWell, have you signed the applet? If not do it.

  • Java Card Game (Carioca)

    Hi everyone.
    Im currently making a card game in java for a south american game called Carioca
    originally i had
    CariocaController, which controlled game logic such as creating cards and players, dealing the cards setting the cards etc.
    btnStartGame in GUI would run controller method startGame which would initialize everything then set the GUI.
    CariocaTablelGUI, which extended JFrame and set the game GUI by using swingcomponents (JButtons with ImageIcons for cards)
    Card, like it says, card suit, no and value
    Deck, which created an ArrayList<Card> + 2 jokers.
    Pile which extended ArrayList<Card>. (Used for creating the 2deck game, player hands, putdown pile)
    Ive never been to good with GUI's and not enjoying my inopropriate gui structure i decided to read about java game designs.
    I read OReilly Killer Game Programming in Java chapters 1-13 before it got into 3d java. and not feeling it provided the examples i needed i went back to my old book
    Deitel & Deitel How to program Java Fifth edition. which has a case study of ElevatorSimulation which uses the Model View Controller design pattern.
    I have used this simulation as my guide to reform my code structure as i want to create this game as proffesionally and efficiently as possible.
    Now i have.
    CariocaTable which extends JFrame and in its constructor;
              // instantiate model, view and ,controller
              model = new CariocaModel();
              view = new CariocaPanel();
              controller = new CariocaController(model);
              // register View for Model events
              model.setCariocaListener( view );
              add(view, BorderLayout.CENTER);
              add(controller, BorderLayout.SOUTH);CariocaPanel in it has 4 player panels (4 player max game) which would contain their hands. then a center panel which contains the pickup and putdown piles.
    I am having alot of trouble implementing this pattern to my game (mybe im on the wrong track).
    the controller (in the ElevatorSimulation ) has 2 buttons which executes model method addPerson, thats about all the controller does which rocks my understanding.
    the model implements ElevatorSimulationListener (which extends all needed listeners) and has private variabels for all listeners.
    it then has a setElevatorSimulationListener(ElevatorSimulationListener listener) which is set with the view class.
    i have trouble understanding the communication between controller-view and model-view.. controller has to go threw model to talk to view but model only talks to view through listener methods
    public void lightTurnedOff( LightEvent lightEvent )
    //variable lightListener is the view.
          lightListener.lightTurnedOff( lightEvent );
       }i dont know where all the logic should go. i currently have model with the startGame method which creates players and cards, deals cards etc.
    am i on the right track. am i misunderstanding the design pattern? im sorry for the lengthy post, im having trouble understanding this and would like assistance with my understanding or even refer me to a book or website the would be helpful. if u would like more information please do ask.

    morgalr wrote:
    OK, I'll make a few assumptions and you can correct me if I am wrong on any of them:
    1 - the game is for 1 person to play against the computer
    2 - you may want to expend to multiplayer at some point
    3 - you would like to have the structure of the game as modular as possible to allow changesThank you for replying, yes thats exactly right.
    My approach now is to maintain the same structure as before instead of using the ElevatorSimulation as a guide.
    CariocaController will contain game logic and the static main method, and will update CariocaTable threw set methods.
    i will keep the revamped GUI classes, using what ive learned about using 2d instead of Swing Components, ive created an ImageLoader class which CariocaTable instantiates that loads all images into a hash map. PlayerPanel for each player, each panel contains variable Player, Pile hand, Pile downHand (objective of the game). Mybe i should get rid of the pile variables since the class Player already contains them?
    Its the drawing of the GUI that gets to me. Any other suggestions or ideas?

  • Need some OO design pointers for a Java card game I wrote for uni

    Hi,
    I hope a few of you Java sifus can help me understand I dilemma I keep finding myself in.
    I created a card game for a university assignment which works great but its not very OO at the moment.
    I only have 3 classes; a Card class, a Deck class and a Game class which contains all my GUI, AI, Game Controller, Player and Hand code.
    The assignment is over but I feel like enhancing the game, adding animation, multiplayer, several AI agents etc.
    The first thing I have attempted is animation and I've hit a brick wall. I am trying to create animation for my card game whereby I have an animation showing the cards being shuffled and then an animation which shows the cards being dealt to the players. The game then commences. The cards on the GUI then need to be clickable (MouseListeners?) to play the game. If you're running Windows 7, load up 'Hearts' and you'll know what I'm trying to achieve.
    I don't understand how the GUI, and Card class need to be seperated so that its good OO.
    If I give you a few snippets of code, it might explain the situation:
    A snippet of my card class is as follows:
    import javax.swing.*;
    public class Card extends JLabel //Each card is a JLabel
         private int value;                    //variable for the value of the card
         private int suit;                         //variable for the suit of the card
         private ImageIcon frontOfCard;     //Displays the image of the front of the cards
         private ImageIcon backOfCard;          //displays the image of the back of the cards
         public Card (int Value, int Suit, ImageIcon front, ImageIcon back)
              value = Value;               
              suit = Suit;               
              frontOfCard = front;     
              backOfCard = back;
              setIcon(backOfCard);     //To make it non-visible when dealt
         }As you can see, each card is a JPanel. I've been told by some I shouldn't extend JPanel but rather that I should have a BufferedImage/Image instance variable for each card as the image of the card. The thing is that I need each card displayed on the GUI which can then be clickable. When it is clicked, it is moved from the players hand, into the players move. - There needs to be an animation showing this.
    I've got the animation code figured out in terms of how to move 'images' around a screen to make a pleasing animation. The problem is there are no clickable listeners for images, so the Images needs to be inside some container; a widget which can fire events - Hence the reason I have chosen to extend JPanel for my Cards.
    and a Deck class, snippet is as follows:
    public class Deck extends JLabel //The deck will be shown on the GUI as a JLabel
         private ArrayList<Card> standardDeck;
         public Deck()
              standardDeck = new ArrayList<Card>();
              ImageIcon cardBack = new ImageIcon("CardBack.png");
              setPreferredSize(new Dimension(90, 135));
              setIcon(cardBack);
              int cardCount = 0;     //This variable counts the cards. Is used to assist in the name generation of the imageicon filename
              String str; //the imageIcon constructor accepts filenames as strings so this string holds the filename of the corresponding card image file.
              for (int a=0; a<4; a++) //putting the cards into the deck with the specifed parameters
                   for (int b=2; b<15; b++)
                        cardCount+=1;     //incrementing the card count (the card files are named 1-52 as integers)
                        str = Integer.toString(cardCount); //Integer is converted to string type before being added to string str variable
                        str += ".png"; //To complete the image filename, ".png" has to be concatenated to the string.
                        standardDeck.add(new Card(b, a, new ImageIcon(str), cardBack)); //creating and then adding the cards
         }This is how I envisage a new class diagram for my game:
    Card class
    Game Class <--- Holds a Deck instance, Players instances, and the GUI instance
    Player Class <-- Will contains hand 'instances' , but I will not create a seperate 'Hand' Class, I will use an ArrayList.
    AI Class extends Player Class
    GUI Class
    Deck Class <-- contains 52 cards
    My question is, how do I show the Cards on the GUI if my Cards are in a Deck and the Deck is held in the Game class?
    Please note that there are 52 cards, so potentially 52 images on the GUI, each of which needs to be clickable. When clicked, the cards are moved about, e.g. from the deck to a players hand, from a players hand back to the deck, from a players hand to a players current move hand.
    etc
    I've read that GUI, program control, and logic should be seperated. If thats the case, what do I have in my GUI class if the Cards (which are JPanels) are held in the Deck class which in turn is held in the Game class?
    Any help on this would be greatly appreciated!
    I know what I have written may not be fully clear. I find it hard sometimes to fully convey a problem at hand. Please let me know if you don't understand what I've written and I'll do my best to explain further.

    Faz_86 wrote:
    Hi,
    I hope a few of you Java sifus can help me understand I dilemma I keep finding myself in.
    I created a card game for a university assignment which works great but its not very OO at the moment.
    I only have 3 classes; a Card class, a Deck class and a Game class which contains all my GUI, AI, Game Controller, Player and Hand code.
    The assignment is over but I feel like enhancing the game, adding animation, multiplayer, several AI agents etc.
    Admirable, and the best way to learn, doing something that interests you.
    The first thing I have attempted is animation and I've hit a brick wall. I am trying to create animation for my card game whereby I have an animation showing the cards being shuffled and then an animation which shows the cards being dealt to the players. The game then commences. The cards on the GUI then need to be clickable (MouseListeners?) to play the game. If you're running Windows 7, load up 'Hearts' and you'll know what I'm trying to achieve.
    I don't understand how the GUI, and Card class need to be seperated so that its good OO.
    If I give you a few snippets of code, it might explain the situation:
    A snippet of my card class is as follows:
    Do a quick Google on the model view controller pattern. Your listeners are your controllers. Your JPanel, JButton, etc. are your view. The AI, Player, Card and Deck (and presumably something like Score) are your model. Your model should be completely testable and not dependent on either the controller or the view. Imagine you could play the game from the command line. Get that working first. Then you can add all the bells and whistles for the UI.
    import javax.swing.*;
    public class Card extends JLabel //Each card is a JLabel
    (redacted)
    As you can see, each card is a JPanel. I've been told by some I shouldn't extend JPanel but rather that I should have a BufferedImage/Image instance variable for each card as the image of the card. The thing is that I need each card displayed on the GUI which can then be clickable. When it is clicked, it is moved from the players hand, into the players move. - There needs to be an animation showing this.Extending JPanel is fine. As you noted, you need something to add listeners to. However, I would separate things a bit. First, a card really only has a rank and suit (and perhaps an association to either the deck or a player holding the card). The notion of setIcon() is where you are tripping up. The card itself exists in memory. You should be able to test a card without using a UI. Create a separate class (CardPanel or something similar) that has a reference to a Card and the additional methods needed for your UI.
    I've got the animation code figured out in terms of how to move 'images' around a screen to make a pleasing animation. The problem is there are no clickable listeners for images, so the Images needs to be inside some container; a widget which can fire events - Hence the reason I have chosen to extend JPanel for my Cards.
    and a Deck class, snippet is as follows:
    public class Deck extends JLabel //The deck will be shown on the GUI as a JLabel
         private ArrayList<Card> standardDeck;
         public Deck()
              standardDeck = new ArrayList<Card>();
              ImageIcon cardBack = new ImageIcon("CardBack.png");
              setPreferredSize(new Dimension(90, 135));
              setIcon(cardBack);
              int cardCount = 0;     //This variable counts the cards. Is used to assist in the name generation of the imageicon filename
              String str; //the imageIcon constructor accepts filenames as strings so this string holds the filename of the corresponding card image file.
              for (int a=0; a<4; a++) //putting the cards into the deck with the specifed parameters
                   for (int b=2; b<15; b++)
                        cardCount+=1;     //incrementing the card count (the card files are named 1-52 as integers)
                        str = Integer.toString(cardCount); //Integer is converted to string type before being added to string str variable
                        str += ".png"; //To complete the image filename, ".png" has to be concatenated to the string.
                        standardDeck.add(new Card(b, a, new ImageIcon(str), cardBack)); //creating and then adding the cards
         }This is how I envisage a new class diagram for my game:
    I am not an animation buff, so I will assume the above works.
    Card classRemove the UI aspects to this class, and I think you are all set here.
    Game Class <--- Holds a Deck instance, Players instances, and the GUI instancePresumably this is where main() resides. It will certainly have a reference to model classes (player, game, deck, etc.) and likely the master JFrame (or a controller class you create yourself).
    Player Class <-- Will contains hand 'instances' , but I will not create a seperate 'Hand' Class, I will use an ArrayList.Does a player really have multiple hands? It seems to me more of a one-to-one relationship (or a player has a one-to-many relationship to Card).
    AI Class extends Player ClassWhy extend Player? Create a Player interface, then have a HumanPlayer and AIPlayer implementation. Common parts could be refactored out into either a helper class (delegation) or AbstractPlayer (inheritance).
    GUI ClassMy assumption is that this class has a reference to the master JFrame.
    Deck Class <-- contains 52 cards
    Yes. You may end up recycling this class such that a Deck can also function as a Hand for a given player. If there are differences between the two, create an interface and have a Hand and a Deck implementation. Coding to interfaces is a good thing.
    My question is, how do I show the Cards on the GUI if my Cards are in a Deck and the Deck is held in the Game class?You need to pass a reference to the appropriate view class. That is how MVC works. The controller receives a request from the view, dispatches to some model functionality you write (such as GameRulesEngine, Deck, etc.) and returns a result to the view (which could be the same view or a different one, imagine someone clicking 'high scores').
    Please note that there are 52 cards, so potentially 52 images on the GUI, each of which needs to be clickable. When clicked, the cards are moved about, e.g. from the deck to a players hand, from a players hand back to the deck, from a players hand to a players current move hand.
    etc
    That is up to you to write the animation code. In principle, you have a mouse listener, and then you take the appropriate rendering steps.
    I've read that GUI, program control, and logic should be seperated. If thats the case, what do I have in my GUI class if the Cards (which are JPanels) are held in the Deck class which in turn is held in the Game class?
    See above.
    Any help on this would be greatly appreciated!
    You are welcome.
    I know what I have written may not be fully clear. I find it hard sometimes to fully convey a problem at hand. Please let me know if you don't understand what I've written and I'll do my best to explain further.No, you have been doing fine.
    - Saish

  • Java swing/visual components in an Oracle Form

    Hello,
    Has someone used visual javabeans embedded in Oracle Forms ?
    is there a special api or componente to use?
    I want to embed a jclass javabean in an Oracle Form (oracle forms client)
    any help will be welcome, thanks

    There are examples of white papers on OTN which show how you can integrate Java Beans into the Forms UI.
    You may have some success with Swing but forms is based on AWT/EWT of which there was only and old (and not
    very good) Swing version.
    As I said - check out the white papers and you can try the demos which are on the Sample Code page.
    Regards
    Grant Ronald
    Forms Product Management

  • HT5242 since installing this java my games in Pogo and Yahoo won't work?

    since updating to the new java for osx10.73 my games wont load in Pogo and Yahoo games...How do I resolve the problem?

    I am having a similar problem Scrabble will not load but the other two games I play on Pogo are fine. But I thought it was adobe fash not Java I downloaded yesterday?

  • Upgraded Java: Yahoo games won't load

    Just upgraded to the very latest Java (JRE-7U51) and each time I try to play an online Yahoo game, I get the following message:
    Application Blocked by Security Settings
    Name       ygames_applet
    Location   http://yog34.games.sp2.yahoo.com
    Your security settings have blocked an untrusted application from running
    I've uninstalled it and re-installed it, but it's the same thing each time.  Anyone know what I can do about this?

    Roger Barre
    Sorry to hear you are experiencing this problem with Java. As for Java, avoid the new update (Java 7 Update 51). You can uninstall Java and then revert back to the last working version (Java 7 update 45) to get apps that use java working again.
    I would suggest and I hope my post won't get taken down from Apple for advertising. Google "AppCleaner" a Mac must have! Use this utility to remove java and all of it's component files from your Mac. You can then revert to the last working version of java by running the JRE-U45 installer.
    Life is good again

Maybe you are looking for

  • The selected operation process could not be invoked.

    The selected operation process could not be invoked. An exception occured while invoking the webservice operation. Please see logs for more details. java.lang.Exception: oracle.sysman.emSDK.webservices.wsdlapi.SoapTestException: XPath expression fail

  • Photoshop Album 1.0

    Hi We have 11000+ plus photos all carefully cataloged in Photoshop Album 1.0 on my old Windows XP PC. Our new PC is Windows 7 Home Premium with Photoshop Elements 9. How do I import our existing catalog and continue sorting our new photos into our ol

  • In my library for faces all names are disappeared

    Hello I have problem with my iphoto. Before I can write a name for any faces in all my photos. I was also able to add name in photos for any faces. Now I can no more and in my library all names are disappeared. Can anyone help my for my problem ? Tha

  • ((  SQL DEVELOPER UserName Password??? --- To Access APEX TABLES ))

    How do I access APEX tables from SQL DEVELOPER? What do I use as a USERNAME and PASSWORD-- inside SQL DEVELOPER? Hello, I have APEX installed on my machine. WINDOWS 7 PROFESSIONAL 64 BIT. I also have installed: ORACLE XE and SQL DEVELOPER. I have app

  • Photos not printing right

    When I try to print photos using MS Vista OS they come out looking like negatives.  It isn't the printer itself as it prints photos fine when using MS XP OS.    What am I missing with Vista?