Question

In: Computer Science

Write Java code which will create a GUI window on screen. The window has one button:...

Write Java code which will create a GUI window on screen. The window has one button: Doggy. When the user selects Doggy, “Bow Bow” should be printed on screen. Justify your syntax.  

Solutions

Expert Solution

Code


import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;

public class Doggy {
public static void main(String[] args) {
JFrame f=new JFrame();//creating instance of JFrame
JButton btnDoggy=new JButton("Doggy");//creates the JButton
JLabel lblText=new JLabel();//creates the JLabel
btnDoggy.setBounds(100, 30,110 , 30);//set postion of the button
lblText.setBounds(120, 90,110 , 30);//set postion label
lblText.setFont(new Font("Serif", Font.BOLD, 20));//set font style and font size of the label
//button click event
btnDoggy.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
lblText.setText("Bow Bow");
}
});
//add button and lable to frame
f.add(btnDoggy);
f.add(lblText);
//set size of the frame
f.setSize(350,200);//350 width and 200 height
f.setLayout(null);//using no layout managers
f.setTitle("Doggy");
f.setVisible(true);//making the frame visible
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
  
}

output

If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.


Related Solutions

Write Java code which will create a GUI window on screen. The window has one button:...
Write Java code which will create a GUI window on screen. The window has one button: Doggy. When the user selects Doggy, “Bow Bow” should be printed on screen. Justify your syntax.
Write Java code which will create a GUI window on screen. The window has one button:...
Write Java code which will create a GUI window on screen. The window has one button: Doggy. When the user selects Doggy, “Bow Bow” should be printed on screen. Justify your syntax.
Write Java code which will create a GUI window on screen. The window has one button:...
Write Java code which will create a GUI window on screen. The window has one button: Doggy. When the user selects Doggy, “Bow Bow” should be printed on screen. Justify your syntax.
Write Java code which will create a GUI window on screen. The window has one button:...
Write Java code which will create a GUI window on screen. The window has one button: Doggy. When the user selects Doggy, “Bow Bow” should be printed on screen. Justify your syntax.
Write Java code which will create a GUI window on screen. The window has one button:...
Write Java code which will create a GUI window on screen. The window has one button: Doggy. When the user selects Doggy, “Bow Bow” should be printed on screen. Justify your syntax.
Write Java code which will create a GUI window on screen. The window has one button:...
Write Java code which will create a GUI window on screen. The window has one button: Doggy. When the user selects Doggy, “Bow Bow” should be printed on screen. Justify your syntax.
Write Java code which will create a GUI window on screen. The window has one button:...
Write Java code which will create a GUI window on screen. The window has one button: Doggy. When the user selects Doggy, “Bow Bow” should be printed on screen. Justify your syntax.
Write Java code which will create a GUI window on screen. The window has one button:...
Write Java code which will create a GUI window on screen. The window has one button: Doggy. When the user selects Doggy, “Bow Bow” should be printed on screen. Justify your syntax.  
Write Java code which will create a GUI window on screen. The window has one button:...
Write Java code which will create a GUI window on screen. The window has one button: Doggy. When the user selects Doggy, “Bow Bow” should be printed on screen. Justify your syntax. ASAP
Write Java code which will create a GUI window on screen. The window has one button:...
Write Java code which will create a GUI window on screen. The window has one button: Doggy. When the user selects Doggy, “Bow Bow” should be printed on screen. Justify your syntax.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT