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

Using the FlowLayout manager) Write a program that meets the following requireme

ID: 3646840 • Letter: U

Question

Using the FlowLayout manager) Write a program that meets the following requirements (see Figure 12.14):
? CreateaframeandsetitslayouttoFlowLayout.?? Createtwopanelsandaddthemtotheframe.?? Eachpanelcontainsthreebuttons.ThepanelusesFlowLayout.
Using JPanel to group buttons) Rewrite the preceding program to create the same user interface. Instead of creating buttons and panels separately, define a class that extends the JPanel class. Place three buttons in your panel class, and create two panels from the user-defined panel class.
FIGURE 12.14 Exercise 12.1 places the first three buttons in one panel and the other three buttons in another panel.
??

Explanation / Answer

import java.awt.FlowLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; public class Lab5_13_1 extends JFrame { private JPanel p1 = new JPanel(); private JPanel p2 = new JPanel(); public static void main(String[] args) { // frame Lab5_13_1 j = new Lab5_13_1(); j.setLayout(new FlowLayout()); j.setLocationRelativeTo(null); j.setTitle("Lab5_13_1"); j.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public Lab5_13_1() { // panel #1 p1.setLayout(new FlowLayout()); // panel #2 p2.setLayout(new FlowLayout()); // add buttons to panel #1 p1.add(new JButton("Button 1")); p1.add(new JButton("Button 2")); p1.add(new JButton("Button 3")); // add buttons to panel #2 p2.add(new JButton("Button 4")); p2.add(new JButton("Button 5")); p2.add(new JButton("Button 6")); // add panels to frame add(p1); add(p2); setSize(650,90); setVisible(true); } }

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