I am in the process of completing a course work but I need some help understanding this:
"Note: Your application should keep the relative positioning of buttons and checkboxes when the frame of the application is resized based on the layout managers and the tech- niques covered in the module. I.e. you should not choose absolute coordinates when placing JComponents on the screen but relative positioning, i.e. component X is to the right of component Y and to the left of component Z and these relative locations should be maintained if the user resizes the frame of the application."
Does this mean im not to use BoxLayout.X/Y_AXIS? Absolute coordinates?
To my understanding I have to use several panels? If so, my code contains a login and when I login how will I change the colour of the frame?
There's basically two ways to layout the components in a JFC/Swing application:
What the layout manager in effect does is assign each JComponent an absolute position derived from the layout the component is layed out by at runtime, dynamically - usually using the PreferredSize of the JComponents; for example, a FlowLayout will assign each JComponent an absolute position that will put it exactly fitting to the right of the JComponent before it, wrapping lines when needed. When a container is resized, all components within it will have their positions recomputed. See here for details.
Concerning your question about BoxLayout, that is a layout manager; BoxLayout.X_AXIS and BoxLayout.Y_AXIS are used to determine in which direction the JComponents which the BoxLayout manages are to be arranged; they do not refer to absolute positioning. See the Javadocs on BoxLayout and the Java tutorial on BoxLayout for details.
All in all, your task is to use a layout manager; the different layout managers that are available in the standard java libraries are described in sufficient detail in the tutorials (see links, browse the sites). Have fun!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With