Foros del Web » Programación para mayores de 30 ;) » Java »

problema al cargar text??

Estas en el tema de problema al cargar text?? en el foro de Java en Foros del Web. cuando ejecuto el programa no me carga el archi de texto deseado en la clase "ventana" a ver si me podrian corregir que estoy haciendo ...
  #1 (permalink)  
Antiguo 20/06/2011, 18:07
 
Fecha de Ingreso: mayo-2010
Mensajes: 5
Antigüedad: 14 años
Puntos: 0
problema al cargar text??

cuando ejecuto el programa no me carga el archi de texto deseado en la clase "ventana" a ver si me podrian corregir que estoy haciendo mal. aca les dejo el Source

Código java:
Ver original
  1. package javaapplication7;
  2.  
  3. /**
  4.  *
  5.  * @author Dell
  6.  */
  7. import java.io.*;
  8. import java.awt.*;
  9. import java.awt.event.*;
  10. import javax.swing.*;
  11. public class Pantalla extends JFrame //implements ActionListener
  12. {
  13. public String nombre;
  14. TextField txtdiscos;
  15. TextField txtopcion;
  16. JButton boton2 =new  JButton("siguiente");
  17. JPanel panel = new JPanel();
  18. public Pantalla (){
  19. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  20. panel.setBackground(Color.red);
  21. panel. add(boton2);
  22. add(panel,"South");
  23. setSize(1024,700);
  24. dispose();
  25. boton2.addActionListener(new ActionListener(){
  26. public void actionPerformed(ActionEvent e){
  27. ventana n = new ventana();
  28. n.l.setText("Medios USB");
  29. n.show();
  30. setVisible(false);
  31.  
  32. }
  33. });
  34. }
  35. }
  36. class ventana extends JFrame //implements ActionListener
  37. {
  38. public String Obtener_texto(String ruta){
  39.  
  40.         String texto="C:\\Documents and Settings\\Dell\\Escritorio\\Majo.txt";
  41.  
  42. try{
  43.  
  44.     BufferedReader b= new BufferedReader(new FileReader(new File(ruta)));
  45.  
  46.     String control="C:\\Documents and Settings\\Dell\\Escritorio\\Majo.txt";
  47.  
  48.     while(control!=null){
  49.  
  50.         control = b.readLine();
  51.  
  52.         if(control!=null){
  53.  
  54.             texto+=control + "\n";
  55.  
  56.         }
  57.  
  58.     }
  59.  
  60.  
  61.  
  62. }catch(IOException ex){
  63.  
  64. JOptionPane.showMessageDialog(null, "El archivo no existe o esta mal escrita la ruta");
  65.  
  66. }
  67.  
  68.         return texto;
  69.  
  70.     }
  71. JTextArea area = new JTextArea();
  72. JPanel b = new JPanel();
  73. JPanel p = new JPanel();
  74. JLabel l=new JLabel();
  75. JButton boton0 = new JButton("Anterior");
  76. JButton boton1 = new JButton ("Video");
  77. JButton boton3 =new JButton("Imprimir");
  78. JButton boton4= new JButton("Sonido");
  79. JButton boton6= new JButton("Siguiente");
  80. Pantalla X= new Pantalla();
  81. JPanel sig=new JPanel();
  82. public ventana(){
  83. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  84. p.setBackground(Color.red);
  85. b.add(area);
  86. add(b,"North");
  87. l.setText(X.nombre);
  88. p.add(l);
  89. p.add(sig);
  90. p.add(boton0);
  91. p.add(boton1);
  92. p.add(boton3);
  93. p.add(boton4);
  94. p.add(boton6);
  95. add(p,"South");
  96. dispose();
  97. setSize(1024,700);
  98. boton6.addActionListener(new ActionListener(){
  99. public void actionPerformed(ActionEvent e){
  100. desarrollo D=new desarrollo();
  101. D.show();
  102. dispose ();
  103. }
  104. });
  105. boton0.addActionListener(new ActionListener(){
  106. public void actionPerformed(ActionEvent e){
  107. Pantalla P=new Pantalla();
  108. P.show();
  109. setVisible(false);
  110. }
  111. });
  112. }
  113. }
  114. class desarrollo extends JFrame //implements ActionListener
  115. {
  116.  
  117. JPanel pan = new JPanel();
  118. JLabel l=new JLabel();
  119. JButton boton7=new JButton("Volver Atras");
  120. JButton boto=new JButton("Finalizar");
  121.  
  122. Pantalla X= new Pantalla();
  123. JPanel fin=new JPanel();
  124. public desarrollo(){
  125. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  126. pan.setBackground(Color.red);
  127. l.setText(X.nombre);
  128.  
  129. pan.add(l);
  130. pan.add(fin);
  131. pan.add(boton7);
  132. pan.add(boto);
  133.  
  134. add(pan,"South");
  135. setVisible(true);
  136. setSize(1024,700);
  137. boton7.addActionListener(new ActionListener(){
  138. public void actionPerformed(ActionEvent e){
  139. ventana  V=new ventana();
  140. V.show();
  141. dispose ();
  142.  
  143. }
  144. });
  145. }
  146. }
  #2 (permalink)  
Antiguo 20/06/2011, 19:46
Avatar de FiruzzZ  
Fecha de Ingreso: diciembre-2007
Ubicación: en casa
Mensajes: 470
Antigüedad: 16 años, 4 meses
Puntos: 41
Respuesta: problema al cargar text??

Mmmm Si te tengo que decir todo lo que está mal en "tú" código, no termino mas (empezando por el título del post que no da ni una pista), así que me voy a limitar a tu duda

El método Obtener_texto(String ruta) (linea código Nº 38) de la clase ventana NO ESTÁ siendo llamado en ninguna parte del código que posteaste.
__________________
BadProgrammerException!
  #3 (permalink)  
Antiguo 21/06/2011, 10:37
 
Fecha de Ingreso: mayo-2010
Mensajes: 5
Antigüedad: 14 años
Puntos: 0
Respuesta: problema al cargar text??

y mas o menos como le haria ese llamado..??

Etiquetas: txt
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 10:05.