Add button functionality to the resulting GUI of number 2 above. When the button is clicked, the title of the window changes to “Modified First Window”.
What will be an ideal response?
Additional code for button functionality appears below in bold text.
```
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class FirstGui
{
public static final int WIDTH = 300;
public static final int HEIGHT = 300;
public static void main(String args[])
{
final JFrame window = new JFrame();
window.setSize(WIDTH, HEIGHT);
JButton btnClick = new JButton("Click Me");
window.getContentPane().add(btnClick);
btnClick.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
window.setTitle("Modified First Window");
}
});
window.setTitle("First Window");
window.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
window.setVisible(true);
}
}
```
You might also like to view...
All of the following are advantages of using named constants except
a. they can be used in the place of keywords. b. it is easier to make a consistent change throughout a program. c. they help make the program more self documenting. d. they’re useful for common values such as pi.
The C# language provides a set of operators known as ____________, which you can use to create complex Boolean expressions.
a. Boolean operators
b. relational operators
c. logical operators
d. expressional operators
The ____ Tool moves a path segment or individual anchor points.
A. Pen B. Direct Selection C. Path Selection D. Freeform Pen
Which of these is primarily an ergonomic device?
A. adjustable chair B. footrest C. document holder D. all of these