Professional Documents
Culture Documents
En J2SE 1.2, los widgets de AWT fueron ampliamente superados por aquellos del kit de herramientas Swing. Adems de proveer un conjunto ms rico de widgets UI, Swing dibuja sus propios widgets (usando Java 2D para llamar a las subrutinas de bajo nivel en el subsistema de grficos local) en lugar de confiar en el mdulo de interfaz de usuario de alto nivel del sistema operativo. Swing suministra la opcin de usar un aspecto nativo o de plataforma cruzada para la aplicacin. AWT contina suministrando el ncleo del subsistema de eventos GUI y la interfaz entre el sistema de ventanas nativo y la aplicacin Java, suministrando la estructura que necesita Swing. Tambin suministra gestores de disposicin bsicos, un paquete de transferencia de datos para uso con el Bloc de notas y Arrastrar y Soltar, y la interface para los dispositivos de entrada tales como el ratn y el teclado.
Establezca las siguientes propiedades a cada control: Control Button1 Button2 Button3 Button4 Button5 TextField Propiedad / Ficha Label VariableName Label VariableName Label VariableName Label VariableName Label VariableName VariableName Valor Agregar btnagregar Eliminar btneliminar Seleccin Multiple btnmultiple Seleccin Simple btnsimple Salir Btnsalir txtNombre
private void btnagregarActionPerformed(java.awt.event.ActionEvent evt) { if (evt.getSource().equals(btnagregar)) { String nombre=txtnombre.getText(); if(nombre.length()==0) txtnombre.setText("Ingrese Nombre"); else { lstamigos.add(nombre); txtnombre.setText(""); txtnombre.requestFocus(); } } } private void btneliminarActionPerformed(java.awt.event.ActionEvent evt) { if(evt.getSource().equals(btneliminar)) { if(lstamigos.isMultipleMode()) { int indices[]=lstamigos.getSelectedIndexes(); if (indices.length>0) { int items=lstamigos.getItemCount(); int indice=0; do{ while(lstamigos.isIndexSelected(indice)) { txtnombre.setText(lstamigos.getItem(indice)); lstamigos.remove(indice); items--; } indice++; } while(items>indice); } else txtnombre.setText("Falta Seleccionar"); } else { int indice=lstamigos.getSelectedIndex(); if (indice>0) { String nombre=lstamigos.getSelectedItem(); txtnombre.setText(nombre); lstamigos.remove(indice); } else txtnombre.setText("Falta seleccionar"); } } } private void btnsimpleActionPerformed(java.awt.event.ActionEvent evt) { if(evt.getSource().equals(btnsimple)) { btnmultiple.setEnabled(true);
Escriba el siguiente cdigo import javax.swing.*; public class forma1 extends javax.swing.JFrame {public forma1() {initComponents(); iniciar(); } private void iniciar() {this.setVisible(true); this.setLocation(200,200); this.setSize(442,502); } private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { this.jTextField1.setText(""); this.jTextField2.setText("");
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) { int respuesta; respuesta=JOptionPane.showConfirmDialog(this,"Estas Seguro de Sistema",JOptionPane.YES_NO_OPTION); if (respuesta==JOptionPane.YES_OPTION) System.exit(0); } private void formWindowOpened(java.awt.event.WindowEvent evt) { // llenado del combobox this.jComboBox1.removeAllItems(); this.jComboBox1.addItem("Soltero"); this.jComboBox1.addItem("Casado"); this.jComboBox1.addItem("Divorciado"); this.jComboBox1.addItem("Viudo"); }
Terminar","Aviso
del