1 / 20

LAB SESSION 9

LAB SESSION 9. * COMPONENTS IN JAPPLET * SETBOUNDS METHOD * DIRECTION OF INPUT TO STDIN. JAPPLET IS A SUB CLASS OF APPLET Components in JAPPLET AND APPLET JApplet Applet JButton Button JTextField TextField

talia
Download Presentation

LAB SESSION 9

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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 cpane=getContentPane(); Cpane.setLayout(null); JLabel ll=new 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 cpane=getContentPane(); Cpane.setLayout(null); JTextField tt=new 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 cpane=getContentPane(); Cpane.setLayout(null); JButton jb=new 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 cpane=getContentPane(); Cpane.setLayout(null); JCheckBox cb=new 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 cpane=getContentPane(); Cpane.setLayout(null); RadioButtonGroup jpg=new RadioButtonGroup(); JRadioButton bb=new JButton(String str); JRadioButton bb1=new 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); • It’s 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 cpane=getContentPane(); Cpane.setLayout(null); JComboBox jcb=new 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 cpane=getContentPane(); Cpane.setLayout(null); ListBox lb=new 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,y1—coordinates where the component has to be placed Width and height –are that of the components

  19. Public applet1 extends JApplet { Public void init() { Container cpane=getContentPane(); Cpane.setLayout(null); JButton b1=new 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 jb=new JButton(String str); Jb.setBackground(Color.GREEN); Jb.setForeground(Color.BLUE); } }

More Related