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

Java Code:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Gui{
private JFrame f;
private JLabel hLabel;
private JLabel sLabel;
private JPanel panel;
public Gui(){
prepareGUI();
}
public static void main(String[] args){
Gui g = new Gui();
g.showButtonDemo();
}
private void prepareGUI(){
f= new JFrame("Gui");
f.setSize(500,500);
f.setLayout(new GridLayout(3, 1));
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent windowEvent){
System.exit(0);
}
});
hLabel = new JLabel("", JLabel.CENTER);
sLabel = new JLabel("",JLabel.CENTER);
sLabel.setSize(350,100);
panel = new JPanel();
panel.setLayout(new FlowLayout());
f.add(hLabel);
f.add(panel);
f.add(sLabel);
f.setVisible(true);
}
private void showButtonDemo(){
hLabel.setText("Welcome to Java Gui");
JButton bt = new JButton("Doggy");
bt.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
sLabel.setText("Bow Bow !!");
}
});
panel.add(bt);
f.setVisible(true);
}
}

if you like the answer please provide a thtumbs up


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