UNIDAD 5: JAVA ARREGLOS
JAVA TEMA 5: Componente List JAVA
En java este componente permite procesar visualmente un conjunto de elementos de tipo string.
Su primer y mas importante aspecto a recordar, cuando se procese o programe, es que el primer indice de la lista, es el indice numero 0(cero).
Ejemplo:
import java.lang.*; import java.awt.*; import java.awt.event.*;
public class prog22 {
//declaracion, creacion e inicializacion de componentes, objetos y variables
static Frame ventana= new Frame();
static Panel p1= new Panel(); static Panel p2= new Panel();
static List lista1= new List(5); static List lista2= new List(5);
static Label l1 = new Label("DAME EDAD:"); static TextField t1 = new TextField(4);
static Button b1 = new Button("INSERTAR"); static Button b2 = new Button("A meses");
// parte principal de programa
public static void main(String[] args)
{ // area de definicion de propiedades de el objeto
ventana.setTitle("mi programa");
p1.add(l1);p1.add(t1);p1.add(b1);p1.add(lista1);
ventana.add(p1,BorderLayout.NORTH);
p2.add(lista2);p2.add(b2);
ventana.add(p2,BorderLayout.SOUTH);
ventana.pack(); ventana.setVisible(true);
//area de asociacion de objeto-eventos
b1.addMouseListener( new MouseAdapter()
{ public void mousePressed(MouseEvent e){
lista1.add(t1.getText()); }} );
b2.addMouseListener( new MouseAdapter()
{ public void mousePressed(MouseEvent e){
int ren;int temp;
for (ren=0; ren<=4; ren++)
{temp =Integer.parseInt(lista1.getItem(ren));
temp=temp*12;
lista2.add(String.valueOf(temp)); }; }} );
ventana.addWindowListener( new WindowAdapter()
{ public void windowClosing(WindowEvent e){ System.exit(0); }} );
}; // termina main
} // termina clase
Corrida:
NOTAS:
Conversiones, conversiones, conversiones
recordar que solo podran emplearse en aplicaciones de tipo FRAME Y APPLET.
Este componente, contiene muchas propiedades y métodos que facilitan el trabajo con datos, entre ellas se encuentran:
| Constructor Summary | |
| List”()“ Creates a new scrolling list. |
|
| List”(int rows)“ Creates a new scrolling list initialized with the specified number of visible lines. |
|
| List”(int rows, boolean multipleMode)“ Creates a new scrolling list initialized to display the specified number of rows. |
|
| Method Summary | |
| “void” | add”(“String “item)“ Adds the specified item to the end of scrolling list. |
| “void” | add”(“String “item, int index)“ Adds the specified item to the the scrolling list at the position indicated by the index. |
| “void” | addActionListener”(“ActionListener “l)“ Adds the specified action listener to receive action events from this list. |
| “void” | addItem”(“String “item)“ Deprecated. replaced by “add(String)”. |
| “void” | addItem”(“String “item, int index)“ Deprecated. replaced by “add(String, int)”. |
| “void” | addItemListener”(“ItemListener “l)“ Adds the specified item listener to receive item events from this list. |
| “void” | addNotify”()“ Creates the peer for the list. |
| “boolean” | allowsMultipleSelections”()“ Deprecated. As of JDK version 1.1, replaced by “isMultipleMode()”. |
| “void” | clear”()“ Deprecated. As of JDK version 1.1, replaced by “removeAll()”. |
| “int” | countItems”()“ Deprecated. As of JDK version 1.1, replaced by “getItemCount()”. |
| “void” | delItem”(int position)“ Deprecated. replaced by “remove(String)” and “remove(int)”. |
| “void” | delItems”(int start, int end)“ Deprecated. As of JDK version 1.1, Not for public use in the future. This method is expected to be retained only as a package private method. |
| “void” | deselect”(int index)“ Deselects the item at the specified index. |
| AccessibleContext | getAccessibleContext”()“ Gets the AccessibleContext associated with this List. |
| String | getItem”(int index)“ Gets the item associated with the specified index. |
| “int” | getItemCount”()“ Gets the number of items in the list. |
| String”[]” | getItems”()“ Gets the items in the list. |
| EventListener”[]” | getListeners”(“Class “listenerType)“ Return an array of all the listeners that were added to the List with addXXXListener(), where XXX is the name of the “listenerType” argument. |
| Dimension | getMinimumSize”()“ Determines the minimum size of this scrolling list. |
| Dimension | getMinimumSize”(int rows)“ Gets the minumum dimensions for a list with the specified number of rows. |
| Dimension | getPreferredSize”()“ Gets the preferred size of this scrolling list. |
| Dimension | getPreferredSize”(int rows)“ Gets the preferred dimensions for a list with the specified number of rows. |
| “int” | getRows”()“ Get the number of visible lines in this list. |
| “int” | getSelectedIndex”()“ Gets the index of the selected item on the list, |
| “int[]” | getSelectedIndexes”()“ Gets the selected indexes on the list. |
| String | getSelectedItem”()“ Get the selected item on this scrolling list. |
| String”[]” | getSelectedItems”()“ Get the selected items on this scrolling list. |
| Object”[]” | getSelectedObjects”()“ Returns the selected items on the list in an array of Objects. |
| “int” | getVisibleIndex”()“ Gets the index of the item that was last made visible by the method “makeVisible”. |
| “boolean” | isIndexSelected”(int index)“ Determines if the specified item in this scrolling list is selected. |
| “boolean” | isMultipleMode”()“ Determines whether this list allows multiple selections. |
| “boolean” | isSelected”(int index)“ Deprecated. As of JDK version 1.1, replaced by “isIndexSelected(int)”. |
| “void” | makeVisible”(int index)“ Makes the item at the specified index visible. |
| Dimension | minimumSize”()“ Deprecated. As of JDK version 1.1, replaced by “getMinimumSize()”. |
| Dimension | minimumSize”(int rows)“ Deprecated. As of JDK version 1.1, replaced by “getMinimumSize(int)”. |
| “protected” String | paramString”()“ Returns the parameter string representing the state of this scrolling list. |
| Dimension | preferredSize”()“ Deprecated. As of JDK version 1.1, replaced by “getPreferredSize()”. |
| Dimension | preferredSize”(int rows)“ Deprecated. As of JDK version 1.1, replaced by “getPreferredSize(int)”. |
| “protected void” | processActionEvent”(“ActionEvent “e)“ Processes action events occurring on this component by dispatching them to any registered “ActionListener” objects. |
| “protected void” | processEvent”(“AWTEvent “e)“ Processes events on this scrolling list. |
| “protected void” | processItemEvent”(“ItemEvent “e)“ Processes item events occurring on this list by dispatching them to any registered “ItemListener” objects. |
| “void” | remove”(int position)“ Remove the item at the specified position from this scrolling list. |
| “void” | remove”(“String “item)“ Removes the first occurrence of an item from the list. |
| “void” | removeActionListener”(“ActionListener “l)“ Removes the specified action listener so that it no longer receives action events from this list. |
| “void” | removeAll”()“ Removes all items from this list. |
| “void” | removeItemListener”(“ItemListener “l)“ Removes the specified item listener so that it no longer receives item events from this list. |
| “void” | removeNotify”()“ Removes the peer for this list. |
| “void” | replaceItem”(“String “newValue, int index)“ Replaces the item at the specified index in the scrolling list with the new string. |
| “void” | select”(int index)“ Selects the item at the specified index in the scrolling list. |
| “void” | setMultipleMode”(boolean b)“ Sets the flag that determines whether this list allows multiple selections. |
| “void” | setMultipleSelections”(boolean b)“ Deprecated. As of JDK version 1.1, replaced by “setMultipleMode(boolean)”. |
TABLAS TOMADAS DEL API DE JAVA
TAREAS JAVA
1.- EN JAVA CAPTURAR EN UNA LISTA LOS SUELDOS DE 6 EMPLEADOS Y DESPLEGARLOS EN UNA SEGUNDA LISTA AUMENTADOS EN UN 30% ( java frame )
2.- EN JAVA CAPTURAR EN UNA LISTA LOS PESOS EN KILOGRAMOS DE 6 PERSONAS DESPLEGARLOS EN UNA SEGUNDA LISTA CONVERTIDOS A LIBRAS Y ADEMAS SOLO LOS MAYORES DE 100 LIBRAS. ( java applet )
3.- EN JAVA CAPTURAR EN SUS 4 LISTAS RESPECTIVAS MATRICULA, NOMBRE Y DOS CALIFICACIONES DE 5 ALUMNOS, DESPUÉS CALCULAR UNA LISTA DE PROMEDIOS DE CALIFICACIONES. ( java frame )
4.-EN JAVA CAPTURAR EN SUS LISTAS RESPECTIVAS NUMEMPLEADO, NOMEMPLEADO, DÍAS TRABAJADOS Y SUELDO DIARIO DE 5 EMPLEADOS, DESPLEGAR EN OTRA PANTALLA O PANEL LA NOMINA PERO SOLO DE AQUELLOS EMPLEADOS QUE GANAN MAS DE $300.00 A LA SEMANA.( java applet )