CS3135/CS2135
Object Oriented Programming (Java)
BSCS-3 / MCS-3
Lecture # 6
JFrame,
JScrollPane
JLabel
GUI Components  JFrame
javax.swing.JFrame
• JFrame()
• JFrame(String)
• void super()
• void super(String)
• void setLayout()
• void setTitle(String)
• String getTitle()
• void setLocation(int, int) // x, y
• void setSize(int, int) // width, height
• void setBounds(int, int, int, int) // x, y, width, height
• void setVisible(boolean)
• void getContentPane().setBackground(Color)
• void setUndecorated(boolean)
Instructor: Tanzila Kehkashan
2
• setIconImage(ImageIcon.getImage())
• setExtendedState(int) //state constant
• setCursor(Cursor)
• add(component)
• void setJMenuBar(JMenuBar)
• void setDefaultCloseOperation(int)
• int getDefaultCloseOperation()
Default Close Constants
• DO_NOTHING_ON_CLOSE
• HIDE_ON_CLOSE //Default for JDialog and JFrame
• DISPOSE_ON_CLOSE //removes window from screen and frees up any resources used by it
• EXIT_ON_CLOSE //Exits the application, using System.exit(0)
GUI Components  JFrame
Instructor: Tanzila Kehkashan
3
State constants
• NORMAL • ICONIFIED • MAXIMIZED_BOTH • MAXIMIZED_HORIZ
• MAXIMIZED_VERT
GUI Components  JFrame
Instructor: Tanzila Kehkashan
4
GUI Components  JFrame  Cursor
java.awt.Cursor
• Cursor(int) // Cursor constant
• Cursor getDefaultCursor()
• Cursor getPredefinedCursor(int) //cursor constant
Cursor Constant
• CROSSHAIR_CURSOR • DEFAULT_CURSOR • E_RESIZE_CURSOR
• HAND_CURSOR • MOVE_CURSOR • N_RESIZE_CURSOR
• NE_RESIZE_CURSOR • NW_RESIZE_CURSOR • S_RESIZE_CURSOR
• SE_RESIZE_CURSOR • SW_RESIZE_CURSOR • TEXT_CURSOR
• W_RESIZE_CURSOR • WAIT_CURSOR
Instructor: Tanzila Kehkashan
5
javax.swing.JScrollPane
• JScrollPane()
• JScrollPane(Component)
• void setHorizontalScrollBarPolicy(int) // method determines when horizontal scroll bar appears
• void setVerticalScrollBarPolicy(int) // method determines when vertical scroll bar appears
• void setHorizontalScrollBar(JScrollBar)
• void setVerticalScrollBar(JScrollBar)
Policies Constants
• HORIZONTAL_SCROLLBAR_ALWAYS
• HORIZONTAL_SCROLLBAR_AS_NEEDED //default
• HORIZONTAL_SCROLLBAR_NEVER
• VERTICAL_SCROLLBAR_ALWAYS
• VERTICAL_SCROLLBAR_AS_NEEDED //default
• VERTICAL_SCROLLBAR_NEVER
GUI Components  JFrame  JScrollPane
Instructor: Tanzila Kehkashan
6
Instructor: Tanzila Kehkashan
7
javax.swing.JLabel
• JLabel(ImageIcon)
• JLabel(ImageIcon, int)
• int specifies horizontal alignment of label’s contents
• LEFT, CENTER, RIGHT, LEADING, TRAILING.
• JLabel(String)
• JLabel(String, ImageIcon, int)
• JLabel(String, int)
• JLabel()
• void setText(String)
• String getText()
• void setIcon(ImageIcon)
• Icon getIcon()
• setToolTipText(String)
GUI Components  JFrame  JLabel
Instructor: Tanzila Kehkashan
8
• void setVisible(boolean)
• void setVerticalTextPosition(int)
• int getVerticalTextPosition()
• void setHorizontalTextPosition(int)
• int getHorizontalTextPosition()
Horizontal position constants
• LEFT
• CENTER
• RIGHT
Vertical position constants
• TOP
• CENTER
• BOTTOM
GUI Components  JFrame  JLabel
Instructor: Tanzila Kehkashan
9
Instructor: Tanzila Kehkashan
10
• Create your project’s interface:
• Splash screen
• Signup
• Sign in
• Main screen
• Levels
• Help
• Create package of your project
ASSIGNMENT
Instructor: Tanzila Kehkashan
11
Instructor: Tanzila Kehkashan
12

OOP Lecture 6-JFrame,JScrollPane,JLabel.pptx

  • 1.
    CS3135/CS2135 Object Oriented Programming(Java) BSCS-3 / MCS-3 Lecture # 6 JFrame, JScrollPane JLabel
  • 2.
    GUI Components JFrame javax.swing.JFrame • JFrame() • JFrame(String) • void super() • void super(String) • void setLayout() • void setTitle(String) • String getTitle() • void setLocation(int, int) // x, y • void setSize(int, int) // width, height • void setBounds(int, int, int, int) // x, y, width, height • void setVisible(boolean) • void getContentPane().setBackground(Color) • void setUndecorated(boolean) Instructor: Tanzila Kehkashan 2
  • 3.
    • setIconImage(ImageIcon.getImage()) • setExtendedState(int)//state constant • setCursor(Cursor) • add(component) • void setJMenuBar(JMenuBar) • void setDefaultCloseOperation(int) • int getDefaultCloseOperation() Default Close Constants • DO_NOTHING_ON_CLOSE • HIDE_ON_CLOSE //Default for JDialog and JFrame • DISPOSE_ON_CLOSE //removes window from screen and frees up any resources used by it • EXIT_ON_CLOSE //Exits the application, using System.exit(0) GUI Components  JFrame Instructor: Tanzila Kehkashan 3
  • 4.
    State constants • NORMAL• ICONIFIED • MAXIMIZED_BOTH • MAXIMIZED_HORIZ • MAXIMIZED_VERT GUI Components  JFrame Instructor: Tanzila Kehkashan 4
  • 5.
    GUI Components JFrame  Cursor java.awt.Cursor • Cursor(int) // Cursor constant • Cursor getDefaultCursor() • Cursor getPredefinedCursor(int) //cursor constant Cursor Constant • CROSSHAIR_CURSOR • DEFAULT_CURSOR • E_RESIZE_CURSOR • HAND_CURSOR • MOVE_CURSOR • N_RESIZE_CURSOR • NE_RESIZE_CURSOR • NW_RESIZE_CURSOR • S_RESIZE_CURSOR • SE_RESIZE_CURSOR • SW_RESIZE_CURSOR • TEXT_CURSOR • W_RESIZE_CURSOR • WAIT_CURSOR Instructor: Tanzila Kehkashan 5
  • 6.
    javax.swing.JScrollPane • JScrollPane() • JScrollPane(Component) •void setHorizontalScrollBarPolicy(int) // method determines when horizontal scroll bar appears • void setVerticalScrollBarPolicy(int) // method determines when vertical scroll bar appears • void setHorizontalScrollBar(JScrollBar) • void setVerticalScrollBar(JScrollBar) Policies Constants • HORIZONTAL_SCROLLBAR_ALWAYS • HORIZONTAL_SCROLLBAR_AS_NEEDED //default • HORIZONTAL_SCROLLBAR_NEVER • VERTICAL_SCROLLBAR_ALWAYS • VERTICAL_SCROLLBAR_AS_NEEDED //default • VERTICAL_SCROLLBAR_NEVER GUI Components  JFrame  JScrollPane Instructor: Tanzila Kehkashan 6
  • 7.
  • 8.
    javax.swing.JLabel • JLabel(ImageIcon) • JLabel(ImageIcon,int) • int specifies horizontal alignment of label’s contents • LEFT, CENTER, RIGHT, LEADING, TRAILING. • JLabel(String) • JLabel(String, ImageIcon, int) • JLabel(String, int) • JLabel() • void setText(String) • String getText() • void setIcon(ImageIcon) • Icon getIcon() • setToolTipText(String) GUI Components  JFrame  JLabel Instructor: Tanzila Kehkashan 8
  • 9.
    • void setVisible(boolean) •void setVerticalTextPosition(int) • int getVerticalTextPosition() • void setHorizontalTextPosition(int) • int getHorizontalTextPosition() Horizontal position constants • LEFT • CENTER • RIGHT Vertical position constants • TOP • CENTER • BOTTOM GUI Components  JFrame  JLabel Instructor: Tanzila Kehkashan 9
  • 10.
  • 11.
    • Create yourproject’s interface: • Splash screen • Signup • Sign in • Main screen • Levels • Help • Create package of your project ASSIGNMENT Instructor: Tanzila Kehkashan 11
  • 12.