Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 2 of 3 FirstFirst 123 LastLast
Results 26 to 50 of 61

Thread: Tower Defense on Java

  1. #26
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Tower Defense on Java

    Some where in you GUI there is a JLabel component. It is possible to have dozens of different variables that refer to that one JLabel object. The getComponent() method gives you one of the many possible references to that JLabel object so you can call its methods

  2. #27
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Tower Defense on Java

    so say that JPanel trigger caused the event

    JLabel x = e.getComponent();
    then your code here is wrong if a JPanel triggered the event, not a JLabel.

  3. #28
    Member snowguy13's Avatar
    Join Date
    Nov 2011
    Location
    In Hyrule enjoying a chat with Demise and Ganondorf
    Posts
    339
    My Mood
    Happy
    Thanks
    31
    Thanked 48 Times in 42 Posts

    Default Re: Tower Defense on Java

    then your code here is wrong if a JPanel triggered the event, not a JLabel
    I forgot to cast the Component to a JLabel. Nevertheless, I do not intend to apply this MouseListener to a JPanel, so there is not an issue with that.

    After some exploring, I found out how it edits all references of the same object.

    MouseEvent extends AWTEvent which extends EventObject. EventObject has a protected transient Object source. I assume that transient means that when you edit one reference to an object, all of its references will be updated.

    Thanks for your help; I'm going offline for now.
    Last edited by snowguy13; December 7th, 2011 at 08:11 PM.
    Use highlight tags to help others help you!

    [highlight=Java]Your prettily formatted code goes here[/highlight]

    Using these tags makes your code formatted, and helps everyone answer your questions more easily!




    Wanna hear something funny?

    Me too.

  4. #29
    Member snowguy13's Avatar
    Join Date
    Nov 2011
    Location
    In Hyrule enjoying a chat with Demise and Ganondorf
    Posts
    339
    My Mood
    Happy
    Thanks
    31
    Thanked 48 Times in 42 Posts

    Default Re: Tower Defense on Java

    Okay. Now I'm working on saving/deleting files and the GUI's associated with the process. I have a pretty awesome load game GUI (at least I think) and now I'm working on the delete button. The only problem is that sometimes files won't delete.

    This is what the load GUI currently looks like. The mouse is invisible, but it is hovering over the "Delete" JLabel.
    LoadGameGUI-1.jpg

    This is the code I'm currently using for deleting a directory that represents a profile.
       private static void deleteFile(String path)
       {
     
          File file = new File(path);
     
          //If the file is a directory, list all of its files, then use this
          //method to delete them one by one
          if(file.isDirectory())
          {
     
             String[] files = file.list();
     
             for(int a = 0; a < files.length; a++)
             {
     
                deleteFile(path + "/" + files[a]);
     
             }
          }
     
          //If the file is a file, delete it, and assign
          //its return boolean to a boolean called 'success'
          boolean success = file.delete();
     
          //This is for debugging; I use it to tell me why the
          //file couldn't be deleted.
          JOptionPane.showMessageDialog(null, "Deletion of \n" + file.getAbsolutePath() + "\n"
    		   + (success ? "Success!" : "Failed: " + (!file.canWrite() ? "Cannot write" : "Other issue")));
     
       }

    Often, the files will fail to be deleted, and my debugging helper (the JOptionPane dialog) will tell me "other issue" (see code). Then, one minute and ten tries later, it will suddenly work... Is there a way to make it work the first time, hands down? I've tried using a loop that runs until the deletion succeeds, but then I just get a StackOverflowError...
    Use highlight tags to help others help you!

    [highlight=Java]Your prettily formatted code goes here[/highlight]

    Using these tags makes your code formatted, and helps everyone answer your questions more easily!




    Wanna hear something funny?

    Me too.

  5. #30
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Tower Defense on Java

    Are the files being used by other versions of your program?

  6. #31
    Member snowguy13's Avatar
    Join Date
    Nov 2011
    Location
    In Hyrule enjoying a chat with Demise and Ganondorf
    Posts
    339
    My Mood
    Happy
    Thanks
    31
    Thanked 48 Times in 42 Posts

    Default Re: Tower Defense on Java

    Are the files being used by other versions of your program?
    Well, it's complicated to explain, but I think it may be the GUI itself that is using the files. The GUI I picture above creates the panels inside of it by this code:
       private static String[] getProfileNames()
       {
     
          File profileDirectory = new File(getAppDataDirectory() + "/.WeatherTowerDefense/profiles");
     
          return profileDirectory.list();
     
       }
     
       private static int numPages;
       private static int pageNum = 1;
       private static String[][] pages = organizeProfileNames();
     
       private static void refreshProfileList()
       {
     
          pages = organizeProfileNames();
     
       }
     
       private static String[][] organizeProfileNames()
       {
     
          String[] names = getProfileNames();
     
          int numOfPages = ((names.length - 1) / 5) + 1;
          numPages = numOfPages;
          int numOnLastPage = names.length - ((numOfPages - 1) * 5);
          String[][] tempPages = new String[numOfPages][];
     
          for(int a = 0; a < numOfPages; a++)
          {
     
             tempPages[a] = new String[(a == numOfPages - 1 ? numOnLastPage : 5)];
     
          }
     
          int namesIndex = 0;
     
          for(int a = 0; a < numOfPages; a++)
          {
     
             for(int b = 0; b < (a == numOfPages - 1 ? numOnLastPage : 5); b++)
             {
     
     
                tempPages[a][b] = names[namesIndex];
                namesIndex += 1;
     
             }
          }
     
          return tempPages;
       }

    Basically what it does is it gets all of the known profiles that are store in the "/.WeatherTowerDefense/profiles" folder, which is located in the user's Application Data folder (or a similar folder). After all of the profile folders are organized into pages (obviously I can't just keep piling up panels; the window would get too tall), this code creates the panels pictured in the GUI:
          for(int a = 0; a < pages[pageNum - 1].length; a++)
          {
     
             add(new LoadableGamePanel(pages[pageNum - 1][a]));
     
          }

    So maybe the program can't delete the files because it thinks it's using them, even though they are no longer necessary for it to function?

    However, this is weirder: the deletion attempts will randomly work, after failing a plethora of times... I'm so confused...
    Use highlight tags to help others help you!

    [highlight=Java]Your prettily formatted code goes here[/highlight]

    Using these tags makes your code formatted, and helps everyone answer your questions more easily!




    Wanna hear something funny?

    Me too.

  7. #32
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Tower Defense on Java

    If parts of your program are using a file,then you will not be able to delete it.
    You need to close the file when the code is finished using it.

  8. The Following User Says Thank You to Norm For This Useful Post:

    snowguy13 (December 9th, 2011)

  9. #33
    Member snowguy13's Avatar
    Join Date
    Nov 2011
    Location
    In Hyrule enjoying a chat with Demise and Ganondorf
    Posts
    339
    My Mood
    Happy
    Thanks
    31
    Thanked 48 Times in 42 Posts

    Default Re: Tower Defense on Java

    You need to close the file when the code is finished using it.
    ...THANK YOU!!!!! It works GREAT!

    It was as simple as adding this:

    fr.close();
    br.close();

    where fr is a FileReader, and br is a BufferedReader!

    Thank you so much! And now... my next problem... (get your facepalms out of the way now...)

    ....and I'm on a roll now. I'll tell you if I get another problem, but I'm working on renaming right now.

    Thanks so much, Norm.
    Use highlight tags to help others help you!

    [highlight=Java]Your prettily formatted code goes here[/highlight]

    Using these tags makes your code formatted, and helps everyone answer your questions more easily!




    Wanna hear something funny?

    Me too.

  10. #34
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Tower Defense on Java

    See you later.

  11. #35
    Member snowguy13's Avatar
    Join Date
    Nov 2011
    Location
    In Hyrule enjoying a chat with Demise and Ganondorf
    Posts
    339
    My Mood
    Happy
    Thanks
    31
    Thanked 48 Times in 42 Posts

    Default Re: Tower Defense on Java

    YESSSSSS!

    I got the rename function to work! Now, I can start working on the actual game GUI! And then, it's the end of the easy stuff, for I have to start thinking about complex tower, bullet, and enemy interactions, along with the correct enemy path, status defects, etc... The task is daunting...

    But, I think I'll rest for tonight, to gather my thoughts. Thanks again for your help, Norm!
    Use highlight tags to help others help you!

    [highlight=Java]Your prettily formatted code goes here[/highlight]

    Using these tags makes your code formatted, and helps everyone answer your questions more easily!




    Wanna hear something funny?

    Me too.

  12. #36
    Member snowguy13's Avatar
    Join Date
    Nov 2011
    Location
    In Hyrule enjoying a chat with Demise and Ganondorf
    Posts
    339
    My Mood
    Happy
    Thanks
    31
    Thanked 48 Times in 42 Posts

    Default Re: Tower Defense on Java

    Alright I have a new problem, this time with a KeyListener.

    Here is the code I'm using for the KeyListener:

       //KeyListener for NewGameGUI
       private class KListener implements KeyListener
       {
     
          public void keyTyped(KeyEvent e)
          {
     
             if(e.getKeyCode() == KeyEvent.VK_ESCAPE)
             {
     
                dispose();
                new MainGUI();
     
             }
             else if(e.getKeyCode() == KeyEvent.VK_ENTER)
             {
     
                if(validName)
                {
     
                   createNewGame(nameField.getText());
                   dispose();
                   new MainGUI();
     
                }
                else
                {
     
                   createLabel.setForeground(textColor_inactive);
                   createLabel.setBackground(backgroundColor_inactive);
                   createLabel.setBorder(border_inactive);
                   createLabel.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
     
                }
             }
          }
     
          public void keyPressed(KeyEvent e)
          {
     
          }
     
          public void keyReleased(KeyEvent e)
          {
     
          }
       }

    And then this code adds it to a JTextField:

       //Add the KeyListener to only the nameField (input field for file name)
       //because adding it to the JFrame didn't work
       nameField.addKeyListener(new KListener());

    When I type enter or escape, nothing happens. I have also tried this code combination:

       //KeyListener for NewGameGUI
       private class KListener implements KeyListener
       {
     
          public void keyTyped(KeyEvent e)
          {
     
          }
     
          public void keyPressed(KeyEvent e)
          {
     
          }
     
          public void keyReleased(KeyEvent e)
          {
     
             if(e.getKeyCode() == KeyEvent.VK_ESCAPE)
             {
     
                dispose();
                new MainGUI();
     
             }
             else if(e.getKeyCode() == KeyEvent.VK_ENTER)
             {
     
                if(validName)
                {
     
                   createNewGame(nameField.getText());
                   dispose();
                   new MainGUI();
     
                }
                else
                {
     
                   createLabel.setForeground(textColor_inactive);
                   createLabel.setBackground(backgroundColor_inactive);
                   createLabel.setBorder(border_inactive);
                   createLabel.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
     
                }
             }
          }
       }
       //Add the KeyListener to the entire JFrame
       addKeyListener(new KListener());

    I'm pretty sure this issue has something to do with the JTextField somehow blocking the event, and if that is the problem I don't know how to bypass it. And then it could also be something totally different as well. Any help would be appreciated.
    Use highlight tags to help others help you!

    [highlight=Java]Your prettily formatted code goes here[/highlight]

    Using these tags makes your code formatted, and helps everyone answer your questions more easily!




    Wanna hear something funny?

    Me too.

  13. #37
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Tower Defense on Java

    Your code doesn't have an printlns to show you what is happening.

    Please make a small simple complete program (SSCCE) that compiles and executes and shows your problem and post it here.

  14. #38
    Member snowguy13's Avatar
    Join Date
    Nov 2011
    Location
    In Hyrule enjoying a chat with Demise and Ganondorf
    Posts
    339
    My Mood
    Happy
    Thanks
    31
    Thanked 48 Times in 42 Posts

    Default Re: Tower Defense on Java

    Your code doesn't have an printlns to show you what is happening.
    printlns? Why would it have those? None of my program is done in the terminal.

    Please make a small simple complete program (SSCCE) that compiles and executes and shows your problem and post it here.
    I don't completely understand... Do you want me just to copy the code for the NewGameGUI (from which the above snippets were collected) here?
    Use highlight tags to help others help you!

    [highlight=Java]Your prettily formatted code goes here[/highlight]

    Using these tags makes your code formatted, and helps everyone answer your questions more easily!




    Wanna hear something funny?

    Me too.

  15. #39
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Tower Defense on Java

    Quote Originally Posted by snowguy13 View Post
    printlns? Why would it have those? None of my program is done in the terminal.


    I don't completely understand... Do you want me just to copy the code for the NewGameGUI (from which the above snippets were collected) here?
    Suggested Reading:
    http://www.javaprogrammingforums.com...t-println.html
    http://www.javaprogrammingforums.com...why-sscce.html

  16. The Following User Says Thank You to copeg For This Useful Post:

    Norm (December 10th, 2011)

  17. #40
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Tower Defense on Java

    I use printlns for debugging. When I don't know what a program is doing I add printlns so I can see what is happening.

    Do you want me just to copy the code for the NewGameGUI
    No. I want a small program that has just enough in it to show the problem. Nothing more.

  18. #41
    Member snowguy13's Avatar
    Join Date
    Nov 2011
    Location
    In Hyrule enjoying a chat with Demise and Ganondorf
    Posts
    339
    My Mood
    Happy
    Thanks
    31
    Thanked 48 Times in 42 Posts

    Default Re: Tower Defense on Java

    I have to go now... Sorry for the abruptness. I'll work on that code and put it here when I finish.
    Use highlight tags to help others help you!

    [highlight=Java]Your prettily formatted code goes here[/highlight]

    Using these tags makes your code formatted, and helps everyone answer your questions more easily!




    Wanna hear something funny?

    Me too.

  19. #42
    Member snowguy13's Avatar
    Join Date
    Nov 2011
    Location
    In Hyrule enjoying a chat with Demise and Ganondorf
    Posts
    339
    My Mood
    Happy
    Thanks
    31
    Thanked 48 Times in 42 Posts

    Default Re: Tower Defense on Java

    Okay. Here's the SSCCE I made.

    package GUIs;
     
    import java.awt.GridBagLayout;
    import java.awt.GridBagConstraints;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    import javax.swing.JLabel;
    import java.awt.event.KeyListener;
    import java.awt.event.KeyEvent;
    import javax.swing.SwingConstants;
    import javax.swing.JOptionPane;
     
    public class KLSSCCE extends JFrame
    {
     
       public static void main(String[] args)
       {
     
          new KLSSCCE();
     
       }
     
       //Create final integers to represent the window's size
       private final int WINDOW_WIDTH = 300;
       private final int WINDOW_HEIGHT = 200;
     
       public KLSSCCE()
       {
     
          super("Key Listener SSCCE");
          JOptionPane.showMessageDialog(
                  null, 
                  "This is a simplified example of my problem.\n"
                  + "Pressing Enter or Escape should terminate this program.\n"
                  + "Neither works. I believe the JTextField is the culprit.");
          System.out.print("Initializing frame and size...");
          setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
          setResizable(false);
          setLocationRelativeTo(null);
          setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          System.out.print(" Done.\n");
          addPanel();
          System.out.print("Adding key listener..."); 
          textField.addKeyListener(new KListener());
          System.out.print(" Done.\n");
          System.out.print("Displaying window...");
          setVisible(true);
          System.out.print(" Done.\n");
     
       }
     
       private JPanel panel;
       private JTextField textField;
       private JLabel infoLabel;
     
       private void addPanel()
       {
     
          System.out.print("Building panel and text field...");
          panel = new JPanel(new GridBagLayout());
          GridBagConstraints c = new GridBagConstraints();
          c.gridx = 1;
          c.gridy = 1;
          c.weightx = 0.5;
          c.weighty = 0.5;
          c.ipadx = 100;
          c.ipady = 10;
          textField = new JTextField(WINDOW_WIDTH - 10);
          panel.add(textField, c);
          infoLabel = new JLabel("Pressing Enter or Escape should exit the program.", SwingConstants.CENTER);
          c.gridy = 0;
          panel.add(infoLabel, c);
          add(panel);
          System.out.print(" Done.\n");
     
       }
     
       private class KListener implements KeyListener
       {
     
          public void keyTyped(KeyEvent e)
          {
     
             if(e.getKeyCode() == KeyEvent.VK_ESCAPE)
             {
     
                System.out.print("Escape key pressed. Disposing of window...");
                dispose();
                System.out.print(" Done.\nExiting program...");
                System.exit(0);
     
             }
             else if(e.getKeyCode() == KeyEvent.VK_ENTER)
             {
     
                System.out.print("Enter key pressed. Disposing of window...");
                dispose();
                System.out.print(" Done.\nExiting program...");
                System.exit(0);
     
             }
          }
     
          public void keyPressed(KeyEvent e)
          {
     
          }
     
          public void keyReleased(KeyEvent e)
          {
     
          }
       }
    }
    Use highlight tags to help others help you!

    [highlight=Java]Your prettily formatted code goes here[/highlight]

    Using these tags makes your code formatted, and helps everyone answer your questions more easily!




    Wanna hear something funny?

    Me too.

  20. #43
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Tower Defense on Java

    Where is the printlns I suggested you add to the listener methods to see if they are being called?
    When I added some I got this:
    sP e=java.awt.event.KeyEvent[KEY_PRESSED,keyCode=10,keyText=Enter,keyChar=Enter ,keyLocation=KEY_LOCATION_STANDARD,rawCode=13,prim aryLevelUnicode=13,scancode=28] on javax.swing.JTextField[,95,107,104x30,layout=javax.swing.plaf.basic.Basic TextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0 ,border=javax.swing.plaf.BorderUIResource$Compound BorderUIResource@169e11,flags=296,maximumSize=,min imumSize=,preferredSize=,caretColor=sun.swing.Prin tColorUIResource[r=51,g=51,b=51],disabledTextColor=javax.swing.plaf.ColorUIResourc e[r=184,g=207,b=229],editable=true,margin=javax.swing.plaf.InsetsUIRes ource[top=0,left=0,bottom=0,right=0],selectedTextColor=sun.swing.PrintColorUIResource[r=51,g=51,b=51],selectionColor=javax.swing.plaf.ColorUIResource[r=184,g=207,b=229],columns=290,columnWidth=11,command=,horizontalAli gnment=LEADING]
    sT e=java.awt.event.KeyEvent[KEY_TYPED,keyCode=0,keyText=Unknown keyCode: 0x0,keyChar=Enter,keyLocation=KEY_LOCATION_UNKNOWN ,rawCode=0,primaryLevelUnicode=0,scancode=0] on javax.swing.JTextField[,95,107,104x30,layout=javax.swing.plaf.basic.Basic TextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0 ,border=javax.swing.plaf.BorderUIResource$Compound BorderUIResource@169e11,flags=296,maximumSize=,min imumSize=,preferredSize=,caretColor=sun.swing.Prin tColorUIResource[r=51,g=51,b=51],disabledTextColor=javax.swing.plaf.ColorUIResourc e[r=184,g=207,b=229],editable=true,margin=javax.swing.plaf.InsetsUIRes ource[top=0,left=0,bottom=0,right=0],selectedTextColor=sun.swing.PrintColorUIResource[r=51,g=51,b=51],selectionColor=javax.swing.plaf.ColorUIResource[r=184,g=207,b=229],columns=290,columnWidth=11,command=,horizontalAli gnment=LEADING]

  21. #44
    Member snowguy13's Avatar
    Join Date
    Nov 2011
    Location
    In Hyrule enjoying a chat with Demise and Ganondorf
    Posts
    339
    My Mood
    Happy
    Thanks
    31
    Thanked 48 Times in 42 Posts

    Default Re: Tower Defense on Java

    Oh. I think I'm misunderstanding you. By printlns, I thought you meant this (which is what I did):
             if(e.getKeyCode() == KeyEvent.VK_ESCAPE)
             {
     
                System.out.print("Escape key pressed. Disposing of window...");
                dispose();
                System.out.print(" Done.\nExiting program...");
                System.exit(0);
     
             }
    Note the print statements at the top and bottom of the code block. That's what I thought you meant. What did you actually mean?

    Also note that those statements never printed, which means that the KeyEvent either a) doesn't occur, b) is blocked, or c) is wrongly coded by me.
    Use highlight tags to help others help you!

    [highlight=Java]Your prettily formatted code goes here[/highlight]

    Using these tags makes your code formatted, and helps everyone answer your questions more easily!




    Wanna hear something funny?

    Me too.

  22. #45
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Tower Defense on Java

    What the printlns will tell you is if the listeners are being called. They are.
    So now you need to look at the event object data and see how you can detect the keys you want to handle in the listener.
    Your printlns would only print if everything worked the way you expected. The first question was: Is the listener being called and it looks like it is.

  23. #46
    Member snowguy13's Avatar
    Join Date
    Nov 2011
    Location
    In Hyrule enjoying a chat with Demise and Ganondorf
    Posts
    339
    My Mood
    Happy
    Thanks
    31
    Thanked 48 Times in 42 Posts

    Default Re: Tower Defense on Java

    Well firstly how did you get the program to display this:
    sP e=java.awt.event.KeyEvent[KEY_PRESSED,keyCode=10,keyText=Enter,keyChar=Enter ,keyLocation=KEY_LOCATION_STANDARD,rawCode=13,prim aryLevelUnicode=13,scancode=28] on javax.swing.JTextField[,95,107,104x30,layout=javax.swing.plaf.basic.Basic TextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0 ,border=javax.swing.plaf.BorderUIResource$Compound BorderUIResource@169e11,flags=296,maximumSize=,min imumSize=,preferredSize=,caretColor=sun.swing.Prin tColorUIResource[r=51,g=51,b=51],disabledTextColor=javax.swing.plaf.ColorUIResourc e[r=184,g=207,b=229],editable=true,margin=javax.swing.plaf.InsetsUIRes ource[top=0,left=0,bottom=0,right=0],selectedTextColor=sun.swing.PrintColorUIResource[r=51,g=51,b=51],selectionColor=javax.swing.plaf.ColorUIResource[r=184,g=207,b=229],columns=290,columnWidth=11,command=,horizontalAli gnment=LEADING]
    sT e=java.awt.event.KeyEvent[KEY_TYPED,keyCode=0,keyText=Unknown keyCode: 0x0,keyChar=Enter,keyLocation=KEY_LOCATION_UNKNOWN ,rawCode=0,primaryLevelUnicode=0,scancode=0] on javax.swing.JTextField[,95,107,104x30,layout=javax.swing.plaf.basic.Basic TextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0 ,border=javax.swing.plaf.BorderUIResource$Compound BorderUIResource@169e11,flags=296,maximumSize=,min imumSize=,preferredSize=,caretColor=sun.swing.Prin tColorUIResource[r=51,g=51,b=51],disabledTextColor=javax.swing.plaf.ColorUIResourc e[r=184,g=207,b=229],editable=true,margin=javax.swing.plaf.InsetsUIRes ource[top=0,left=0,bottom=0,right=0],selectedTextColor=sun.swing.PrintColorUIResource[r=51,g=51,b=51],selectionColor=javax.swing.plaf.ColorUIResource[r=184,g=207,b=229],columns=290,columnWidth=11,command=,horizontalAli gnment=LEADING]
    ..?

    And if you say the listener is being called, why aren't my statements printing?
    Use highlight tags to help others help you!

    [highlight=Java]Your prettily formatted code goes here[/highlight]

    Using these tags makes your code formatted, and helps everyone answer your questions more easily!




    Wanna hear something funny?

    Me too.

  24. #47
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Tower Defense on Java

    I printed the value of the e object passed to the listener methods.

    why aren't my statements printing?
    Because your if tests are not true.

  25. #48
    Member snowguy13's Avatar
    Join Date
    Nov 2011
    Location
    In Hyrule enjoying a chat with Demise and Ganondorf
    Posts
    339
    My Mood
    Happy
    Thanks
    31
    Thanked 48 Times in 42 Posts

    Default Re: Tower Defense on Java

    Because your if tests are not true.
    -_- Well yes, I surmised that much. However, how is the enter key's code not equal to KeyEvent.VK_ENTER? I don't know what else it would be...
    Use highlight tags to help others help you!

    [highlight=Java]Your prettily formatted code goes here[/highlight]

    Using these tags makes your code formatted, and helps everyone answer your questions more easily!




    Wanna hear something funny?

    Me too.

  26. #49
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Tower Defense on Java

    Did you look at the contents of the Event object?

  27. #50
    Member snowguy13's Avatar
    Join Date
    Nov 2011
    Location
    In Hyrule enjoying a chat with Demise and Ganondorf
    Posts
    339
    My Mood
    Happy
    Thanks
    31
    Thanked 48 Times in 42 Posts

    Default Re: Tower Defense on Java

    Did you look at the contents of the Event object?
    I did now. Problem fixed. Thanks.
    Use highlight tags to help others help you!

    [highlight=Java]Your prettily formatted code goes here[/highlight]

    Using these tags makes your code formatted, and helps everyone answer your questions more easily!




    Wanna hear something funny?

    Me too.

Page 2 of 3 FirstFirst 123 LastLast

Similar Threads

  1. Extended Hanooi Tower
    By mahsa in forum Algorithms & Recursion
    Replies: 1
    Last Post: December 31st, 2010, 05:55 PM