Learning Activity: Layout Managers Objectives Gain familiarity with layout manag
ID: 3881373 • Letter: L
Question
Learning Activity: Layout Managers
Objectives
Gain familiarity with layout managers.
Instructions
All of these exercises for the lab are based on the Layout.java class. The lab exercise is broken into a series of different portions or "cases". Each case consists as a set of method calls for a Layout instance; they are given as an application method. You can either add an application method to the Layout class, or make these method calls interactively within your chosen IDE. I have also provided a class which runs each case depending on the command-line argument. In each case, you need to answer the questions posed for that case. Note: the cases are independent. You will submit the answers for the questions in a text file. We will discuss the "Challenge Questions" in class next week.
Case 1
Consider the following application method for Layout.
public static void main(String[] args)
{
Layout theApp = new Layout();
}
Answer the following questions:
How many JButton instances exist in the application?
How many JButton instances are shown?
What happens as the user resizes the window?
Case 2
Consider the following application method for Layout.
public static void main(String[] args)
{
Layout theApp = new Layout();
theApp.useFlowLayout();
}
Answer the following questions:
What does the window look like? (Refer to images page at the bottom.)
Are the buttons all the same size?
What determines the size of the buttons?
What happens as the user resizes the window, making it considerably narrower? Wider?
Case 3
Consider the following application method for Layout.
public static void main(String[] args)
{
Layout theApp = new Layout();
theApp.useFlowLayout();
theApp.pack();
}
Answer the following questions:
What does the window look like? (Refer to images page at the bottom.)
What does the pack method do?
Case 4
Consider the following application method for Layout.
public static void main(String[] args)
{
Layout theApp = new Layout();
theApp.useGridLayout();
}
Answer the following questions:
What does the window look like? (Refer to images page at the bottom.)
What determines the size of the buttons?
What happens as the user resizes the window?
Case 5
Consider the following application method for Layout.
public static void main(String[] args)
{
Layout theApp = new Layout();
theApp.useBorderLayout();
}
Answer the following questions:
What does the window look like? (Refer to images page at the bottom.)
What happens as the user resizes the window?
What determines the size of the buttons?
Hint: What happens if you add the call theApp.pack() to the end of main?
Case 6
Consider the following application method for Layout.
public static void main(String[] args)
{
Layout theApp = new Layout();
theApp.useToolbar();
}
Answer the following questions:
What does the window look like? (Refer to images page at the bottom.)
When the window first appears, how many are visible? Explain.
Hint: What happens if the user resizes the window?
Case 7
Consider the following application method for Layout.
public static void main(String[] args)
{
Layout theApp = new Layout();
theApp.useToolbarII();
}
Answer the following questions:
What does the window look like? (Refer to images page at the bottom.)
Why is "Ernie ..." now visible?
Hint: Read the documentation for setPreferredSize. This method is inherited from JComponent.
Case 8
Consider the following application method for Layout.
public static void main(String[] args)
{
Layout theApp = new Layout();
theApp.useCustomLayout();
}
Answer the following questions:
What does the window look like? (Refer to images page at the bottom.)
What happens as the user resizes the window?
What happens when c.validate() is called at the end of the useCustomLayout method?
Case 9
Consider the following application method for Layout.
public static void main(String[] args)
{
Layout theApp = new Layout();
theApp.useBoxLayout();
}
Answer the following questions:
What does the window look like? (Refer to images page at the bottom.)
What happens as the user resizes the window?
Briefly describe the difference between BoxLayout (case 9) and FlowLayout (case 6) for the toolbar.
Hint: The javax.swing.Box class provides an easy way to use javax.swing.BoxLayout. For more information, see the API documentation for these two classes.
"Can you figure it out?" Questions
These cases are for discussion. Understanding the "odd" behavior presented by these cases will help develop a good understanding of the way layout managers work. So, these cases are not part of the learning activity, per se.
Case 10
Consider the following alternate application methods for Layout.
public static void main(String[] args)
{
Layout theApp = new Layout();
theApp.useToolbarII();
theApp.useGridLayout();
}
public static void main(String[] args)
{
Layout theApp = new Layout();
theApp.useToolbarII();
theApp.useFlowLayout();
}
Answer the following questions:
What do the windows look like?
The arrangement of buttons is different due to the call to useToolbarII. Explain.
Hint: What happens if a call to resetToolbar is added to either of these application methods?
Case 11
Consider the following application method for Layout.
public static void main(String[] args)
{
Layout theApp = new Layout();
theApp.useGridLayout();
theApp.useBorderLayout();
}
Answer the following questions:
What does the window look like?
What happens as the user resizes the window?
Briefly explain the behavior of "Charlie".
Case 12
Consider the following application method for Layout.
public static void main(String[] args)
{
Layout theApp = new Layout();
theApp.useBorderLayout();
theApp.showAButton();
}
Answer the following questions:
What buttons appear?
What happens as the user moves the mouse over the window?
What happens if the user resizes the window?
Briefly explain this behavior.
Explanation / Answer
The diagram which is said to be attached is missing.So the discussion is done only considering the functions that are used in general and not the diagram.
Case 2:
The FlowLayout class provides a very simple layout manager that is used, by the JPanel objects.
Q)What does the window look like?
A)The window comprises of 5 jbuttons.
Q) Are the buttons all the same size?
A)yes
Q)What determines the size of the buttons?
A)A FlowLayout constructor takes an alignment argument to re size the buttons.
Q)What happens as the user resizes the window, making it considerably narrower? Wider?
A)The size of button adjusts accordingly to the window.
Case 3:
Q)What does the window look like?
A)Window has buttons of equal size
Q) What does the pack method do?
A)The pack method sizes the frame so that all its contents are at their preferred sizes.
Case 4:
Q)What determines the size of the buttons?
A)Each component takes all the available space within its cell, and each cell is exactly the same size.
Q)What happens as the user resizes the window?
A) If the window is resized, the cell size chanes so that the cells are as large as possible
Case 5:
Q)What happens as the user resizes the window?
A)If the window is enlarged, the center area gets max available. The other areas expand only as necessary to fill all available space.
Q)What determines the size of the buttons?
A)The area in which the button is placed.
Case 6:
Q)When the window first appears, how many are visible? Explain.
A)ToolBar groups several components ,usually buttons with icons into a row or column.
Three buttons are available.one pointing to precious,up and other to next
Case 8:
Q)What happens as the user resizes the window?
A)The layout sizes are also resized accordinly
Q)What happens when c.validate() is called at the end of the useCustomLayout method?
A)It clears the cached values of layout that are discarded.
Case 9:
Q)What happens as the user resizes the window?
A)No change.
Case 12:
Q)What buttons appear?
A)Radio,check buttons and jbuttons
Q)What happens as the user moves the mouse over the window?
A)the buttons may get checked or selected if the mouse is clicked over them.
Q)What happens if the user resizes the window?
A)size adjusts accodingly
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.