package semestre; import javax.swing.*; import java.awt.*; import javax.swing.event.*; import java.awt.event.*; public class Autocompletar extends JComboBox{ JTextField First = new JTextField(); String [] Last = {"Lapiz","Regla","Lampara","Remache","Pluma","Pincel","Plumon","Pizarron","Pintarron","Lamina"}; public Autocompletar(){ First.setText("WElp"); this.setEditable(true); HazListeners(); System.out.println("asd"); } KeyListener listener = new KeyListener() { public void keyTyped(KeyEvent keyEvent) { System.out.println("Typed: " + keyEvent.getKeyChar()); Metodo(); } public void keyPressed(KeyEvent keyEvent) { System.out.println("Pressed: " + keyEvent.getKeyChar()); } public void keyReleased(KeyEvent keyEvent) { System.out.println("Released: " + keyEvent.getKeyChar()); } }; public void Metodo(){ this.addItem("welp"); } public void HazListeners(){ Component Inicializador = this.getEditor().getEditorComponent(); Inicializador.addKeyListener(listener); } public void glorioso (String Word, String[] Array){ boolean number = false; for (int j=1;j<=10;j++) this.remove(j); for (int i=0;i<=Array.length;i++){ if (poderoso(Word,Array[i])) number=true; } } public boolean poderoso(String Check, String Target){ for (int i=0;i<=Target.length();i++) try { if (Check.charAt(i)!=Target.charAt(i)) return false; } catch (Exception r) { System.out.println("Error al comparar"); return false; } return true; } } /* for (int i=0; i<=Last.length-1;i++) Last[i] = new JLabel(); Last[0].setText("Lapiz"); Last[1].setText("Regla"); Last[2].setText("Lampara"); Last[3].setText("Lapicero"); Last[4].setText("Remache"); Last[5].setText("Pluma"); Last[6].setText("Plumon"); Last[7].setText("Pincel"); Last[8].setText("Pizarron"); Last[9].setText("Pintarron"); Last[10].setText("Lamina"); for (int i=0; i<=Last.length-1;i++){ this.add(Last[i]); } - - - - - System.out.println("one"); First.getDocument().addDocumentListener( new DocumentListener(){ public void changedUpdate(DocumentEvent e){ System.out.println("one"); } public void insertUpdate(DocumentEvent e){ System.out.println("two"); } public void removeUpdate(DocumentEvent e){ System.out.println("three"); } }); */