Topic 05: More Complex User Interfaces

2,012 views

Published on

Slides

Published in: Education
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,012
On SlideShare
0
From Embeds
0
Number of Embeds
1,110
Actions
Shares
0
Downloads
81
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Topic 05: More Complex User Interfaces

  1. 1. Topic 5 : More Complex User Interfaces DDOOCP
  2. 2. Swing Components (Classes) › javax.swing 1. JOptionPane 2. JFrame 3. JButton 4. JTextField 5. Jlabel 6. JPasswordField 7. JTextArea 8. JRadioButton 9. JCheckBox 10.JComboBox 11.JPanel 12.JScrollBar 13.JScrollPane 14.JSlider
  3. 3. JOptionPane.showMessageDialog
  4. 4. JOptionPane.showMessageDialog › Possible values for messageType are -1, 0, 1, 2, 3
  5. 5. Message Type arguments of showMessageDialog 1. JOptionPane.PLAIN_MESSAGE (no icon will be used) => -1 2. JOptionPane.ERROR_MESSAGE => 0 3. JOptionPane.INFORMATION_MESSAGE => 1 4. JOptionPane.WARNING_MESSAGE => 2 5. JOptionPane.QUESTION_MESSAGE => 3
  6. 6. JOptionPane.showMessageDialog
  7. 7. JOptionPane.showInputDialog
  8. 8. JOptionPane.showInputDialog › WAP to take 2 inputs from user and display the sum.
  9. 9. JOptionPane.showConfirmDialog
  10. 10. JFrame › Constructors – JFrame( ) – JFrame(String str) › Methods – Container getContentPane( ) – void setDefaultCloseOperation(int value) – void remove(Component cm) – void setLayout(LayoutManager manager) › Other inherited Methods – setSize( ) – setVisible( ) – setTitle( ) – setBackground( ) – add( )
  11. 11. JFrame
  12. 12. JButton › Constructors – JButton( ) – JButton(String str) › Methods – void setText(String str) – void setEnabled(boolean b) – String getText( ) – void addActionListener(ActionListener al)
  13. 13. JButton
  14. 14. Click event in JButton
  15. 15. JTextField › Constructors  JTextField( )  JTextField(String str) › Methods  void addActionListener(ActionListener al)  void removeActionListener(ActionListener al)  void setFont( ) • Inherited Methods void setText(String t) String getText( ) void setBackground(Color bg) void setForeground(Color fg) void setEditable(boolean b) void copy( ) void cut( ) void paste( )
  16. 16. JLabel › Constructors  JLabel( )  JLabel(str) › Methods  String getText( )  void setText(String str) • Inherited Methods void setVisible(boolean visible) void setEnabled(boolean enabled) void setBounds(int x, int y, int width, int height)
  17. 17. Develop the following application.
  18. 18. JTextArea › Constructors  JTextArea( )  JTextArea(String str) › Methods  void append(String text)  void insert(String text, int position)  void setFont(Font f) • Inherited Methods String getText( ) void setText(String text) void setVisible(boolean visible) void setEnabled(boolean enabled)
  19. 19. TextAreaDemo
  20. 20. JPasswordField › Constructors  JPasswordField( )  JPasswordField(String str) › Methods  void copy( )  void cut( )  String getText( )  char[ ] getPassword( ) String getText( ) method is Deprecated. • Inerited Methods void setVisible(boolean visible) void setEnabled(boolean enabled)
  21. 21. Login Logic
  22. 22. Login Form
  23. 23. Login Form
  24. 24. Login Form
  25. 25. JPanel › Constructors  JPanel( )  JPanel (LayoutManager layout) › Inherited Methods  void setVisible(boolean visible)  void setEnabled(boolean enabled)  void setBackground(Color bg)
  26. 26. JCheckBox › Constructors  JCheckBox( )  JCheckBox(String text)  JCheckBox(String text, boolean selected) › Inherited Methods  void addActionListener(ActionListener l)  void setText(String text)  void setVisible(boolean visible)  boolean isSelected()  void setSelected(boolean b)
  27. 27. JRadioButton › Constructors  JRadioButton( )  JRadioButton(String text)  JRadioButton(String text, boolean selected) › Inherited Methods  void addActionListener(ActionListener l)  void setText(String text)  void setVisible(boolean visible)  boolean isSelected()  void setSelected(boolean b)
  28. 28. JRadioButtonDemo
  29. 29. JComboBox › Constructors  JComboBox( )  JComboBox(Object [ ] items) › Methods  void addActionListener(ActionListener l)  void addItem(Object item)  void removeAllItems()  void removeItem(Object item)  void removeItemAt(int index)  void setSelectedItem(Object anObject)  void setSelectedIndex(int anIndex)  Object getSelectedItem()  int getSelectedIndex()
  30. 30. JComboBoxDemo
  31. 31. JComboBoxDemo
  32. 32. JComboBoxDemo
  33. 33. JSlider › Constructors  JSlider( )  JSlider(int orientation) JSlider.HORIZONTAL => 0 JSlider.VERTICAL => 1  JSlider(int min, int max)  JSlider(int min, int max, int value)  JSlider(int orientation, int min, int max, int value) › Methods  void addChangeListener (ChangeListener l)  int getValue( )  void setValue(int n)  void setPaintLabels(boolean b)  void setMajorTickSpacing(int n) Slider Demo
  34. 34. JSlider Important Code
  35. 35. Color Chooser
  36. 36. MeroSlider.java
  37. 37. ColorChooser.java
  38. 38. ColorChooser.java
  39. 39. JScrollPane › Constructor JScrollPane( ) JScrollPane(Component view) JScrollPane(Component view, int vertical, int horizontal) › Methods void setLayout(LayoutManager layout) Demo First
  40. 40. JScrollPane Example
  41. 41. Multiplication Table of 5
  42. 42. Layout Managers 1. GridLayout 2. NullLayout or Absolute Layout 3. FlowLayout 4. GridBagLayout 5. BorderLayout 6. BoxLayout
  43. 43. GridLayout › Constructors  GridLayout()  GridLayout(int rows, int columns)  GridLayout(int rows, int columns, int hgap, int vgap) › Methods – void setColumns(int cols) – void setRows(int rows) – void setHgap(int hgap) – void setVgap(int vgap)
  44. 44. GridLayout
  45. 45. FlowLayout › Constructors  FlowLayout()  FlowLayout(int align)  FlowLayout.LEFT => 0  FlowLayout.CENTER => 1  FlowLayout.RIGHT => 2  FlowLayout(int align, int hgap, int vgap) › Methods – void setAlignment(int align) – void setHgap(int hgap) – void setVgap(int vgap)
  46. 46. Fonts › public Font(String name, int style, int size) S.N. Modifier and Type Field 1 static final int BOLD 2 static final int ITALIC 3 String name 4 Int size
  47. 47. Events Event Type Listener Method ActionEvent ActionListener void actionPerformed(ActionEvent e) ChangeEvent ChangeListener void stateChanged(ChangeEvent e) MouseEvent MouseListener void mouseClicked(MouseEvent e) void mouseEntered(MouseEvent e) void mouseExited(MouseEvent e) void mousePressed(MouseEvent e) void mouseReleased(MouseEvent e)
  48. 48. Events Event Type Listener Method KeyEvent KeyListener void keyPressed(KeyEvent e) void keyReleased(KeyEvent e) void keyTyped(KeyEvent e) FocusEvent FocusListener void focusGained(FocusEvent e) void focusLost(FocusEvent e)
  49. 49. References › http://www.java2s.com/Tutorial/Java/0240__Swing/UsingJOptio nPanetoDisplayaMessage.htm › http://docs.oracle.com/javase/tutorial/uiswing/components/dial og.html › http://docs.oracle.com/javase/7/docs/api/javax/swing/JFrame. html › http://docs.oracle.com/javase/tutorial/uiswing/layout/visual.htm l › http://docs.oracle.com/javase/7/docs/api/java/awt/Font.html

×