Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

GUI LAYOUT I need help with this please 1. Create two Java files with two different layouts of your choice. 2.. Do not use Flow

GUI LAYOUT

I need help with this please

1. Create two Java files with two different layouts of your choice.

2.. Do not use Flow layout and Box layout. You can use Flowlayout only as the default layout between the panels.

3. In your window use one panel with 4-6 buttons and another panel with 2 labels and one text area.

4. Use different colours for the components background and different colours for the text.

5. 2 java files with LayoutName.java It is not a separate assignment.

Example with box layout:

public class LayoutBox extends JFrame {

JFrame frame = new JFrame("Box Layout"); //creating frame

JPanel panel1 = new JPanel(); //creating panel 1

JButton btn1 = new JButton("1"); //creating button 1

JButton btn2 = new JButton("2"); //creating button 2

JButton btn3 = new JButton("3"); //creating button 3

JButton btn4 = new JButton("4"); //creating button 4

JButton btn5 = new JButton("5"); //creating button 5

JButton btn6 = new JButton("6"); //creating button 6

JPanel panel2 = new JPanel(); //creating panel 2

JLabel label1 = new JLabel("Hello!"); //creating label 1

JLabel label2 = new JLabel("Welcome to my program!"); //creating label 2

JTextArea textArea = new JTextArea (10,20); //creating text area

public LayoutBox(){

frame.setSize(500,500); //set size of frame

frame.setLayout(new FlowLayout()); //setting layout for frame

/* PANEL 1 */

panel1.setLayout(new BoxLayout(panel1, BoxLayout.X_AXIS)); //setting panel 1 layout to "x-axis"

panel1.setBackground(Color.YELLOW); //setting background of panel 1

btn1.setForeground(Color.GRAY); //setting text colour of button 1

panel1.add(btn1); //adding button 1 to the panel

btn2.setForeground(Color.BLUE); //setting text colour of button 2

panel1.add(btn2); //adding button 2 to the panel

btn3.setForeground(Color.MAGENTA); //setting text colour of button 3

panel1.add(btn3); //adding button 3 to the panel

btn4.setForeground(Color.PINK); //setting text colour of button 4

panel1.add(btn4); //adding button 4 to the panel

btn5.setForeground(Color.RED); //setting text colour of button 5

panel1.add(btn5); //adding button 5 to the panel

btn6.setForeground(Color.ORANGE); //setting text colour of button 6

panel1.add(btn6); //adding button 6 to the panel

frame.add(panel1); //adding panel 1 to frame

/* PANEL 2 */

panel2.setLayout(new BoxLayout(panel2, BoxLayout.Y_AXIS)); //setting panel 2 layout to "y-axis"

panel2.setBackground(Color.LIGHT_GRAY); //setting background colour for panel 2

label1.setForeground(Color.BLACK); //setting text colour for label 1

panel2.add(label1); //adding label 1 to the panel

label2.setForeground(Color.GREEN); //setting text colour for label 2

panel2.add(label2); //adding label 2 to the panel

panel2.add(textArea); //adding text area to the panel

frame.add(panel2); //adding panel 2 to frame

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //setting to exit frame when closed

frame.pack(); //leaves the layout manager in charge of frame size

frame.setVisible(true); //allows user to see frame and its components

}

public static void main(String[] args) {

new LayoutBox(); //calling constructor to run

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Programming questions

Question

What is a strategy map and how is it used?

Answered: 1 week ago

Question

What are your goals for this interview today?

Answered: 1 week ago