23
CHAPTER:08 JAVA IDE PROGRAMMING-III Prepared By Prepared By : VINAY ALEXANDER VINAY ALEXANDER ( ( वववव वववव ववववववववववव ववववववववववव ) ) PGT(CS) ,KV JHAGRAKHAND PGT(CS) ,KV JHAGRAKHAND

CHAPTER:08 JAVA IDE PROGRAMMING-III Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND

Embed Size (px)

Citation preview

  • Slide 1

CHAPTER:08 JAVA IDE PROGRAMMING-III Prepared By Prepared By : VINAY ALEXANDER ( ) PGT(CS),KV JHAGRAKHAND Slide 2 Objective In this presentation you will learn about the following swing controls i.e. Purpose, their design time Properties and Run time Methods. List (jList) Combo (List+Text Field) (jComboBox) Timers Random Number Generation & use Slide 3 Working with jList control A List (or List box) is box shaped control containing list of objects, from which single or multiple selection can be made. jList control offers the following features- A box shaped control capable to displaying a list of choices (Text or graphics/images). It Allows single or multiple selection of items using mouse. Equipped with built-in scroll bar to view a large list. valueChanged() method of ListSelection Listener is used to handle the JList events Slide 4 How to add jList control with Frame A jList can be attached with frame in following way- Select List control from Swing palette, and drag and drop on the frame. Select the jList control and click on() button of Model property. A dialog box appears. Type list of choices in ListModelEditor dialog box. Finally press OK button. List Box is displayed on the frame with typed choices. Slide 5 Slide 6 int [ ] getSelectedIndices( ) Returns an array of all of the selected indices, in increasing order, or an empty if nothing is selected Slide 7 Slide 8 Slide 9 Slide 10 Adding/Removing Items at run time (Dynamic List) Step 1. Add a list control to your form. Step 2. Define its through DefaultListModel Step3:The following steps should be followed in the event handler of the button, where you want to implement the command. 1. Make a model object as- DefaultListModel dlm = (DefaultListModel) jList1.getModel(); Slide 11 2. Use following command as per requirement- // add item in the end of the list// dlm.addElement(Apple); // Insert item at given index in the list// dlm.addElementAt(Apple,2); // Remove selected item from the list// dlm.removeElement(jList1.getSelectedIndex()); // Remove item from given position from the list// dlm.removeElementAt(4); // Remove given item from from the list// dlm.removeElement(Banana); 3. Reflect all changes to the list jList1.setModel(dlm) Slide 12 Slide 13 Slide 14 Slide 15 Slide 16 Slide 17 Slide 18 Table: It is responsible for displaying or representing the data in tabular way i.e, in row and column format using JTable. But the data to a Jtable is provided via a Table Model. A Table Model is responsible for storing data that will act as source for Jtable. Slide 19 Steps for Adding a row in a table: 1.Create a table in netbeans. if a table stores details like empno, empname, desig, basic. 2. create an object array out of the data for the new row by specifying data in the same order as determined in step 1 object newRow[]={1105,ram, head,108000}; Or object[ ] newRow={ emn.getText, emname.getText(), emdesig. getText(), emsal. getText() }; Slide 20 3. Obtain the tables model in a DefaultTableModel object. Syntax: DefaultTableModel =(DefaultTableModel). getMode(); Example: DefaultTableModel tm=(DefaultTableModel) emptbl. getMode(); Import javax.swing.table.*; // top of source editor 4. Now add the object array created in step 2 into the table-model object of step 3 using addRow( ) method. Syntax:.addRow ( ; OR tm.addRow(newRow); // add a row in a table tm.removeRow(2); // remove row 3 from table Slide 21 Commonly used methods of Jtable class Ml getModelethodDescription int getColumnCount( )Return the number of column in the table int getRowCount ( )Return the number of row in the table TableMode getModel( )Return the TableModel that provides the data displayed by this JTable Object getValueAt(int row,int column)Return the cell value at row and column Slide 22 MENU BASIC => Horizontal menu known as Menu bar. It contains one or more menus and has a customary,platform-dependent location. => Vertical Menu known as popup menu/pull-down/ sub menu. It is invisible until the user performs more mouse action. => A Toolbar is a collection of buttons that correspond to items in an applications menu, providing a graphic interface for the user to access an applications most frequently used functions and commands. Slide 23