Asked by Praneeth Ganedi on Apr 27, 2024

verifed

Verified

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".

Button Functionality

Describes the actions or operations that are performed in a software application when a button is clicked or activated by the user.

GUI

Stands for Graphical User Interface, a visual way of interacting with computers and applications through elements like windows, icons, and buttons.

Modified First Window

Refers to the altered initial interface or window of an application from its default state, typically involving changes made by programming or user customization.

  • Exhibit competency in developing Java GUI applications that interact with user inputs.
verifed

Verified Answer

AJ
Adnan JawabriMay 02, 2024
Final Answer :
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 mainString args[])
{
final JFrame window = new JFrame);
window.setSizeWIDTH,HEIGHT);
JButton btnClick = new JButton"Click Me");
window.getContentPane).addbtnClick);
btnClick.addActionListenernew ActionListener)
{
public void actionPerformedActionEvent e)
{
window.setTitle"Modified First Window");
}
});
window.setTitle"First Window");
window.setDefaultCloseOperation JFrame.EXIT_ON_CLOSE );
window.setVisibletrue);
}
}