Answered You can hire a professional tutor to get the answer.

QUESTION

More Java Graphics - Layouts What will you learn How to organize graphical elements on a Panel Recommended reading From the Java textbook, Sams...

Before you start Lab 5, Layouts, take a look at the code below. Play with is, for instance,

  • commenting the setLayout() lines and checking the result
  • change background colors
  • experiment with other layouts
  • add a couple of buttons to some of the panels
  • make some changes myJPanel12 (p12)

public class app

{

    public static void main(String args[])

{

myJFrame mjf = new myJFrame();

}

}

import java.awt.*;

import javax.swing.*;

{

myJPanel p1;

public myJFrame ()

{

super ("My First Frame");

//------------------------------------------------

// Create components

p1 = new myJPanel();

//------------------------------------------------

// Choose a Layout for JFrame and

// add Jpanel to JFrame according to layout

getContentPane().setLayout(new BorderLayout());

getContentPane().add(p1,"Center");

//-----------------------------------------------

setDefaultCloseOperation(EXIT_ON_CLOSE);

setSize (640, 480);

setVisible(true);

}

}

import java.awt.*;

import javax.swing.*;

public class myJPanel1 extends JPanel

{

myJPanel11 p11;

myJPanel12 p12;

public myJPanel1()

{

setBackground(Color.pink);

p11 = new myJPanel11();

p12 = new myJPanel12();

setLayout(new GridLayout(1,2));

add(p11);

add(p12);

}

}

import java.awt.*;

import javax.swing.*;

public class myJPanel11 extends JPanel

{

myJPanel111 p111;

myJPanel112 p112;

myJPanel113 p113;

public myJPanel11()

{

setBackground(Color.green);

p111 = new myJPanel111();

p112 = new myJPanel112();

p113 = new myJPanel113();

//-----------------------------------------------

// Choose a Layout for JPanel1 and

// add components to Jpanel according to layout

setLayout(new GridLayout(3,1));

add(p111);

add(p112);

add(p113);

}

}

import java.awt.*;

import javax.swing.*;

public class myJPanel12 extends JPanel

{

public myJPanel12()

{

setBackground(Color.yellow);

}

}

import java.awt.*;

import javax.swing.*;

public class myJPanel111 extends JPanel

{

public myJPanel111()

{

setBackground(Color.orange);

}

}

import java.awt.*;

import javax.swing.*;

public class myJPanel112 extends JPanel

{

public myJPanel112()

{

setBackground(Color.red);

}

}

import java.awt.*;

import javax.swing.*;

public class myJPanel113 extends JPanel

{

public myJPanel113()

{

setBackground(Color.pink);

}

}

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question