LAB SESSION 9 - PowerPoint PPT Presentation

1 / 20
About This Presentation
Title:

LAB SESSION 9

Description:

The model of the Nordic Investment Bank. Siv Hell n. Adviser ... Founded in 1975 by the five ... Paternity leave intially granted for 1-18 working days ... – PowerPoint PPT presentation

Number of Views:51
Avg rating:3.0/5.0
Slides: 21
Provided by: nor71
Category:
Tags: lab | session | intially

less

Transcript and Presenter's Notes

Title: LAB SESSION 9


1
LAB SESSION 9
  • COMPONENTS IN JAPPLET
  • SETBOUNDS METHOD
  • DIRECTION OF INPUT TO STDIN

2
  • JAPPLET IS A SUB CLASS OF APPLET
  • Components in JAPPLET AND APPLET
  • JApplet Applet
  • JButton Button
  • JTextField TextField
  • JCheckbox Checkbox
  • JRadioButton RadioButton
  • JComboBox Choice control
  • ListBox
  • ScrollBars
  • TextArea

3
JLABEL
  • JLabel(String str,int align)
  • Str is a message displayed on label
  • Align indicates the message should be aligned in
    center,left or right
  • There are two methods to set the text and get the
    text on the Jlabel
  • String getText()
  • Void setText()

4
  • Public applet1 extends JApplet
  • Public void init()
  • Container cpanegetContentPane()
  • Cpane.setLayout(null)
  • JLabel llnew JButton(String str)
  • ll.setBounds(10,10,50,50)
  • Cpane.add(ll)

5
JTextField
  • JTextField(String str,int cols)
  • JTextField(int cols)
  • Here str is string that is intially to be
    displayed in the textBox when applet is loaded
  • cols-no of cols in textBox(width of the
    textBox)

6
  • Public applet1 extends JApplet
  • Public void init()
  • Container cpanegetContentPane()
  • Cpane.setLayout(null)
  • JTextField ttnew JButton(String str)
  • tt.setBounds(10,10,50,50)
  • Cpane.add(tt)

7
JButton
  • JButton(String str)
  • Str is a message displayed on button
  • There are two methods to set the text and get the
    text on the Jlabel
  • String getText()
  • Void setText()

8
  • Public applet1 extends JApplet
  • Public void init()
  • Container cpanegetContentPane()
  • Cpane.setLayout(null)
  • JButton jbnew JButton(String str)
  • Cpane.add(jb)
  • Jb.setForeground(Color.BLUE)

9
JCheckBox
  • JCheckBox(String s,boolean state)
  • Str is a message displayed on checkbox.
  • state is set to True or False indicates
    whether the textbox should be selected or not
  • The state of the textbox can be changed via
  • this method
  • Void setSelected(boolean state)
  • void getSelected() //get selected items

10
  • Public applet1 extends JApplet
  • Public void init()
  • Container cpanegetContentPane()
  • Cpane.setLayout(null)
  • JCheckBox cbnew JButton(String str)
  • Cb.setBounds(10,10,45,70)
  • Cpane.add(cb)

11
JRadioButton
  • JRadioButton(String s,boolean state)
  • Str is a message displayed on Radiobutton
  • State indicates whether it is selected or not
  • The state of the textbox can be changed via
  • this method
  • Void setSelected(boolean state)
  • void getSelected() //get selected items

12
  • Public applet1 extends JApplet
  • Public void init()
  • Container cpanegetContentPane()
  • Cpane.setLayout(null)
  • RadioButtonGroup jpgnew RadioButtonGroup()
  • JRadioButton bbnew JButton(String str)
  • JRadioButton bb1new JButton(String str)
  • bb.setBounds(10,10,50,50)
  • bb1.setBounds(10,10,50,50)
  • Jbg.add(bb)
  • Jbg.add(bb1)
  • Cpane.add(bb)

13
COMBOBOX(Dropdown list)
  • JComboBox()
  • JComboBox(vector v)
  • Its a dropdown list containing items that can be
    selected
  • We can add items by using this method
  • Void additem(Object ob)

14
  • Public applet1 extends JApplet
  • Public void init()
  • Container cpanegetContentPane()
  • Cpane.setLayout(null)
  • JComboBox jcbnew JButton(String str)
  • Cpane.add(jcb)
  • Jcb.add(france)
  • Jcb.add(England)

15
LISTS
  • LIST(int cols,int multipleselect)
  • it list a list of items that can be selected
  • cols indicates the length the list
  • how many can be listed
  • multiselect indicates 0/1
  • 0-only one can be selected at a time
  • 1 user can select 2 or more items
  • Methods used to add items are
  • Void add(String name)
  • Void add(String str,int index)

16
  • There are two more methods to get selcted item
    name or index
  • String getSelectedItem()
  • int getSelectedIndex()
  • IF MULTISELECT IS 1 THEN
  • String getSelectedItems()
  • int getSelectedIndexes()
  • Void select(int index)
  • Int itemCount()

17
  • Public applet1 extends JApplet
  • Public void init()
  • Container cpanegetContentPane()
  • Cpane.setLayout(null)
  • ListBox lbnew ListBox(5,0)
  • Cpane.add(lb)
  • Jcb.additem(france,4)
  • Jcb.additem(England)

18
SETBOUNDS METHOD
  • This method is used to set the Size and shape of
    all awt components
  • This method works when we set the layout to null
    and we want to add the components manually
  • Void setBounds(int x1,int y1,int width,int
    Height)
  • X1,y1coordinates where the component has to be
    placed
  • Width and height are that of the components

19
  • Public applet1 extends JApplet
  • Public void init()
  • Container cpanegetContentPane()
  • Cpane.setLayout(null)
  • JButton b1new JButton(String str)
  • Jb.setBounds(10,10,50,50)
  • Cpane.add(b1)

20
Setting color for components
  • Void setBackground(Color.c)
  • Void setForeground(Color.c)
  • Public applet1 extends JApplet
  • Public void init()
  • JButton jbnew JButton(String str)
  • Jb.setBackground(Color.GREEN)
  • Jb.setForeground(Color.BLUE)
Write a Comment
User Comments (0)
About PowerShow.com