Question
Using Project modified in class perform the same 2 modifications on Show GridLayout Project Create a single class with a GridLayout and 10 buttons (added
- Using Project modified in class perform the same 2 modifications on Show GridLayout Project
- Create a single class with a GridLayout and 10 buttons (added the long way), breaking the individual component buttons out of the loop to add as individual "object-named" objects and add them individually by name to the frame's content Pane
- Break the single class into 2 classes: (1) with the default constructor for the frame and (2) with the main() method that creates an instance of the class in (1)
- In the default constructor, break the individual component buttons out of the loop to add as individual "object-named" objects and add them individually by name to the frame's content Pane
// ShowGridLayout.java: Demonstrate using GridLayout import javax.swing.JButton; import javax.swing.JFrame; import java.awt.GridLayout; import java.awt.Container;
public class ShowGridLayout extends JFrame { /** Default constructor */ public ShowGridLayout() { // Get the content pane of the frame Container container = getContentPane();
// Set GridLayout, 4 rows, 3 columns, and gaps 5 between // components horizontally and vertically container.setLayout(new GridLayout(4, 3, 5, 5));
// Add buttons to the frame for (int i = 1; i <= 10; i++) container.add(new JButton("Component " + i)); }
/** Main method */ public static void main(String[] args) { ShowGridLayout frame = new ShowGridLayout(); frame.setTitle("Show GridLayout"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(200, 200); frame.setVisible(true); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started