Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

From the following Java code change this to an application that uses \"BorderLay

ID: 3545324 • Letter: F

Question

From the following Java code change this to an application that uses "BorderLayout" and then place each button in the appropiate area (either NORTH, SOUTH, WEST, EAST, OR CENTER).

The final application should have a button in each of the five areas.

import javax.swing.JOptionPane;

import java.awt.*;

import java.awt.event.*;

public class Layout extends Frame

{

           Button northButton = new Button("First");

           Button southButton = new Button("Second");

           Button eastButton = new Button("Third");

           Button westButton = new Button ("Fourth");

           Button centerButton = new Button ("Fifth");

           public Layout ()

           {

                     this.setLayout (new FlowLayout ());

                     add(northButton);

                     add(southButton);

                     add(eastButton);

                     add(westButton);

                     add(centerButton);

} // end of constructor method

public static void main(String[] args)

{

                     Layout f = new Layout ();

                     f.setBounds(200,200,300,300);

                     f.setTitle("Flow Layout");

                     f.setVisible(true);

} //end of main

} //end of class

Explanation / Answer

import javax.swing.*;


import java.awt.*;


import java.awt.event.*;



class Layout extends JFrame


{


JButton northButton = new JButton("First");


JButton southButton = new JButton("Second");


JButton eastButton = new JButton("Third");


JButton westButton = new JButton ("Fourth");


JButton centerButton = new JButton ("Fifth");


public Layout ()


{


this.setLayout (new BorderLayout ());


this.add(northButton,BorderLayout.NORTH);


this.add(southButton,BorderLayout.SOUTH);


this.add(eastButton,BorderLayout.EAST);


this.add(westButton,BorderLayout.WEST);


this.add(centerButton,BorderLayout.CENTER);


} // end of constructor method


public static void main(String[] args)


{


Layout f = new Layout ();


f.setSize(400,400);


f.setTitle("Flow Layout");


f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


f.setVisible(true);


} //end of main


} //end of class

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote