Results 1 to 9 of 9
  1. #1
    Join Date
    Jul 2010
    Posts
    12
    Rep Power
    0

    Default For some reason, my GUI is not recognizing multiple action listeners for buttons.

    I need an answer ASAP, this program is due tomorrow night.

    I'm making a Blackjack GUI. The text-version of the game works fine, so the GUI is the only .java file that I'm having a problem with.

    When one button is programmed to have an action listener (the deal button), it works fine. However, when I try to program the hit button, it doesn't recognize the HitListener class.

    For some reason, a new error just game up, also: cannot find symbol -- method getCardFileName(blackfiles.Card)

    It doesn't recognize the getCardFileName method in the HitListener class, but it's recognized in the DealListener class.

    Please HELP! THANK YOU! I need help by tonight. I can turn in the text version for a grade (I'm doing the GUI for extra credit), but I would like to finish the GUI by tonight.

    Java Code:
    package blackfiles;  
    
    
    
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.JOptionPane;
    import javax.swing.JDialog;
    import javax.swing.JButton;
    import javax.swing.JRadioButton;
    import javax.swing.ButtonGroup;
    import javax.swing.JLabel;
    import javax.swing.ImageIcon;
    import javax.swing.BoxLayout;
    import javax.swing.Box;
    import javax.swing.BorderFactory;
    import javax.swing.border.Border;
    import javax.swing.JTabbedPane;
    import javax.swing.JPanel;
    import javax.swing.JFrame;
    import java.beans.*; //Property change stuff
    /**
     * Write a description of class GUI here.
     * 
     * @author Grace L. Christenbery
     * @version 8/7/2010
     */
    
    
    public class Game21 extends JFrame
    {
        int playerHandsWon = 0;
        int dealerHandsWon = 0;
        int playerTotal = 0;
        int dealerTotal = 0;
        boolean dealPressed = false;
        
    
       //Creates the labels that hold the card images. Theoretically, it's possible to get up to 13
       //cards dealt before going over 21 if by chance the player draws a card with value 2 over and over.
       private JLabel card1Label;
       private JLabel card2Label;
       private JLabel card3Label;
       private JLabel card4Label;
       private JLabel card5Label;
       private JLabel card6Label;
       private JLabel card7Label;
       private JLabel card8Label;
       private JLabel card9Label;
       private JLabel card10Label;
       private JLabel card11Label;
       private JLabel card12Label;
       private JLabel card13Label;
       //Label to keeps track of the scores.
       private JLabel scoreLabel;
       //Buttons for deal, hit, and stand choices.
       private JButton deal;
       private JButton hit;
       private JButton stand;
       //Panels to hold the cards, buttons, and scores.
       private JPanel cardPanel;
       private JPanel buttonPanel;
       private JPanel scorePanel;
       //Progress Bar
       private javax.swing.JProgressBar jProgressBar1;
       
       /**Constructor*/
       public Game21()
       {
           //Call the JFrame constructor.
           super("Blackjack");
           //Specify an action for the close button.
           setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
           //Create a BorderLayout manager for the content pane.
           setLayout(new BorderLayout());
           //Build the panels.
           buildCardPanel();
           buildButtonPanel();
           buildScorePanel();
           //Add the panels to the content pane.
           add(cardPanel, BorderLayout.CENTER);
           add(scorePanel, BorderLayout.NORTH);
           add(buttonPanel, BorderLayout.SOUTH);
           //Pack and display the window.
           pack();
           setVisible(true);
        }
        /**The buildCardPanel method adds a label to a panel.*/
        private void buildCardPanel()
        {
            //Create a panel.
            cardPanel = new JPanel();
            //Create a label.
            card1Label = new JLabel(" This is where the cards will be dealt.");
            card2Label = new JLabel(" ");
            card3Label = new JLabel(" ");
            card4Label = new JLabel(" ");
            card5Label = new JLabel(" ");
            card6Label = new JLabel(" ");
            card7Label = new JLabel(" ");
            card8Label = new JLabel(" ");
            card9Label = new JLabel(" ");
            card10Label = new JLabel(" ");
            card11Label = new JLabel(" ");
            card12Label = new JLabel(" ");
            card13Label = new JLabel(" ");
            //Add the label to the panel.
            cardPanel.add(card1Label);
            cardPanel.add(card2Label);
            cardPanel.add(card3Label);
            cardPanel.add(card4Label);
            cardPanel.add(card5Label);
            cardPanel.add(card6Label);
            cardPanel.add(card7Label);
            cardPanel.add(card8Label);
            cardPanel.add(card9Label);
            cardPanel.add(card10Label);
            cardPanel.add(card11Label);
            cardPanel.add(card12Label);
            cardPanel.add(card13Label);
        }
        
        
        private void buildButtonPanel()
        {
            //Create a panel.
            buttonPanel = new JPanel();
            //Get an optional image for the button(s).
            //ImageIcon buttonImage = new ImageIcon("filename.gif");
            //Create the buttons.
            deal = new JButton("Deal!");
            hit = new JButton("Hit!");
            stand = new JButton("Stand");
            //deal.setIcon(buttonImage);
            //Register action listeners with the buttons.
            deal.addActionListener(new DealListener());
            hit.addActionListener(new HitListener());
            //hit.addActionListener(new HitListener());
            //stand.addActionListener(new ButtonListener());
            //Add the buttons to the panel.
            buttonPanel.add(deal);
            buttonPanel.add(hit);
            buttonPanel.add(stand);
            JLabel bustMeter;
            bustMeter = new JLabel(" Bust Meter: ");
            buttonPanel.add(bustMeter);
            jProgressBar1 = new javax.swing.JProgressBar();
            buttonPanel.add(jProgressBar1);
            jProgressBar1.setMinimum(0);
            jProgressBar1.setMaximum(21);
            jProgressBar1.setStringPainted(true);
        }
        
        private void buildScorePanel()
        {
            //Create a panel.
            scorePanel = new JPanel();
            scoreLabel = new JLabel("Player Score: " + playerHandsWon + "  Dealer Score: " + dealerHandsWon + " | Hand Value: 0");
            //Adds the score label to the panel.
            scorePanel.add(scoreLabel);
                    //Adds the progress bar.
        }
    
        /** Private inner class that handles the event when the user clicks the deal button. */
        private class DealListener implements ActionListener
        {
            public void actionPerformed(ActionEvent e)
            {
                while(dealPressed == false)
                {
                //Tells the program that the button has been pressed.
                dealPressed = true;
                //Procure the filename based on the card randomly drawn from the deck.
                //Creates the player's deck and the dealer's deck.
                Deck playerDeck = new Deck();
                Deck dealerDeck = new Deck();
                playerDeck = playerDeck.shuffle(playerDeck);
                dealerDeck = dealerDeck.shuffle(dealerDeck);
    
                
                Card firstPlayerCard = playerDeck.getTopCard(playerDeck);
                String playerCard1File = getCardFileName(playerDeck.getTopCard(playerDeck));
                playerDeck = playerDeck.shuffle(playerDeck);
                Card secondPlayerCard = playerDeck.getTopCard(playerDeck);
                String playerCard2File = getCardFileName(playerDeck.getTopCard(playerDeck));
                playerDeck = playerDeck.shuffle(playerDeck);
                
                //Handles the Ace scenario.
                if(firstPlayerCard.face.equals("Ace"))
                {
                    if(secondPlayerCard.value + 11 <= 21)
                    {
                        firstPlayerCard.setValue(11);
                    }
                    else
                    {
                        firstPlayerCard.setValue(1);
                    }
                }
                if(secondPlayerCard.face.equals("Ace"))
                {
                    if(firstPlayerCard.value + 11 <= 21)
                    {
                        secondPlayerCard.setValue(11);
                    }
                    else
                    {
                        secondPlayerCard.setValue(1);
                    }
                }
                
                //Read the image file into an ImageIcon object.
                ImageIcon card = new ImageIcon(playerCard1File);
                ImageIcon card2 = new ImageIcon(playerCard2File);
                //Display the image in the label.
                card1Label.setIcon(card);
                card2Label.setIcon(card2);
                //Computes the dealer's cards.
                Card firstDealerCard = playerDeck.getTopCard(playerDeck);
                playerDeck = playerDeck.shuffle(playerDeck);
            Card secondDealerCard = playerDeck.getTopCard(playerDeck);
            playerDeck = playerDeck.shuffle(playerDeck);
                if(firstDealerCard.face.equals("Ace"))
                {
                    if(secondDealerCard.value + 11 <= 21)
                    {
                        firstDealerCard.setValue(11);
                    }
                    else
                    {
                        firstDealerCard.setValue(1);
                    }
                }
                if(secondDealerCard.face.equals("Ace"))
                {
                    if(firstDealerCard.value + 11 <= 21)
                    {
                        secondDealerCard.setValue(11);
                    }
                    else
                    {
                        secondDealerCard.setValue(1);
                    }
                }
                dealerTotal = firstDealerCard.value + secondDealerCard.value;
                playerTotal = firstPlayerCard.value + secondPlayerCard.value;
                //Shows the user what he or she drew.
                scoreLabel.setText("Player Score: " + playerHandsWon + " | Dealer Score: " + dealerHandsWon + " | Hand Value: " + playerTotal + " | Dealer's Hand: " + dealerTotal);
    
                //Remove the text from the label.
                if(playerCard1File.equals("FileNotFound.gif"))
                {
                
                card1Label.setText(playerCard1File + playerDeck.getCard(0).toString());
                card2Label.setText(playerCard2File);
                pack();
            }else if (playerCard2File.equals("FileNotFound.gif"))
            {
                card1Label.setText(playerCard1File);
                card2Label.setText(playerDeck.getCard(0).toString());
                pack();
            }
            else
            {
                card1Label.setText(null);
                card2Label.setText(null);
                //card1Label.setText(playerCardFile);
                //card2Label.setText(dealerCardFile);
                //Pack the frame again to accomodate the new size of the label.
                pack();
            }
            //Set the value of the progress bar.
            jProgressBar1.setValue(playerTotal);
            pack();
        }
    }
    
    
        
    public String getCardFileName(Card card)
    {
        String file = " ";
        //If-statements for the "Card" of Clubs.
        if (card.toString().equals("Two of Clubs"))
        {
            file = "2Club.gif";
        }
        else if (card.toString().equals("Three of Clubs"))
        {
            file = "3Club.gif";
        }
        else if (card.toString().equals("Four of Clubs"))
        {
            file = "4Club.gif";
        }
        else if (card.toString().equals("Five of Clubs"))
        {
            file = "5Club.gif";
        }
        else if (card.toString().equals("Six of Clubs"))
        {
            file = "6Club.gif";
        }
        else if (card.toString().equals("Seven of Clubs"))
        {
            file = "7Club.gif";
        }
        else if (card.toString().equals("Eight of Clubs"))
        {
            file = "8Club.gif";
        }
        else if (card.toString().equals("Nine of Clubs"))
        {
            file = "9Club.gif";
        }
        else if (card.toString().equals("Ten of Clubs"))
        {
            file = "10Club.gif";
        }
        else if (card.toString().equals("Ace of Clubs"))
        {
            file = "AceClub.gif";
        }
        else if (card.toString().equals("Queen of Clubs"))
        {
            file = "QueenClub.gif";
        }
        else if (card.toString().equals("King of Clubs"))
        {
            file = "KingClub.gif";
        }
         else if (card.toString().equals("Jack of Clubs"))
         {
            file = "JackClub.gif";
        }
        else if (card.toString().equals("Two of Spades"))
        {
            file = "2Spade.gif";
        }
        else if (card.toString().equals("Three of Spades"))
        {
            file = "3Spade.gif";
        }
        else if (card.toString().equals("Four of Spades"))
        {
            file = "4Spade.gif";
        }
        else if (card.toString().equals("Five of Spades"))
        {
            file = "5Spade.gif";
        }
        else if (card.toString().equals("Six of Spades"))
        {
            file = "6Spade.gif";
        }
        else if (card.toString().equals("Seven of Spades"))
        {
            file = "7Spade.gif";
        }
        else if (card.toString().equals("Eight of Spades"))
        {
            file = "8Spade.gif";
        }
        else if (card.toString().equals("Nine of Spades"))
        {
            file = "9Spade.gif";
        }
        else if (card.toString().equals("Ten of Spades"))
        {
            file = "10Spade.gif";
        }
        else if (card.toString().equals("Ace of Spades"))
        {
            file = "AceSpade.gif";
        }
        else if (card.toString().equals("Queen of Spades"))
        {
            file = "QueenSpade.gif";
        }
        else if (card.toString().equals("King of Spades"))
        {
            file = "KingSpade.gif";
        }
         else if (card.toString().equals("Jack of Spades"))
         {
            file = "JackSpade.gif";
        }
            else if (card.toString().equals("Two of Hearts"))
        {
            file = "2Heart.gif";
        }
        else if (card.toString().equals("Three of Hearts"))
        {
            file = "3Heart.gif";
        }
        else if (card.toString().equals("Four of Hearts"))
        {
            file = "4Heart.gif";
        }
        else if (card.toString().equals("Five of Hearts"))
        {
            file = "5Heart.gif";
        }
        else if (card.toString().equals("Six of Hearts"))
        {
            file = "6Heart.gif";
        }
        else if (card.toString().equals("Seven of Hearts"))
        {
            file = "7Heart.gif";
        }
        else if (card.toString().equals("Eight of Hearts"))
        {
            file = "8Heart.gif";
        }
        else if (card.toString().equals("Nine of Hearts"))
        {
            file = "9Heart.gif";
        }
        else if (card.toString().equals("Ten of Hearts"))
        {
            file = "10Heart.gif";
        }
        else if (card.toString().equals("Ace of Hearts"))
        {
            file = "AceHeart.gif";
        }
        else if (card.toString().equals("Queen of Hearts"))
        {
            file = "QueenHeart.gif";
        }
         else if (card.toString().equals("Jack of Hearts"))
         {
            file = "JackHeart.gif";
        }
        else if (card.toString().equals("King of Hearts"))
        {
            file = "KingHeart.gif";
        }
            else if (card.toString().equals("Two of Diamonds"))
        {
            file = "2Diamond.gif";
        }
        else if (card.toString().equals("Three of Diamonds"))
        {
            file = "3Diamond.gif";
        }
        else if (card.toString().equals("Four of Diamonds"))
        {
            file = "4Diamond.gif";
        }
        else if (card.toString().equals("Five of Diamonds"))
        {
            file = "5Diamond.gif";
        }
        else if (card.toString().equals("Six of Diamonds"))
        {
            file = "6Diamond.gif";
        }
        else if (card.toString().equals("Seven of Diamonds"))
        {
            file = "7Diamond.gif";
        }
        else if (card.toString().equals("Eight of Diamonds"))
        {
            file = "8Diamond.gif";
        }
        else if (card.toString().equals("Nine of Diamonds"))
        {
            file = "9Diamond.gif";
        }
        else if (card.toString().equals("Ten of Diamonds"))
        {
            file = "10Diamond.gif";
        }
        else if (card.toString().equals("Ace of Diamonds"))
        {
            file = "AceDiamond.gif";
        }
        else if (card.toString().equals("Queen of Diamonds"))
        {
            file = "QueenDiamond.gif";
        }
        else if (card.toString().equals("King of Diamonds"))
        {
            file = "KingDiamond.gif";
        }
         else if (card.toString().equals("Jack of Diamonds"))
         {
            file = "JackDiamond.gif";
        }
        else
        {
            file = "FileNotFound.gif";
        }
    
        return file;
    }}
    
        private class HitListener implements ActionListener
        {
            public void actionPerformed(ActionEvent e2)
            {
                while(dealPressed == true)
                {
                    Deck playerDeck = new Deck();
                    Deck dealerDeck = new Deck();
                    playerDeck = playerDeck.shuffle(playerDeck);
                    dealerDeck = dealerDeck.shuffle(dealerDeck);
                    //Draws a new card object and shuffles the deck.
                    Card nextPlayerCard = playerDeck.getTopCard(playerDeck);
                    String nextCardFile = getCardFileName(playerDeck.getTopCard(playerDeck));
                    playerDeck = playerDeck.shuffle(playerDeck);
                    
                    //Handles the Ace scenario.
                if(firstPlayerCard.face.equals("Ace"))
                {
                    if(secondPlayerCard.value + 11 <= 21)
                    {
                        firstPlayerCard.setValue(11);
                    }
                    else
                    {
                        firstPlayerCard.setValue(1);
                    }
                }
                if(secondPlayerCard.face.equals("Ace"))
                {
                    if(firstPlayerCard.value + 11 <= 21)
                    {
                        secondPlayerCard.setValue(11);
                    }
                    else
                    {
                        secondPlayerCard.setValue(1);
                    }
                }
                //Read the image file into an ImageIcon object.
                ImageIcon card = new ImageIcon(nextCardFile);
                cardLabel3 = new JLabel(" ");
                cardLabel3.setIcon(card);
                
                playerTotal += nextPlayerCard.value;
                
                    
                }
                //Code to generate a card hit.
            }
        }
        
    
        public static void main(String[] args)
        {
            new Game21();
        }
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  3. #3
    alacn's Avatar
    alacn is offline Senior Member
    Join Date
    Jun 2010
    Location
    UK. near London
    Posts
    118
    Rep Power
    0

    Default

    tbh i think you should optimise your code using object arrays and make it more clean/efficient using loops rather than massive conditional code blocks
    Teaching myself java so that i can eventually join the industry! Started in June 2010

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by JavaStudent1990 View Post
    I need an answer ASAP, this program is due tomorrow night.
    You are far better off leaving your urgency to yourself. It suggests that you presume that your problem is more important than any of the other threads here, and you should know now that it is not. It is after all your urgency, not ours, and while we wish you well, we do not like to feel pressured to work for a solution when we have other more important things to do. We are all volunteers after all.

    For some reason, a new error just game up, also: cannot find symbol -- method getCardFileName(blackfiles.Card)

    It doesn't recognize the getCardFileName method in the HitListener class, but it's recognized in the DealListener class.
    Of course it won't recognize the getCardFileName method since I see no where that it has been declared within the HitListener class. So the error is telling you exactly what you need to fix.

  5. #5
    Join Date
    Jul 2010
    Posts
    12
    Rep Power
    0

    Default

    Fubarable, I mean this as respectfully as possible, feel free to ban me or what not, but as a moderator, shouldn't you have a less condescending attitude? It came across that way, if you didn't mean to. I've been moderators on forums before, and if I violate a forum rule, then rebuke me--but please don't make personal comments.

    I'll change my attitude if you feel that I was rude in anyway, and I believe you said you were a professor the last time you posted on one of my threads, but you are equal on the internet and at least actually help before criticizing. Or, at least if you're going to reply to my threads again, please respond in a way that does not come across as condescending. I enjoy this forum, and I don't want to resent anyone here.

    I'm sure you get tons of students who have a sense of urgency. I don't think my thread is anymore important, I was simply explaining my situation. You assumed a bit about me.

    Now, I asked my teacher, and she gave me a simple answer, which no one here has done yet--thus, I don't think anyone has the right to be condescending until he or she answers the question (that was in the thread title). Answer all my questions, and then that person will have my (extra, in addition to the basic respect for another forum member) respect.

    The simple answer is that you only have one Action Listener (which I did not know, as I am new to Java. Everyone starts at some point. I'm a freshman in university), and you use the the "get source" method with a series of if-statements to determine which button is pressed.

    The reason my program would not compile (which is why I posted, I'm surprised you responded that way in your first response. If it compiled, I wouldn't be asking a question about why it won't compile...) is because, according to my professor, the code is only supposed to have one Action Listener.

    So please stop talking down to students who come to the forum to learn (Or maybe I just rub you the wrong way.)

    The method is recognized by the main class, and I have come to think that anything within that class is recognized, so I assumed the HitListener class, being in the same class as the method, would recognize it--alas, I was wrong. Regardless, I got my GUI working and it's gotten me an A in my course and a job as a teaching assistant for the Fall. The get method works fine without any changes.

    Here's a picture of my working program:
    http://glchriste.com/blog/wp-content...ckjackGUI1.jpg

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by JavaStudent1990 View Post
    Fubarable, I mean this as respectfully as possible, feel free to ban me or what not, but as a moderator, shouldn't you have a less condescending attitude? It came across that way, if you didn't mean to. I've been moderators on forums before, and if I violate a forum rule, then rebuke me--but please don't make personal comments.
    No one is going to ban you for these comments as you have a right to expressing your opinion.

    The only thing I was commenting on in a personal way was your comment about urgency. You'll find that if you mark posts urgent, it bugs many of the volunteers here for the reason I've mentioned, and because of this, it will have the opposite effect intended: many will avoid trying to help you. If you think me condenscending for mentioning something that if you listen to with an open mind will help you get help, well, I can't help that. For more on this, please see this link: marking threads urgent

    I'll change my attitude if you feel that I was rude in anyway, and I believe you said you were a professor the last time you posted on one of my threads, but you are equal on the internet and at least actually help before criticizing. Or, at least if you're going to reply to my threads again, please respond in a way that does not come across as condescending. I enjoy this forum, and I don't want to resent anyone here.
    Again, please see the link above. It has helped me and many others to formulate questions that get quicker and better answers.


    Now, I asked my teacher, and she gave me a simple answer, which no one here has done yet--thus, I don't think anyone has the right to be condescending until he or she answers the question (that was in the thread title). Answer all my questions, and then that person will have my (extra, in addition to the basic respect for another forum member) respect.

    The simple answer is that you only have one Action Listener (which I did not know, as I am new to Java. Everyone starts at some point. I'm a freshman in university), and you use the the "get source" method with a series of if-statements to determine which button is pressed.
    And you'll forgive me for saying that I think your teacher is wrong as that way often leads one to create "telephone switch-board" listeners, ones that hard to debug and modify. Many here, myself included, much prefer use of anonymous inner type ActionListeners, either that or private inner classes. Right now I'm leaning towards use of anonymous inner listener coupled with a separate handler or control class a la the MVC pattern (check the Wikipedia article on MVC for more on this). It scales up to larger projects much easier.



    The reason my program would not compile (which is why I posted, I'm surprised you responded that way in your first response. If it compiled, I wouldn't be asking a question about why it won't compile...) is because, according to my professor, the code is only supposed to have one Action Listener.
    That's not why it doesn't compile as many GUI classes have more than one listener. The reason yours didn't compile is because you were calling methods that didn't exist in the class, simple as that.

    So please stop talking down to students who come to the forum to learn (Or maybe I just rub you the wrong way.)
    And I'm sorry that I rubbed you the wrong way. It was not intended.

    The method is recognized by the main class, and I have come to think that anything within that class is recognized, so I assumed the HitListener class, being in the same class as the method, would recognize it--alas, I was wrong. Regardless, I got my GUI working and it's gotten me an A in my course and a job as a teaching assistant for the Fall. The get method works fine without any changes.
    And congrats on the "A".


    Here's an example program that has two different ActionListeners in one class. One is an anonymous inner class and the other a private inner class:
    Java Code:
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.*;
    
    public class MultipleListeners {
       private static void createAndShowUI() {
          JPanel panel = new MultipleListenersPanel();
    
          JFrame frame = new JFrame("MultipleListeners");
          frame.getContentPane().add(panel);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.pack();
          frame.setLocationRelativeTo(null);
          frame.setVisible(true);
       }
    
       public static void main(String[] args) {
          java.awt.EventQueue.invokeLater(new Runnable() {
             public void run() {
                createAndShowUI();
             }
          });
       }
    }
    
    class MultipleListenersPanel extends JPanel {
       public MultipleListenersPanel() {
          JButton buttonA = new JButton("Button A");
          JButton buttonB = new JButton("Button B");
          
          add(buttonA);
          add(buttonB);
          
          // anonymous inner class used 
          buttonA.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent arg0) {
                System.out.println("Button A pushed");
             }
          });
          
          // private inner class used
          buttonB.addActionListener(new PrivateInnerListener());
       }
       
       private class PrivateInnerListener implements ActionListener {
          public void actionPerformed(ActionEvent e) {
             System.out.println(e.getActionCommand() + " pushed");
          }
       }
       
    }
    Last edited by Fubarable; 08-09-2010 at 08:12 PM.

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Edit: and the main reason your class could not compile for me was that we did not have all the necessary classes, in particular the Card class and Deck class. So not being able to compile or run the code, none of us could reproduce your problem. And while we don't want your whole program, we do appreciate it if you can simplify the problem into one small compilable program that reproduces it without forcing volunteers to have to go through much unrelated code. Please read the link in my signature on creating an SSCCE, as if you can create one of these, you'll likely be able to get better and quicker help here.

  8. #8
    alacn's Avatar
    alacn is offline Senior Member
    Join Date
    Jun 2010
    Location
    UK. near London
    Posts
    118
    Rep Power
    0

    Default

    i agree with Fubarable
    tbh i use anonymous events whereever possible because it just makes alot more sense and is easier to read. Plus i used to program in visual basic which basically handles each action events in its own code block, which to me looks very similiar to anonymous class events.
    Teaching myself java so that i can eventually join the industry! Started in June 2010

  9. #9
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,234
    Rep Power
    7

    Default

    JavaStudent1990,

    Fubarable said nothing in any way that was condescending and I totally agree with his comments. He did not make any personal comments, only comments about how to get an answer more effectively. If you take this personally that is your problem not ours.

    I was simply explaining my situation. You assumed a bit about me.
    Your situation is irrelevant to the question. We don't have time to read through unnecessary commentary. All we want are the facts and details related to the question.

    Now, I asked my teacher, and she gave me a simple answer, which no one here has done yet
    Of course no one has helped you. You attack the only person who did offer some help and you expect other to help? Amazing.


    --thus, I don't think anyone has the right to be condescending until he or she answers the question
    Again, no one was condescending. However, the forum is NOT about you. You have no right to be so judgemental of people who volunteer their time in an effort to help you. You post hundreds of lines of code that doesn't compile and expect us to be mind readers on what the code is expected to do?

    Answer all my questions, and then that person will have my respect.
    Again, who do you think you are that we need to gain your respect? That attitude along with the "urgency" of the question is what gives you a bad reputation. We gladly volunteer our time to help out individuals who appreciate the time and effort we give towards solving problems.

    I'm a freshman in university
    Too bad universties to take more time to teach proper forum ettiquette.

    If it compiled, I wouldn't be asking a question about why it won't compile...
    That is not the way I interpreted your question either. I thought the GUI was working, just not responding to multiple buttons when the user clicked on it. And since we couldn't compile the code we couldn't test this out.

Similar Threads

  1. Question on Multiple Listeners implementation
    By StormyWaters in forum AWT / Swing
    Replies: 14
    Last Post: 06-11-2010, 08:28 PM
  2. Creating a GUI events with action listeners
    By sidd0123 in forum AWT / Swing
    Replies: 8
    Last Post: 04-02-2010, 11:32 PM
  3. JOptionPane, action listeners, and the Enter key.
    By DigitalMan in forum AWT / Swing
    Replies: 5
    Last Post: 01-26-2010, 02:51 AM
  4. Multiple listeners per event
    By Java Tip in forum Java Tip
    Replies: 1
    Last Post: 01-03-2008, 10:06 AM
  5. Action Event and Listeners
    By lost1 in forum New To Java
    Replies: 3
    Last Post: 11-14-2007, 04:26 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •