1. 2. 3. 4. 5. When creating graphics inside a JFrame, the program continues to
ID: 3902481 • Letter: 1
Question
1.
2.
3.
4.
5.
When creating graphics inside a JFrame, the program continues to run once the JFrame has been instantiated. How can the program be set to terminate upon closing the Frame? Select one 0 a. The Java system automatically detects the closing of a JFrame and will terminate the program in response O b. Invoke the setDefaultCloseOperation) method with the parameter JFrame.EXIT_ON CLOSE O c. Invoke the JFrame.close) method from the main0 method O d. Invoke the setVisible) method with the parameter value falseExplanation / Answer
1. The default behaviour when we are pressing close button in JFrame is equivalent to
someFrame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); so we need to add some lines to close it manually by writing the following lines of code :
someFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
We can also declare EXIT_ON_CLOSE constant in some java file too. So the option (b) is correct is choice.
2. Action Listener is an interface in java that contains single method actionPerformed() which takes ActionEvent as a parameter. We can also say that it's simple interface with only one method. It is available in the package java.awt.event.package.The method actionPerformed is automatically invoked while clicking on registered component.hence option (c) is correct choice for this.
3. If the parameter is of type component then it must be relative to component. Hence option (c) is correct. As if we're using any component then it automatically centers the dialog on the top of JFrame.The parent component in the showOpenDialog() method will affect the position of dialog.In our case parent is of type component so it must be relative to that component, if parent component is in frame then dialog will be dependent on that frame.
4. Event is changes in state of an object,like clicking a button.Thus, Option (a) is not correct as each event in java is an object which are being created when something happens or changes in GUI like click,hover,drag etc. For example if a JButton is clicked by user in java then click event is performed which only performs uniquue action that is being supported by that Event only. Some types of events are ActionEvent, ContainerEvent, KeyEvent etc.
* We are required to do four parts.
*If you have any problem with the answer or want me to edit the answer just let me know in the comments and i will try to get on it as soon as possible. Do give a plus if this answer helps.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.