Java - [Ayuda] Con respecto a un void y un textarea

 
Vista:
sin imagen de perfil

[Ayuda] Con respecto a un void y un textarea

Publicado por Gustavo (5 intervenciones) el 25/11/2016 03:45:40
Buenas amigos, cuestion que estoy trabajando con interfaces graficas en java y quiero imprimirel siguiente metodo en un text area, pero no se como hacerlo, hasta ahora llevo esto.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
public void CreaArchivo(){
         try{
            BufferedWriter ficheroSalida = new BufferedWriter(new FileWriter(new File("Fichero.txt")));
            ficheroSalida.write("Hola");
            ficheroSalida.newLine();
            ficheroSalida.write("esto es un archivo");
            ficheroSalida.newLine();
            ficheroSalida.write("y está siendo leido.");
            ficheroSalida.newLine();
            ficheroSalida.close();
 
 
 
        }catch (IOException errorDeFichero){
            System.out.println("ha habido un problema" + errorDeFichero.getMessage());
        }
 
 
    }
 
    public Fichero() {
 
    }
}

y en la parte grafica tengo esto.

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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package barberia;
 
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import javax.swing.JOptionPane;
import javax.swing.JFileChooser;
import java.io.FileReader;
import java.io.BufferedReader;
 
/**
 *
 * @author La Casa
 */
public class Facturacion extends javax.swing.JFrame {
 
    /**
     * Creates new form Facturacion
     */
    public Facturacion() {
        initComponents();
    }
 
    /**
     * 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() {
 
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtResultado = new javax.swing.JTextArea();
        btnLimpiar = new javax.swing.JButton();
        btnSalir = new javax.swing.JButton();
        btnMostrar = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
 
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setMinimumSize(new java.awt.Dimension(670, 400));
        setResizable(false);
 
        jPanel1.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jPanel1.setMinimumSize(new java.awt.Dimension(670, 400));
        jPanel1.setLayout(null);
 
        txtResultado.setColumns(20);
        txtResultado.setRows(5);
        jScrollPane1.setViewportView(txtResultado);
 
        jPanel1.add(jScrollPane1);
        jScrollPane1.setBounds(10, 11, 650, 300);
 
        btnLimpiar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/btns/Limpiar_Null.png"))); // NOI18N
        btnLimpiar.setContentAreaFilled(false);
        btnLimpiar.setPressedIcon(new javax.swing.ImageIcon(getClass().getResource("/img/btns/Limpiar_Presion.png"))); // NOI18N
        btnLimpiar.setSelectedIcon(new javax.swing.ImageIcon(getClass().getResource("/img/btns/Limpiar_Mouse.png"))); // NOI18N
        btnLimpiar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLimpiarActionPerformed(evt);
            }
        });
        jPanel1.add(btnLimpiar);
        btnLimpiar.setBounds(450, 340, 90, 40);
 
        btnSalir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/btns/Salir_Null.png"))); // NOI18N
        btnSalir.setContentAreaFilled(false);
        btnSalir.setPressedIcon(new javax.swing.ImageIcon(getClass().getResource("/img/btns/Salir_Presion.png"))); // NOI18N
        btnSalir.setSelectedIcon(new javax.swing.ImageIcon(getClass().getResource("/img/btns/Salir_Mouse.png"))); // NOI18N
        btnSalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSalirActionPerformed(evt);
            }
        });
        jPanel1.add(btnSalir);
        btnSalir.setBounds(550, 340, 90, 40);
 
        btnMostrar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/btns/Mostrar_Null.png"))); // NOI18N
        btnMostrar.setContentAreaFilled(false);
        btnMostrar.setPressedIcon(new javax.swing.ImageIcon(getClass().getResource("/img/btns/Mostrar_Presion.png"))); // NOI18N
        btnMostrar.setSelectedIcon(new javax.swing.ImageIcon(getClass().getResource("/img/btns/Mostrar_Mouse.png"))); // NOI18N
        btnMostrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnMostrarActionPerformed(evt);
            }
        });
        jPanel1.add(btnMostrar);
        btnMostrar.setBounds(350, 339, 90, 40);
 
        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/fondoPlano.jpg"))); // NOI18N
        jPanel1.add(jLabel1);
        jLabel1.setBounds(-7, -3, 680, 410);
 
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
 
        pack();
    }// </editor-fold>                        
 
    private void btnMostrarActionPerformed(java.awt.event.ActionEvent evt) {
//       Persona persona = new Persona();
//       String Nombre = persona.getNombre();
//       txtResultado.setText(Nombre);
 
//        JFileChooser chooser = new JFileChooser();
//        chooser.showOpenDialog(null);
//        File f = chooser.getSelectedFile();
//        String archivo = f.getAbsolutePath();
//        try{
//            FileReader fr = new FileReader(archivo);
//            BufferedReader br = new BufferedReader(fr);
//            txtResultado.read(br, null);
//            br.close();
//            txtResultado.requestFocus();
//            
//            
//        }catch(Exception e){
//            JOptionPane.showInternalMessageDialog(null,"No ha escogido ningun archivo" + e);
//        }
        Fichero fichero = new Fichero();
        fichero.CreaArchivo();
 
 
 
 
 
 
 
    }
 
    private void btnLimpiarActionPerformed(java.awt.event.ActionEvent evt) {
        txtResultado.setText("");
    }
 
    private void btnSalirActionPerformed(java.awt.event.ActionEvent evt) {
        try{
            String opcion = JOptionPane.showInputDialog(null, "¿Desea salir? \n 1.Si \n 2.No");
        int opc = Integer.parseInt(opcion);
        if(opc == 1){
            System.exit(0);
        }else{
            JOptionPane.showMessageDialog(null, "Ok");
        }
        }catch(Exception e){
            JOptionPane.showMessageDialog(null, "No escogio ninguna opcion.Por favor, hagalo");
        }
 
    }
 
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Facturacion.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Facturacion.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Facturacion.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Facturacion.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
 
        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Facturacion().setVisible(true);
            }
        });
    }
 
    // Variables declaration - do not modify                     
    private javax.swing.JButton btnLimpiar;
    private javax.swing.JButton btnMostrar;
    private javax.swing.JButton btnSalir;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea txtResultado;
    // End of variables declaration                   
 
    private String leerFichero() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
}
De antemano gracias y espero su ayuda con ansias, han sido un gran apoyo en este cuatrimestre!!!
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