Java - Problemita con setText

 
Vista:

Problemita con setText

Publicado por Daniel (2 intervenciones) el 11/06/2013 16:18:41
Buenos dìas gente del foro, soy un nuevo programador con algunas dudas! jeje,
en este momento me encuentro armando un programa para la empresa en la cual trabajo y me esta surgiendo un problemita a la hora de setear un texto en un JTextField.

En la clase Triplicada no estoy teniendo ningùn problema ya que me obtiene el texto correctamente, el problema llega en la clase trabajo cuando quiero desplegar el texto obtenido en la clase anterior en un jtextfield.

Les paso el codigo de las clases:


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
package metal;
 
import java.awt.event.KeyEvent;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
 
/**
 *
 * @author Danibook
 */
public class Triplicada extends javax.swing.JFrame {
 
    /**
     * Creates new form Triplicada
     */
 
 
    public Triplicada() {
        initComponents();
        String nt = nTripli.getText();
        // TODO code application logic here
 
    }
 
 
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
 
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {
 
        nTripli = new javax.swing.JTextField();
        Salir = new javax.swing.JButton();
 
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
 
        nTripli.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        nTripli.setText("0");
        nTripli.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nTripliActionPerformed(evt);
            }
        });
        nTripli.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                nTripliKeyPressed(evt);
            }
        });
 
        Salir.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        Salir.setText("Salir");
        Salir.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                SalirMouseClicked(evt);
            }
        });
 
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(65, 65, 65)
                        .addComponent(nTripli, javax.swing.GroupLayout.PREFERRED_SIZE, 168, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(88, 88, 88)
                        .addComponent(Salir, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(71, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addComponent(nTripli, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(Salir, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(23, Short.MAX_VALUE))
        );
 
        pack();
    }// </editor-fold>                        
 
    private void SalirMouseClicked(java.awt.event.MouseEvent evt) {
        // TODO add your handling code here:
        this.dispose();
    }
 
    private void nTripliActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
 
    }
 
    private void nTripliKeyPressed(java.awt.event.KeyEvent evt) {
        // TODO add your handling code here:
 
 
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            if ("".equals(nTripli.getText())) {
                JOptionPane.showMessageDialog(null, "Ingrese numero de triplicada");
            } else {
                new Trabajo().setVisible(true);
                System.out.println(obtenerTripli());
 
            }
 
        }
 
    }
 
    // Variables declaration - do not modify                     
    private javax.swing.JButton Salir;
    private javax.swing.JTextField nTripli;
    // End of variables declaration                   
   public String obtenerTripli() {
       String tri = nTripli.getText();
    return tri;
}
 
 
 
}

Aca les paso simplemente lo que agrego al constructor porque es muy extensa la clase asi no se matan buscando :P.
Con esto no me setea ningùn texto, probe cambiando por un texto cualquiera ej.: *.setText("11111"), y me funciona perfecto.
por que es?

1
2
Triplicada UD = new Triplicada();
        nTrabajo.setText(UD.obtenerTripli());
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