80 likes | 186 Views
Advanced OOP MCS-3 OOP BSCS-3 Lecture # 9. TOPICS TO COVER. Ways of Arranging Components in GUI Uses Container class setLayout () method from java.awt package Visual Programming in an IDE Provides GUI design tool. Supports drag and drop. Absolute Positioning
E N D
TOPICS TO COVER Ways of Arranging Components in GUI • Uses Container class setLayout() method from java.awt package • Visual Programming in an IDE • Provides GUI design tool. • Supports drag and drop. • Absolute Positioning • Provides greatest level of control by setting setLayoutmethod to null. But it can be tedious to set absolute positioning. • Methods like setSize, setLocation, andsetBoundsare used. • Layout Managers • FlowLayout • BorderLayout • GridLayout
TOPICS TO COVER FlowLayout class (java.awt.FlowLayout) • Default for javax.swing.JPanel • Components are placed from left to right in order they are added. • Automatically places components onto next row, if row is full. • FlowLayout() • FlowLayout(int) // alignment Row positioning options • FlowLayout.LEFT • FlowLayout.RIGHT • FlowLayout.CENTER (default) • void setAlignment(int) // alignment • intgetAlignment()
TOPICS TO COVER BorderLayout class (java.awt.BorderLayout) • Default for javax.swing.JFrame • Arranges components in five regions • Places upto five components in a container one in each region. • Automatically displaces previous component, if component is already occupied in the position. • BorderLayout() • BorderLayout(int, int) // horizontal gap, vertical gap Regions • BorderLayout.NORTH • BorderLayout.SOUTH • BorderLayout.EAST • BorderLayout.WEST • BorderLayout.CENTER
TOPICS TO COVER GridLayout class (java.awt.GridLayout) • Divides container into a grid so that components can be placed in rows and columns. • Each component has same width and height. • GridLayout() • GridLayout(int, int) // rows, columns • GridLayout(int, int, int, int) // rows, columns, horizontal gap, vertical gap • intgetColumns() • intgetHgap() • intgetRows() • intgetVgap() • void setColumns(intcols) • void setHgap(inthgap) • void setRows(introws) • void setVgap(intvgap)
Color java.awt.Color • Color.BLACK • Color.BLUE • Color.CYAN • Color.DARK_GRAY • Color.GRAY • Color.GREEN • Color.LIGHT_GRAY • Color.MAGENTA • Color.ORANGE • Color.PINK • Color.RED • Color.WHITE • Color.YELLOW
Color Color • Color(int, int, int) // red, green, blue ranging from 0 to 255 • Color brighter() • Color darker() • intgetRed() • intgetGreen() • intgetBlue() JColorChooser class in javax.swing.JColorChooser • Color showDialog(Component, String, Color) //component, title of dialogbox, initial color