Event model in swing

Since swing is a light-weight system,
why does it use awt event model?
Will it fall back to a heavy-weight system?

Swing components are derived from AWT components (java.awt.Component). If the AWT event model ain't broke, don't fix it.

Similar Messages

  • Converting 1.0 event model to 1.1

    I am working on converting a game that uses the 1.0 event-handling model to 1.1 (in preparation for eventual conversion to Swing).
    I have reached the point of saturation where I'm probably missing the obvious things that will fix my problem, so I'm hoping someone here can get me on a better track.
    I'm working with a the class gsIndustry (you can see it at http://stardart.funkychickendesign.com/gsIndustry.java) which is a subclass of my GameState class, which in turn I have recently made a subclass of Panel. GameState.root is the applet.
    The functions down, drag, raise, etc. are all being overridden from GameState because they were involved in the 1.0 event-handling. Most everything seems to be working at the moment except processing ActionEvents from any of the buttons (you can ignore GraphicalButton, it's kind of a seperate issue).
    If anyone has guidance, it would be much appreciated.

    Here's an example of an anonymous class being used as an button ActionListener that conforms to the latest event model.
    myButton.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent e) {
              // do whatever
    });

  • Delegation Event Model

    Hey ,
    I am trying to understand the java event handling with swing . I have got good responses from urhand ( thanks for all your responses :) ) but I have a different approach to it. I am primarily a actionscript developer so I`ll try and explain to the best of my abilities what I am trying to achieve with swing here.
    Let us take a very simple example a LoginManager class which basically has 2 JLabes and 2 Textfields and one button.
    So I would like to make my LoginManager class to dispatch an event which would send the username and password and my MainApp class have the call back function to it.
    Here is what the actionscript code would look like
    import mx.events.EventDispatcher;
    class Login extends MovieClip{
    private var okButton:Button
    private var userName:TextField;
    private var dispatchEvent:Function;
    public var addEventListener:Function;
    public function Login (){
    init();
    private function init(){
    EventDispatcher.initialize(this);
    _okButton.onPress=sendEvent();
    private function sendEvent(){
    dispatchEvent({type:"onClick",target:this,username:userName.text});
    class MyApp{
    public function createGUI(){
    var log:Login=new Login();
    log.addEventListener("onClick",onLoginClick);
    private function onLoginClick(eventObj:Object){
    print(eventObj.username);
    So basically the MainApp listens for a onClick event from Login and records the username. I am trying to achieve the same with java swing making . I was searching through the forums and I came accross this solution but I dont know how to or where to dispatch the events and how to set up the call back functions for my mainApp class
    This is the way I want to create my App so I can dispatch events from one class to another sending whatever data I want to.
    public interface InventorySelectionListener {
      public void inventoryChanged(InventorySelectionEvent ev);
    public class InventoryPanel extends JPanel {
      public void addInventorySelectionListener(InventorySelectionListener listener) {
      public void removeInventorySelectionListener(InventorySelectionListener listener) {
    public class Shop extends JFrame implements InventorySelectionListener {
        inventoryPanel.addInventoryListener(this);
      public void inventoryChanged(InventorySelectionEvent ev) {
    }I hope I am making sense as to what I am trying to achieve / learn here.
    Thanks :)
    cheesrs :)
    firdosh
    [urhand .. thanks for your previous solutions  :) ]

    You will need to learn MVC sooner or later... so why not sooner? This is a simple example, a real app would use JPasswordField.
    So how does it work? Rather than listening for a change in the logon dialog, the logon dialog creates a container and puts some data in it. Then, the main class examines the contents, and finds the username & password.
    This way, if the logon dialog completely changes but still uses the same container, then the main frame never needs to change. It's called a model-view separation.
    public class LogonModel {
      public String userName;
      public String password;
      public boolean chooseOk = false;
    public class MainApp exnteds JFrame {
      // Creates the main app.. etc.
      // Now it wants to show a login prompt.. so it calls this method:
      public void showLoginPrompt() {
        LogonModel model = new LogonModel();
        LogonDialog dialog = new LogonDialog(model);
        // makes all the labels and text field goto the right position
        dialog.pack()
        // puts it in the middle of the screen
        dialog.setLocationRelativeTo(null);
        // shows it... the flow stops here and does
        // not return until they close the dialog.
        dialog.show();
        if(model.chooseOk) {
            System.out.println("The user typed the name: " + model.userName);
            System.out.println("The user typed the pass: " + model.password);
         } else {
            System.out.println("The user canceled logon!");
    public class LogonDialog extneds JDialog {
      LogonModel logonModel;
      public LogonDialog(LogonModel model) {
        this.logonModel = model;
      // somewhere in your dialog you will create the buttons...
      // create your OK button like this:
      JButton okButton = new JButton("OK");
      okButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
          // fills the model with data
          model.chooseOk = true;
          model.userName = userNameTextField.getText();
          model.password = passwordTestField.getText();
          close(); // closes the logon dialog.
    }

  • AS3 event model broken?

    Recently I posted a
    question
    on this forum regarding the mouseclick event. After some
    experimenting I finally figured out that the AS3 event model might
    be broken.
    I include two classes to illustrate my point.
    The first has a sprite inside a sprite. The inside sprite has
    a box drawn in it. As expected when clicking the box you get two
    click events, one for the inside sprite and one for the outside
    one.
    The second has exactly the same structure, yet you only get
    one click event(for the outside sprite). What changed in the second
    is that I rearranged the structure of the display list so that my
    class ClickTest2 becomes the inner sprite.
    How can we explain this behaviour? My only suspicion is that
    somehow the basic class of the application although being a sprite
    is treated in a special manner.

    "Roland G" <[email protected]> wrote in
    message
    news:gg7alf$sgj$[email protected]..
    > Recently I posted a
    >
    http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?forumid=60&catid=58
    > 5&threadid=1407048&enterthread=y on this forum
    regarding the mouseclick
    > event.
    > After some experimenting I finally figured out that the
    AS3 event model
    > might
    > be broken.
    > I include two classes to illustrate my point.
    > The first has a sprite inside a sprite. The inside
    sprite has a box drawn
    > in
    > it. As expected when clicking the box you get two click
    events, one for
    > the
    > inside sprite and one for the outside one.
    > The second has exactly the same structure, yet you only
    get one click
    > event(for the outside sprite). What changed in the
    second is that I
    > rearranged
    > the structure of the display list so that my class
    ClickTest2 becomes the
    > inner
    > sprite.
    >
    > How can we explain this behaviour? My only suspicion is
    that somehow the
    > basic
    > class of the application although being a sprite is
    treated in a special
    > manner.
    I'm really amazed that having an object remove itself from
    the stage and
    reparent itself works at all. It's not surprising that screws
    stuff up.

  • Event dispatching to swing components

    Hi,
    I'm implementing an extension of JTextPane, and I would like to make it as much reusable as possible.
    In order to do this, the class don't have to know about the external world (components)..
    The class should notify events (e.g. an event could be that a specific string has been typed..) to the other components just sending a message (or event), and all the components registered to that specific event implement their behavior to react to it.. quite simple..
    which is the simplest solution in Java to do this?
    thanks in advance..

    You should implement event dispatching based on the listener model, for consistency. Since you are extending JTextPane, a lot of the event dispatching code is written for you. Look up JTextPane in the javadocs and check out all the classes it is derived from. To take advantage of the already written listener code, simply call the appropriate fireWhateverEvent method whenever something happens. That will cause the event to be dispatched to all listeners registered with that component. If you want to define some new events that aren't covered by any of the listener methods in any of the classes your new class is derived from, here's the general way to do it:
    1) Define a new listener interface that implements the EventListener interface (which contains no methods).
    2) In your new listener interface, include methods for specific events, such as keyPressed, actionPerformed, textTyped, etc...
    3) Each of these methods should take a single parameter describing the event. This parameter should be a class that extends EventObject and that contains data relevant to your event. For example, you may define a TextEvent class that extends EventObject. The only methods EventObject has is getSource() and toString(). You won't really need to override these as long as you call the EventObject(Object) constructor from your TextEvent constructors.
    4) In your JTextPane derived class, define methods that can add, remove, and get a list of all registered event listeners for your event (ex: void addTextListener(TextListener t), void removeTextListener(TextListener t), TextListener[] getTextListeners()).
    5) add*Listener should add the listener to an internal list of listeners (a LinkedList or a Vector are good ways to store the registered listener lists). remove*Listener should remove the listener from the list, and get*Listeners should return the list in array form.
    6) For ease-of-use, define a fire method like fireTextListener(params), which creates a new TextEvent (assuming you're doing the TextListener thing) holding the specified event data and iterates through the internal list of listeners, calling the appropriate method in each one and passing your TextEvent to it.
    7) Call your fire*Event functions wherever appropriate to fire events.
    It's simpler than it sounds. Here's a small example:
    // TextListener.java
    public class TextListener implements EventListener {
        public void textInserted (TextEvent e);
        public void textDeleted  (TextEvent e);
    // TextEvent.java
    public class TextEvent extends EventObject {
        protected int    pos0;
        protected int    pos1;
        protected String text;
        public TextEvent (Object source, int pos0, int pos1, String text) {
            super(source);
            this.pos0 = pos0;
            this.pos1 = pos1;
            this.text = (text != null) ? text : "";
        public TextEvent (Object source, int pos0, int pos1) {
            this(source, pos0, pos1, null);
        public int getPos0 () {
            return pos0;
        public int getPos1 () {
            return pos1;
        public String getText () {
            return text;
    // MyTextPane.java
    public class MyTextPane extends JTextPane {
        LinkedList textListeners = new LinkedList();
        // This is just some method you defined, can be anything.
        public void someMethodThatInsertsText () {
            fireTextInserted(pos0, pos1, textInserted);
        // Same with this, this can be anything.
        public void someOtherMethodThatDeletesText () {
            fireTextDeleted(pos0, pos1);
        public void addTextListener (TextListener t) {
            textListeners.add(t);
        public void removeTextListener (TextListener t) {
            textListeners.remove(t);
        public TextListener[] getTextListeners () {
            TextListener ts = new TextListener[textListeners.size()];
            Iterator     i;
            int          j;
            // Don't think toArray works good because I'm 99% sure you'll
            // have trouble casting an Object[] to a TextListener[].
            for (j = 0, i = textListeners.iterator(); i.hasNext(); j ++)
                ts[j] = (TextListener)i.next();
        protected fireTextInserted (int pos0, int pos1, String text) {
            TextEvent e = new TextEvent(this, pos0, pos1, text);
            Iterator  i = textListeners.iterator();
            while (i.hasNext())
                ((TextListener)i.next()).textInserted(e);
        protected void fireTextDeleted (int pos0, int pos1) {
            TextEvent e = new TextEvent(this, pos0, pos1);
            Iterator  i = textListeners.iterator();
            while (i.hasNext())
                ((TextListener)i.next()).textDeleted(e);
    };There. I just typed that there, didn't test or compile it, but you get the gist of it. Then, like you do with any listener stuff, when you want to set up a listener and register it with a MyTextPane instance, just create some class that extends TextListener and overrides textInserted and textDeleted to do whatever your application needs to do.
    Hope that makes sense.
    Jason

  • Explicit Event Enabling for Swing Components

    Hi all swing-experts,
    I want to enable some events for an JInternalFrame explicitely,
    but I can't find the corresponding EVENT_MASK anywhere...
    Who knows??
    Anja

    Hello again,
    (besonderes HALLO an Stephen fuer die Muehe!!!)
    there exist two ways of handling an event, at least for awt events:
    1) writing an action listener and adding it to the component who will handle the event
    2) letting the component handle the event itself by "explicit event enabling"
    I am talking about no 2.
    This works so:
    a) Subclass component
    b) in the constructor of the subclass, call
    enableEvents(AWTEvent.XXX_EVENT_MASK)
    c) provide the subclass with a processXXXEvent() method (that should call the superclass' version of this method)
    An other version of my question: is this also possible with Swing?
    Where do I find the appropriate XXX_EVENT_MASK and processXXXEvent method?
    Seems to be an unusual problem...
    Anja
    PS: sieht so aus...

  • Determine event handler for swing components from the API browser

    Is there a way to determine what event handlers are assocaited with the different swing classes. For example JTextField is associated to ActionListener, and JCheckbox uses the event handle ItemListener. Is there a way to determine this by looking at the class via the Java API?

    Yes, there is. You'll observe that JTextField has an "addActionListener(ActionListener)" method, for a start. And JTextField is a subclass of JTextComponent, which has "addCaretListener(CaretListener)" and "addInputMethodListener(InputMethodListener)" methods. And JTextComponent is a subclass of JComponent, which has an "addAncestorListener(AncestorListener)" method. And so on... there are more. All of this can be found in the API documentation by looking for methods whose names start with "add".

  • Help Understanding Event Model

    I am having trouble getting items initialized ontime. I have
    read the flex 3 development guide and some other docunentation a
    couple of times and i have read other posts on this forum
    concerning the creationComplete event. I still don't have a clear
    picture of how this works.
    The development guide says the following:
    initialize - Dispatched when a component and all its children
    have been created, but before the component size has
    been determined.
    creationComplete - Dispatched when the component has been
    laid out and the component is visible (if appropriate).
    From this, I am assuming that using a creationComplete event
    for a parent object should have access to any component ids on
    child objects.
    However, this is not happening in my code.
    I have the following scenario:
    Container1
    ->Container2 (child of Container1)
    -->Datagrid (child of Container2)
    In container 1, I attempt to register an event listener with
    the itemClick event of the datagrid using the creationComplete
    event. This fails. However, if I move this registration to a click
    event on Container 1, it is successful. So the problem appears to
    be related to instantiation of the datagrid. So why would the
    dataGrid not be instantiated by the time the Container1
    creationComplete event fires?

    "rss181919" <[email protected]> wrote in
    message
    news:gfeqai$gr6$[email protected]..
    >I am having trouble getting items initialized ontime. I
    have read the flex
    >3
    > development guide and some other docunentation a couple
    of times and i
    > have
    > read other posts on this forum concerning the
    creationComplete event. I
    > still
    > don't have a clear picture of how this works.
    >
    > The development guide says the following:
    > initialize - Dispatched when a component and all its
    children have been
    > created, but before the component size has
    > been determined.
    > creationComplete - Dispatched when the component has
    been laid out and the
    > component is visible (if appropriate).
    A lot of this depends. For instance, if Container1 is a
    ViewStack or if
    Container2 is added via addChild, Container2 might or might
    exist at
    creationComplete of Container1. All bets are off on creation
    of children of
    Container2 at creationComplete of Container1 :-).
    > From this, I am assuming that using a creationComplete
    event for a parent
    > object should have access to any component ids on child
    objects.
    >
    > However, this is not happening in my code.
    > I have the following scenario:
    > Container1
    > ->Container2 (child of Container1)
    > -->Datagrid (child of Container2)
    >
    > In container 1, I attempt to register an event listener
    with the itemClick
    > event of the datagrid using the creationComplete event.
    This fails.
    > However,
    > if I move this registration to a click event on
    Container 1, it is
    > successful.
    > So the problem appears to be related to instantiation of
    the datagrid. So
    > why
    > would the dataGrid not be instantiated by the time the
    Container1
    > creationComplete event fires?
    Try dispatching a custom bubbling event from the
    creationComplete event of
    the datagrid that you listen for from Container1. Or, just
    have Container2
    do the handling and generate a custom event based on the
    itemClick. That's
    probably the "Flexier" way to handle it.
    HTH;
    Amy

  • Java event model and dialog

    I have a question about Java event handlers. My understanding is that all event handlers are executed by the same event thread, one at a time. How does one then explain the situation where the action for a button press is opening up a dialog pane which has a button of its own (along with an action handler defined for the button) and then wating for the dialog pane to close? It seems like the event thread will have to pause while executing the event handler of the main button, then execute the event handler of the button inside the dialog pane, then resume executing the event handler of the main button. How is that possible?
    JZ

    Interesting..says another event pump will run while the one invoking the dialog is blocked. Two thoughts. First, what "blocks" the first one? Is it that the JDialog code, in the .show() call uses the EventQueue.push() to put its own version of an eventque in place and while that is there, the other one is blocked automatically? Or does it somehow have to put in a loop on the first one while it puts in its own event que, to block the first one? I am a little unsure of how the first one gets blocked.
    Another thought, when a dialog (modal) shows up and puts its own event que in place, if a button in that dialog spawns another modal dialog, does that second modal dialog do the same thing? I would guess it does, seems fitting. Just curious and haven't got the java source handy at the moment.

  • Event Model

    I have multiple web apps and I want these web apps to look
    like one application. So I have a navigation bar A and it shall be
    same for all pages (B1, B2, B3, etc). Except that A will also
    indicate which category of page the users are on.
    B1, B2, B3 may be in different web apps. so that could not
    sure server side code of A. I am planning using Spry HtmlPanel to
    include A. so B1, B2 and B3 will all have an javascript Spry
    HtmlPanel which will call A.
    Now the question is how do I communicate that I am loading
    page B1 (instead of B2 and B3) to A? It looks like I need to have
    an event system to do that. If yes, could you please let me know
    how?
    Thank you so much for reading and replying.
    Melvin
    www.play4kid.com

    "Melvin Ma" <[email protected]> wrote in
    message
    news:g6ajs0$23r$[email protected]..
    > It looks like Spry does not have a good mechanism to
    handle events - one
    > could
    > only listen to an element, one could not create one's
    own event. Yahoo YUI
    > allows one to create custom events but it is still not
    what I wanted -- it
    > seems one need to have the reference to the event
    producer before being
    > able to
    > listen to it -- that is not really what I wanted.
    >
    > I am trying to use an element in DOM to communicate
    results between two
    > parts
    > of my pages. Please let me know if you have better
    suggestions.
    This could be overkilling and too complex for what you are
    trying to do. It
    also assumes familiarity with design patterns and solid
    JavaScript
    programming skills:
    http://www.massimocorner.com/libraries/notifier/
    Massimo Foti, web-programmer for hire
    Tools for ColdFusion, JavaScript and Dreamweaver:
    http://www.massimocorner.com

  • Confusing Event Order in Swing Thread

    hi,
    i've panel which contains a text field for entering number and a submit button
    sometimes new (updated) value can not be sent when i click the button (the previous value of the field is sent)
    in the debug mode, i see that sometimes AbstractButton.fireActionPerformed() is called (which gets the value of the field at that time and then submits) by event dispatch thread before JFormattedTextFiled.FocusLostHandler and JFormattedTextField.commitEdit() (which updates the value of the field) .
    i think jbutton event should have never been called before the text field loses the focus and updates its value
    any idea about the problem?
    i'm using xp-sp2 and java 1.6.0_06-b02

    @macrules2
    thanks, i'll take notice of your advice and please notice that it was my first post both at this forum and stackoverflow (which means i may have lack of some forum principles, sorry)
    @kevinaworkman
    if you really want to help someone, try to be less arrogant
    @BinaryDigit
    thanks for your reply. since it's part of an military project, i'm not allowed to give code samples (and all modifications are in the EDT).
    actually i'm interested in the cause of the problem rather than the solution
    there are two cases in the EventQueuehere are the events for case 1:
    MouseEvent (MOUSE_RELEASED)
    MouseEvent (MOUSE_CLICKED)
    InvocationEvent
    InvocationEvent
    InvocationEvent
    CausedFocusEvent (FOCUS_LOST; opposite: JButton; source: FormattedNumberField)
    CausedFocusEvent (FOCUS_GAINED; opposite: FormattedNumberField; source: JButton)
    InvocationEvent
    MouseEvent (MOUSE_MOVED)
    MouseEvent (MOUSE_EXITED)and here are the events for case 2:
    CausedFocusEvent (FOCUS_LOST; opposite: JButton; source: FormattedNumberField)
    CausedFocusEvent (FOCUS_GAINED; opposite: FormattedNumberField; source: JButton)
    InvocationEvent
    InvocationEvent
    MouseEvent (MOUSE_RELEASED)
    MouseEvent (MOUSE_CLICKED)
    InvocationEvent
    InvocationEvent
    MouseEvent (MOUSE_MOVED)
    MouseEvent (MOUSE_EXITED)maybe java does not guarantee the order of the events. if it's true it would be a common problem but it's an unusual and very rare situation. even i can't reproduce this problem in other gui panels. i wonder what may cause this problem.

  • Event Handling in Swing

    Hi,
    I've a JTextField below which I have a single column table which contains some data. As I enter some character in the text field, the names in the table should sort automatically in that order. It's something like typing mail.yahoo.com. As soon as I type 'm' the address bar will display all the links starting with m and when I type 'ma' it shows links starting with ma and son on. Pls advise.

    Hi,
    maybe this can help you: http://www.javaworld.com/javaworld/jw-02-2001/jw-0216-jfile_p.html
    Regards,
    Michael

  • Event model for multiple components

    Hi
    For some time now I have been searching on the net for a proper way to do following:
    I have a class that extends a JFrame. In it I instantiate and add two more classes ControlPanel and CanavasPanel which extend from JPanel...
    All these are in SEPARATE files...My ControlPanel class has buttons that when clicked are supposed to draw different objects on the CanavasPanel...
    How do I fire a method in my CanavasPanel class when a button is clicked in ControlPanel class??? These are all in separate files and I am looking for a solution that does not uses inner and anonymous classes..If I implement ActionListener in ControlPanel class I know a way of referencing CanavasPanel class so I can fire its methods...
    Is it doable? And if so can someone explain to me what needs to be done.

    Try out this way:
    The below code is not complete code (where ever is ... it is fill in blanks):
    public class MyFrame extends JFrame{
    protected ControlPanel buttonPanel;
    protected CanvasPanel canvasPanel;
    public MyFrame(){  
    // Initialize panels
    canvasPanel = new CanvasPanel(...);
    buttonPanel = new ButtonPanel(...);
    // Set layout
    this.getContentPane().setLayout(new BorderLayout())
    /*----------- CHECK THIS --------*/
    // Assuming Control Panel has some method used to add listener
    // to draw button
    // ex: setDrawButtonActionListener(ActionListener al){}
    buttonPanel.setDrawButtonActionListener(new MyDrawActionListener());
    // Now add panels
    this.getContentPane().add(buttonPanel,BorderLayout.SOUTH);
    this.getContentPane().add(canvasPanel,BorderLayout.CENTER);\
    } // Constructor MyFrame
    class MyDrawActionListener implements ActionListener{
    public void actionPerformed(ActionEvent ae){
    // Make sure that the canvas panel is initialized
    if (canvasPanel != null){
    canvasPanel.drawSomething();
    }else{
    // Your error message display here
    } // Class MyDrawActionListener
    } // Class MyFrame
    Hope this helps.

  • TIC TAC TOE Programming Issue

    Somehow I only have the X's in the i=j or i+j=2 boxes and O's in all the other. Anybody know what's the problem and I can't get it to repeat 3 times...i tried doing the do while loop
       public void actionPerformed( ActionEvent e )
         int i=0;
         int j=0;
         int turn = 0;
         int currentGame = 1;
         boolean winner;
         boolean found = false; //Search for button in 2-D array
         char winChar = ' '; //Hold winner's symbol
         showStatus("");
         for(i=0; i<ROW; ++i)
            for(j=0; j<COL && !found; ++j)
               //Sets X to all the odd turns
               if(turn%2==1 && e.getSource()==ttt[i][j])
                                          //Which button was pressed?
                  ttt[i][j].setBackground(Color.red); //Red X
                  ttt[i][j].setFont(tttFont); //Set to 48 pt bold font
                  ttt[i][j].setText("X"); //Assign 'X' to odd play
                  ttt[i][j].setEnabled(false); //Disable button
                  winChar = 'X'; //Assign symbol
                  found = true;
               //Sets O to all the even turns
               if(turn%2==0 && e.getSource()==ttt[i][j])
                  ttt[i][j].setBackground(Color.blue); //Blue O
                  ttt[i][j].setFont(tttFont); //Set to 48 pt bold font
                  ttt[i][j].setText("O"); //Assign 'O' to even play
                  ttt[i][j].setEnabled(false); //Disable button
                  winChar = 'O'; //Assign symbol
                  found = true;
            ++turn;
         if( winner = isAWin(winChar) ) //Game has a winner
            for(i=0; i<ROW; ++i) //Resets game
               for(j=0; j<COL; ++j)
                  ttt[i][j].setBackground(Color.white);
                  ttt[i][j].setText(""); //Clear buttons
                  ttt[i][j].setEnabled(true); //Enable buttons
            if(currentGame<3)
               showStatus("WINNER of GAME #" + currentGame + ":" + winChar);
               games[currentGame] = winChar; //Store winner in 1-D array
            else
               showStatus("WINNERS: #1:" + games[1] + "#2:" + games[2] + "#3:" +
                          winChar);
            ++currentGame;
       }

    Well, it looks like you've fairly comprehensively misunderstood the events model of swing.
    An actionPerformed is called for each mouse click so you certainly shouldn't be intialising stuff like turn numbers etc in one.
    Rather than using one actionPerformed, presumably defined as part of the JFrame, create a new ActionListener object for each button which knows that block's coordinates so you don't have to muck about searching for the block which you clicked on. Create an inner class which implements ActionListener and create a separate instance for each block (I assume they are JButtons).
    And it's likely to look better if you use ImageIcons for your symbols, not character strings.

  • Non-gui/swing event in java possible ?

    Dear Members :
    Is it possible in java to raise and catch business events, as is possible in other languages, I know.
    For instance - when I create a vehicle instance, that will trigger an event which will add that vehicle to vehicle_list(List) - something like that ? I am aware of Observer/Observable, but that is only if the source changes.
    Could someone please explain with syntax if that's possible, I mean, tackling any kind of business events in java ?
    Thanks in advance
    Atanu

    There is no out of the box event model... and be careful how you phrase these things... and in you are pedantic enough the pattern reveals itself.
    What notifies the sales people that a new car is ready? It's not the Car itself is it? How about the factory? You're getting warmer... Who else does the factory tell? Maybe the tax man?
    Yeah... Observe/r/able was a good first thought.
    And... You might want to look into the Spring framework... I think you're groping for AOP.
    Cheers. Keith.

Maybe you are looking for

  • PDF and Print Control in Reports.

    Dear All, I want to set particular format for every report in PDF and Print control option like want to place client's logo in header and page number and date in fotter , how can i achive this,is there any way we can set it globally coz doing on ever

  • Suggest program to make gif animations

    Since Adobe's ImageReady is no longer in Creative Suite, I'm wondering which program to choose to make small, short gif animations? If possible - please include address where to download tutorial. Thanks.

  • Open Box Item Delivered, but damaged

    Hello, I was out of town when I had an open box range delivered to my house.  When I went to the store to look at the item, it was in perfect condition, both the sales person and I could not find any issues with it, and I bought it.  When on my trip,

  • Webdynpro Application in Portal?

    Hi Experts.. I am using my webdynpro application in portal. The probelm is When i am trying to execute my WD application in portal it takes more time to execute. May i knw the reason. Help me to find out the solution for this.. GS

  • Tree Cell Renderer Highlight

    I have implemented a cutom renderer for my JTree that displays different icons for different types of data. However I cannot get the highlight color to work at all. Before using my custom renderer, the nodes would highlight when selected or being dra