Page 1 of 2 12 LastLast
Results 1 to 20 of 34
  1. #1
    hooshdar3 is offline Member
    Join Date
    Jul 2014
    Posts
    28
    Rep Power
    0

    Default actions for multiple dialogues

    Hello.
    I have two dialogues: one name "dialog" and another named "queryDialog". Each dialog has one button among other things and they are supposed to make their respective dialogues hide when clicked. But the second button doesn't work.Here is my code:
    Java Code:
    import java.io.*;
    import java.util.*;
    import java.util.concurrent.TimeUnit;
    import com.sun.management.OperatingSystemMXBean;
    import java.lang.management.ManagementFactory;
    import java.lang.System;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.lang.reflect.Method;
    import java.lang.reflect.Modifier;
    
        public class SysinfoHooshi implements ActionListener{
    ..
        JDialog dialog = new  JDialog();	
        JButton button = new JButton("OK");
       
        /****************Query dialog variables*******************/
        JDialog queryDialog = new  JDialog();	
        JButton queryButton = new JButton("OK");
    ...
        /*********************************************************/
        
    	public  void simulate()throws Exception{
    	
    		this.showDialog();
    		...
    		showQueryDialog();	
    	}//end simulate()
    	
    	public void showDialog()
    	{
    		dialog.setModal(true);
    		dialog.setSize(400, 150);
    	
    		dialog.setTitle("Input dialog");
    	
    		Container pane = dialog.getContentPane();
    		pane.setLayout(null);
    ...
    		pane.add(button);
    		button.addActionListener(this);
    		button.setBounds(100,100,80,30);
    		dialog.setVisible(true);
    	}
    		 	
    	 public void actionPerformed(ActionEvent e) {
    		  	 dialog.setVisible(false);
    			 System.out.println("Here1");
    		 }
    
    	public void showQueryDialog()
    	{
    		queryDialog.setModal(true);
    		queryDialog.setSize(400, 150);
    	
    		queryDialog.setTitle("Query dialog");
    	
    		JPanel queryPane = new  JPanel();
    		queryPane.setLayout(new FlowLayout());
    		...
    		queryPane.add(queryButton);
    		queryDialog.add(queryPane);	
    		queryDialog.setVisible(true);
    		...
    		queryButton.addActionListener(new ActionListener(){
    			@Override
    			public void  actionPerformed(ActionEvent e)
    			{
    			   queryDialog.setVisible(false);
    			    System.out.println("Here2");
    			}
    		}
    		);
    	}
    ..	 	
    	public static void main(String args[]) throws Exception{	
    	SysinfoHooshi o = new SysinfoHooshi();
    	o.simulate();
    	} // end main
       }// end class
    I tried to follow the example of How to add multiple ActionListeners for multiple buttons in Java Swing - Stack Overflow but there seems to be a problem.
    Where have I gone wrong?
    Thanks in advance

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default Re: actions for multiple dialogues

    the second button doesn't work
    Can you explain?
    Where is the problem? Is the listener called?

    The posted code does not compile. Please fix the compiler errors.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    hooshdar3 is offline Member
    Join Date
    Jul 2014
    Posts
    28
    Rep Power
    0

    Default Re: actions for multiple dialogues

    Quote Originally Posted by Norm View Post
    Can you explain?
    Where is the problem? Is the listener called?

    The posted code does not compile. Please fix the compiler errors.
    OK.I will past the code again

  4. #4
    hooshdar3 is offline Member
    Join Date
    Jul 2014
    Posts
    28
    Rep Power
    0

    Default Re: actions for multiple dialogues

    Java Code:
    import java.io.*;
    import java.util.*;
    import java.util.concurrent.TimeUnit;
    import com.sun.management.OperatingSystemMXBean;
    import java.lang.management.ManagementFactory;
    import java.lang.System;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.lang.reflect.Method;
    import java.lang.reflect.Modifier;
    
        public class SysinfoHooshi implements ActionListener{
    		int k;
    		
    		class Info{			
    			public String name;
    			public String version;
    			public String arch;
    			public double ramUtil;
    			public double CPUUtil;
    		};
        
        JTextField  tf = new JTextField("");
        JTextField  tf2 = new JTextField("");
        JDialog dialog = new  JDialog();	
        JButton button = new JButton("OK");
       
        /****************Query dialog variables*******************/
        JDialog queryDialog = new  JDialog();	
        JButton queryButton = new JButton("OK");
        JCheckBox chkCPUUtil = new JCheckBox("CPU utilization");
        JCheckBox chkRAMUtil = new JCheckBox("RAM utilization");
        JCheckBox chkVersion = new JCheckBox("Version of the OS");
        JCheckBox chkArch = new JCheckBox("Processor architecture");
        JCheckBox chkName = new JCheckBox("Operating system name");
        boolean nameChecked, versionChecked, archChecked, CPUChecked, RAMChecked;
        /*********************************************************/
        
    	public  void simulate()throws Exception{
    	
    		this.showDialog();
    		showQueryDialog();
    		
    	}//end simulate()
    	
    	public void showDialog()
    	{
    		dialog.setModal(true);
    		dialog.setSize(400, 150);
    	
    		dialog.setTitle("Input dialog");
    	
    		Container pane = dialog.getContentPane();
    		pane.setLayout(null);
    		
    		pane.add(button);
    		button.addActionListener(this);
    		button.setBounds(100,100,80,30);
    		dialog.setVisible(true);
    	}
    		 	
    	 public void actionPerformed(ActionEvent e) {
    		  	 dialog.setVisible(false);
    			 System.out.println("Here1");
    		 }
    
    	public void showQueryDialog()
    	{
    		queryDialog.setModal(true);
    		queryDialog.setSize(400, 150);
    	
    		queryDialog.setTitle("Query dialog");
    	
    		JPanel queryPane = new  JPanel();
    		queryPane.setLayout(new FlowLayout());
    		queryPane.add(chkName);
    		queryPane.add(chkVersion);
    		queryPane.add(chkArch);	
    		queryPane.add(queryButton);
    		queryDialog.add(queryPane);	
    		queryDialog.setVisible(true);
    
    		queryButton.addActionListener(new ActionListener(){
    			@Override
    			public void  actionPerformed(ActionEvent e)
    			{
    			   queryDialog.setVisible(false);
    			    System.out.println("Here2");
    			}
    		}
    		);
    	}
    
    	public static void main(String args[]) throws Exception{	
    	SysinfoHooshi o = new SysinfoHooshi();
    	o.simulate();
    	} // end main
       }// end class

  5. #5
    hooshdar3 is offline Member
    Join Date
    Jul 2014
    Posts
    28
    Rep Power
    0

    Default Re: actions for multiple dialogues

    By "doesn't work", I mean that clicking it performs no action

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default Re: actions for multiple dialogues

    The dialog is set to be modal. Do you understand what that means? What does the API doc say about the setModal() method?
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    hooshdar3 is offline Member
    Join Date
    Jul 2014
    Posts
    28
    Rep Power
    0

    Default Re: actions for multiple dialogues

    Quote Originally Posted by Norm View Post
    The dialog is set to be modal. Do you understand what that means? What does the API doc say about the setModal() method?
    it should set the modality, I.e forceability, of inputting to the dialogue. Means the program execution stops until you close the dialog.

    I have no access to Oracle/sun documentation now, but see
    java - How to pause execution while JDialog is open - Stack Overflow

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default Re: actions for multiple dialogues

    the program execution stops until you close the dialog.
    Ok, where does the execution stop? At what statement in your program?

    I have no access to Oracle/sun documentation
    Here is the API doc: Java Platform SE 7
    If you don't understand my response, don't ignore it, ask a question.

  9. #9
    hooshdar3 is offline Member
    Join Date
    Jul 2014
    Posts
    28
    Rep Power
    0

    Default Re: actions for multiple dialogues

    Quote Originally Posted by Norm View Post
    Ok, where does the execution stop? At what statement in your program?
    In simulate(), between the two calls[there are many lines of code which I have deleted]

    And thanks for your link.The doc reads:

    The modal dialog box captures the window focus until it is closed, usually in response to a button press.
    Last edited by hooshdar3; 07-19-2014 at 07:53 AM.

  10. #10
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default Re: actions for multiple dialogues

    In simulate(), between the two calls
    A more exact location needs to be found than that. At what statement does execution pause?
    If you don't understand my response, don't ignore it, ask a question.

  11. #11
    hooshdar3 is offline Member
    Join Date
    Jul 2014
    Posts
    28
    Rep Power
    0

    Default Re: actions for multiple dialogues

    Quote Originally Posted by Norm View Post
    A more exact location needs to be found than that. At what statement does execution pause?
    After the semicolon of the call this.showDialog(); and before the execution of the call queryDialog();

    The following lines need to placed after this.showDialog() call:

    Java Code:
    	int simTime = Integer.parseInt( tf.getText() );;
    		int interval = Integer.parseInt( tf2.getText() );
    		
    		
    		int queueSize = 60*simTime/interval;
    		
    		System.out.println( simTime*60+"/"+interval+" ="+queueSize );
    	
    		Info[] queue = new Info[queueSize];
    Last edited by hooshdar3; 07-19-2014 at 08:37 AM.

  12. #12
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default Re: actions for multiple dialogues

    before the execution of the call queryDialog();
    That would mean that the second dialog window("Query dialog") is not being shown. But your question says that the dialog is being shown with a button and that there is no response when the button is pressed.

    Is the "Query dialog" window being shown? It would not be shown if the execution stops before the call to the queryDialog() method.

    Also posted at: http://forums.codeguru.com/showthrea...ltiple-dialogs
    Last edited by Norm; 07-19-2014 at 04:27 PM.
    If you don't understand my response, don't ignore it, ask a question.

  13. #13
    hooshdar3 is offline Member
    Join Date
    Jul 2014
    Posts
    28
    Rep Power
    0

    Default Re: actions for multiple dialogues

    Quote Originally Posted by Norm View Post
    That would mean that the second dialog window("Query dialog") is not being shown. But your question says that the dialog is being shown with a button and that there is no response when the button is pressed.

    Is the "Query dialog" window being shown? It would not be shown if the execution stops before the call to the queryDialog() method.

    Also posted at: multiple dialogs
    queryDialogue will be shown, yes, but after I closed "dialog" by clicking its button.

  14. #14
    hooshdar3 is offline Member
    Join Date
    Jul 2014
    Posts
    28
    Rep Power
    0

    Default Re: actions for multiple dialogues

    Quote Originally Posted by Norm View Post
    That would mean that the second dialog window("Query dialog") is not being shown. But your question says that the dialog is being shown with a button and that there is no response when the button is pressed.

    Is the "Query dialog" window being shown? It would not be shown if the execution stops before the call to the queryDialog() method.

    Also posted at: multiple dialogs
    queryDialogue will be shown, yes, but after I closed "dialog" by clicking its button.

  15. #15
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default Re: actions for multiple dialogues

    You need to find the LAST statement to be executed showing the statement where execution pauses.
    One way is to add lots of println() statements. The location of the pause will be shown between the last one that prints a message and before the next one that does NOT print a message.
    If you don't understand my response, don't ignore it, ask a question.

  16. #16
    hooshdar3 is offline Member
    Join Date
    Jul 2014
    Posts
    28
    Rep Power
    0

    Default Re: actions for multiple dialogues

    Quote Originally Posted by Norm View Post
    You need to find the LAST statement to be executed showing the statement where execution pauses.
    One way is to add lots of println() statements. The location of the pause will be shown between the last one that prints a message and before the next one that does NOT print a message.
    It will pause at queryDialog.setVisible()

  17. #17
    hooshdar3 is offline Member
    Join Date
    Jul 2014
    Posts
    28
    Rep Power
    0

    Default Re: actions for multiple dialogues

    Quote Originally Posted by hooshdar3 View Post
    It will pause at queryDialog.setVisible()
    I also discovered that Checking the 'JCheckBox'es also performs no action:When I close the queryDiallog(because my queryButton doesn't perfprm when clicking it), upon returning from call to showQueryDialog(), the 3 boolean variables boolean nameChecked, versionChecked, archChecked contain the values "false"L the 3 if/else constructs
    Java Code:
    	if(nameChecked==true)
    			System.out.println("True");
    		else
    		   System.out.println("false");
    		if(versionChecked==true)	
    			System.out.println("True");		
    		else
    		   System.out.println("false");
    		if(archChecked==true)
    			System.out.println("True");
    		else
    		   System.out.println("false");
    print 3 "false" strings on the monitor.
    Last edited by hooshdar3; 07-20-2014 at 04:09 AM.

  18. #18
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default Re: actions for multiple dialogues

    If the program pauses at that statement and shows the dialog window, are there any statements after that one where the program pauses that need to be executed before the pause?

    The code in post#17 is not in the code shown in post#4.
    Last edited by Norm; 07-20-2014 at 04:45 AM.
    If you don't understand my response, don't ignore it, ask a question.

  19. #19
    hooshdar3 is offline Member
    Join Date
    Jul 2014
    Posts
    28
    Rep Power
    0

    Default Re: actions for multiple dialogues

    Quote Originally Posted by Norm View Post
    If the program pauses at that statement and shows the dialog window, are there any statements after that one where the program pauses that need to be executed before the pause?
    .
    No, there is no such statement

    The code in post#17 is not in the code shown in post#4
    I added it recently, just to check the booleans

  20. #20
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default Re: actions for multiple dialogues

    there is no such statement
    What statement is there after the call to setVisible()?
    Is it related to the problem: the second button doesn't work?

    Remember that the statement after where the program pauses is NOT executed until the execution flow returns from the pause.
    If you don't understand my response, don't ignore it, ask a question.

Page 1 of 2 12 LastLast

Similar Threads

  1. Why actions in url?
    By SomeoneHere in forum Struts
    Replies: 5
    Last Post: 01-10-2012, 06:07 AM
  2. Actions
    By What2do in forum New To Java
    Replies: 4
    Last Post: 01-31-2011, 05:45 PM
  3. How to Use Actions
    By AJArmstron@aol.com in forum New To Java
    Replies: 4
    Last Post: 04-18-2010, 10:03 PM
  4. Replies: 6
    Last Post: 02-01-2010, 10:30 AM
  5. Actions
    By alley in forum AWT / Swing
    Replies: 2
    Last Post: 01-16-2008, 03:52 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
  •