Write a program whose source file is named UnitProgljava tha

Write a program whose source file is named \"UnitProgl.java\" that does the following: Creates a frame with a GridLayout Manager Creates two panels and adds them to the frame, stacked one over the other. In each panel creates three buttons, side by side. The buttons should be labeled \"Button 1\", \"Button 2\", \"Button 3\", \"Button 4\", \"Button 5\" and \"Button 6\". Displays this GUI when run. The only buttons that actually works will be the buttons on the window title bar: minimize, maximize and the exit button in the upper right hand corner of the programs window. Part 2 - Event Driven Programming Write a program whose source file is named \"UnitProg2.java\". Do the following: Start by copying the program code from part 1 and modifying it. This program will have a GUI that looks just like the previous one. The goal is to make the JButtons work. Add code to handle the events when the user presses any of the six buttons on the GUI. When the user presses a button simply write out to the console \"The user pressed Button X\", where \"X\" is the number of the button. For example, when \"Button 2\" is pressed the message written to the console should be \"The user pressed Button 2.\".

Solution

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
class JButton extends JFrame
{
JButton button1,button2,button3,button4,button5
public JButton()
{
setTitle(\"Buttons \");
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLayout(new GridLayout());
setOpacity(0.7f);
button1=new JButton(\"To Maximize/Restore\");
button1.addActionListener(new ActionListener(){
   public void actionPerformed(ActionEvent ae)
   {
    if(getExtendedState()==NORMAL)
    setExtendedState(MAXIMIZED_BOTH);
    else
    setExtendedState(NORMAL);
   }
});
button2=new JButton(\"TO Minimize\");
button2.addActionListener(new ActionListener(){
   public void actionPerformed(ActionEvent ae)
   {
    setState(ICONIFIED);
   }
});
button3=new JButton(\"To Close\");
button3.addActionListener(new ActionListener(){
   public void actionPerformed(ActionEvent ae)
   {
   dispose();
   }
});

button4=new JButton();

button5=new JButton();
// add buttons to frame
add(button1);
add(button2);
add(button3);

add(button4);

addbutton(5);
pack();
}
public static void main(String args[])
{
new JButton();
}

 Write a program whose source file is named \
 Write a program whose source file is named \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site