Results 1 to 4 of 4
  1. #1
    the_rider9 is offline Member
    Join Date
    May 2011
    Posts
    7
    Rep Power
    0

    Default Main GUI's method to react to alert frame's buttons

    I have a method called checkForm in my GUI class, where when called, an alert frame pops up (called from another class AlertFrame).

    Depending on what button the user clicks, OK or Cancel, I would like the checkForm method to do an if/else statement,

    ex. if(OK button was pressed in AlertFrame, do this) else (Cancel button was pressed in AlertFrame, do this)

    it is important to note that the AlertFrame is called from my checkForm(), and the if else statement is also in the checkForm()...

    Any ideas? I have tried to create separate threads, listeners etc...nothing worked

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Each button should have a listener attached to it which does what is required when that button is pressed.

  3. #3
    the_rider9 is offline Member
    Join Date
    May 2011
    Posts
    7
    Rep Power
    0

    Default

    So if i understand correctly, it is impossible to have one class alertframe used to display alerts throughout my program (where strings are passed through the alertframe's constructor representing the desired message)? Therefore every alert requires to be defined in separate classes?
    Last edited by the_rider9; 07-09-2011 at 08:13 AM.

  4. #4
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    You can pass a string argument into the constructor if you'd like, but having it do things based on the string message will require a bit more logic.

    If you have a pre determined amount of possible alerts you can code the listeners of buttons to do something based on that string.

    JOptionPane may be helpful for what you want: http://download.oracle.com/javase/6/...ptionPane.html
    Last edited by sunde887; 07-09-2011 at 08:17 AM.

Similar Threads

  1. Replies: 7
    Last Post: 04-03-2011, 01:35 PM
  2. Java slave Frame access to its owner main frame problem
    By cagdaseckin in forum New To Java
    Replies: 0
    Last Post: 12-10-2010, 11:40 AM
  3. Calling The main method from another method
    By SwissR in forum New To Java
    Replies: 3
    Last Post: 07-27-2010, 12:03 PM
  4. Buttons and Method
    By imagiro1 in forum New To Java
    Replies: 2
    Last Post: 05-03-2010, 05:09 AM
  5. calling method from main method
    By bob_bee in forum New To Java
    Replies: 4
    Last Post: 10-02-2009, 06:30 PM

Posting Permissions

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