Java - jtexfield sin foco

   
Vista:

jtexfield sin foco

Publicado por david (3 intervenciones) el 04/04/2014 19:37:45
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
package Interfaz;
 
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.Collections;
import java.util.Vector;
import javax.swing.JList;
 
public class Canal extends javax.swing.JPanel implements KeyListener {
 
    private Vector<String> genteConArroba = new Vector<String>();
    private Vector<String> genteConVoz = new Vector<String>();
    private Vector<String> genteSinPrivilegios = new Vector<String>();
    private javax.swing.JList list1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextField jTextField1;
    private ReceiveMessage _receiver;
 
    public Canal() {
        initComponents();
        this.setVisible(true);
        // this.set
 
    }
 
    Canal(String nombre, ReceiveMessage reciveMensage) {
    }
 
    Canal(String nombre, ReceiveMessage reciveMensage, JList lista) {
        list1 = lista;
        initComponents();
        setName(nombre);
        _receiver = reciveMensage;
        jTextField1.addKeyListener(this);
        // list1=lista;
    }
 
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {
 
        jScrollPane1 = new javax.swing.JScrollPane();
        //list1 = new javax.swing.JList();
        jTextField1 = new javax.swing.JTextField();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jTextArea1.setEditable(false);
        jScrollPane1.setViewportView(list1);
 
        jTextField1.setText("jTextField1");
        jScrollPane1.setHorizontalScrollBar(null);
        jScrollPane2.setHorizontalScrollBar(null);
        jTextArea1.setColumns(30);
        jTextArea1.setRows(5);
        jScrollPane2.setViewportView(jTextArea1);
 
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 335, Short.MAX_VALUE).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED).addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)).addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 10, Short.MAX_VALUE)).addContainerGap()));
        layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 286, Short.MAX_VALUE).addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 286, Short.MAX_VALUE)).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)));
//        jTextField1.setSize(100, 50);
    }// </editor-fold>
 
    public void agregarSinFiltrar(String texto) {
        if (texto.length() > 0) {
            if (jTextArea1.getText().length() > 0) {
                jTextArea1.setText(jTextArea1.getText() + '\n' + texto);
 
            } else {
                jTextArea1.setText(texto);
            }
        }
    }
 
    public void agregarTexto(String texto) {
        texto = filtrar(texto);
        if(texto!=""){
        agregarSinFiltrar(texto);
        }
 
 
    }
 
    public void agregarAvariable(String texto) {
        if (texto.substring(0, 1).contains("@") == true) {
            genteConArroba.add(texto);
        } else if (texto.substring(0, 1).contains("+") == true) {
            genteConVoz.add(texto);
        } else {
            genteSinPrivilegios.add(texto);
        }
    }
 
    private void agregarComponentesLista(Vector<String> personas) {
//
        list1.setListData(personas);
        //for(String personaActual:personas){
//            list1.add(personaActual);
//            list1.ad
//        }
        System.out.println("Ha salido");
    }
 
    public void actualizarLista() {
        ordenarListas();
        list1.removeAll();
        Vector<String> personas = new Vector<String>();
        personas.addAll(genteConArroba);
        personas.addAll(genteConVoz);
        personas.addAll(genteSinPrivilegios);
        agregarComponentesLista(personas);
 
    }
 
    public void ordenarListas() {
        Collections.sort(genteConArroba);
        Collections.sort(genteConVoz);
        Collections.sort(genteSinPrivilegios);
    }
 
    public void keyTyped(KeyEvent e) {
        //  throw new UnsupportedOperationException("Not supported yet.");
    }
 
    public void keyPressed(KeyEvent e) {
 
        if (KeyEvent.VK_ENTER == e.getKeyCode()) {
            String texto = jTextField1.getText();
            if (texto.substring(0, 1).contains("/") == false) {
                //agregarSinFiltrar(texto);
                texto = "privmsg " + getName() + " :" + texto;
 
            }
 
            _receiver.messageReceived(texto);
            jTextField1.setText("");
        }
        ;
    }
 
    public void keyReleased(KeyEvent e) {
        //   throw new UnsupportedOperationException("Not supported yet.");
    }
 
    void addtoTextfield(String texto) {
        jTextField1.setText(texto);
    }
 
    private String filtrar(String texto) {
        System.out.println("Cadena a cambiar=" + texto);
        String nick = "";
 
        if ((texto.contains("PART") == false) && (texto.contains("You're not on that channel")==false)){
            System.out.println("entra aqui");
            String variable = "PRIVMSG " + getName() + " :";
        System.out.println("variable=" + variable);
        if (texto.contains(variable) == true) {
            System.out.println("nick=" + nick);
            nick = texto.substring(0, texto.indexOf("!"));
            if (nick.substring(0, 1).contains(":") == true) {
                nick = nick.substring(1, nick.length());
            }
            System.out.println("numero" + texto.indexOf(variable));
            texto = texto.substring(texto.indexOf(variable), texto.length());
            texto = texto.replace(variable, "");
            return "<" + nick + ">" + texto;
        } else
            {
                System.out.println("entra aqui texto="+texto);
                String mensageSinTratar = "SENT: privmsg ";
                if ((texto.length() >= 16) && (texto.substring(0, 16).contains(mensageSinTratar) == true)) {
                    return "";
                }
                //System.out.println("el mensage sin tratar"+texto);
 
            }
        }
 
 
        return "";
    }
 
}

So añ text area le pongo que sea editable se ve que es el donde esta el foco /cursor
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder