elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Curso de javascript por TickTack


  Mostrar Mensajes
Páginas: [1] 2
1  Programación / Java / Re: problema con BufferedReader en: 19 Junio 2007, 21:49 pm
hola:
gracias por tu sugerencia...

la verdad solo modifique esta parte del codigo y me funcionó perfectamente:

esta linea de codigo

Código:
process = Runtime.getRuntime().exec("/bin/bash");

lo cambie por esta linea

Código:
process = Runtime.getRuntime().exec("/bin/sh");

muchas gracias por tu ayuda...

2  Programación / Java / problema con BufferedReader en: 15 Junio 2007, 20:51 pm
hola:

Tengo un ciclo para leer de buffer y luego imprimir lo que leyo en un TextArea y la manera de detener el ciclo es cuando el buffer sea Null.

en el Text Area deberia aparece escrito la salida de un Script que ejecuto en UNIX como se ve en color rojo.

Ingrese una opcion [1]Prueba   [2]Salir

una vez que aparece esto se debe ingresar la opcion y sigue la ejecucion del script.

pero aparentemente el buffer nunca se hace null y se queda imprimiendo siempre lo mismo en un ciclo infinito y no se le pueden enviar los datos para la seleccion de la opcion [1] o [2]...

alguien tendra alguna sugerencia para que esto no suceda??

este es el codigo del hilo que lee el buffer de entrada.

muchas gracias

prestar atencion en esta parte del codigo

Código:
                                        while ((line = in.readLine()) != null) 
                                        {
                                                t.printOut(line);
                                        }


Código:
        class InputThread implements Runnable 
        {
                BufferedReader in;
                Main t;
                public boolean keepGoing;
 
                public InputThread(BufferedReader in, Main t)
                {
                        this.in = in;
                        this.t = t;
                        this.keepGoing = true;
                }
 
                public void quitIt()
                {
                        keepGoing = false;
                }
 
                public void run()
                {
                        while (keepGoing)
                        {
                                String line;
                                try
                                {
                                        while ((line = in.readLine()) != null)
                                        {
                                                t.printOut(line);
                                        }
                                }
                                catch (IOException e) 
                                {
                                        t.printOut(e.getMessage());
                                }
                        }
                }
        }
3  Programación / Java / Re: Scroll automatico en un JScrollPane en: 15 Junio 2007, 15:00 pm
hola... muchisimas gracias por tu sugerencia... la voy a tomar pq es una forma mucho mas sencilla de hacerlo...

gracias

4  Programación / Java / Re: Scroll automatico en un JScrollPane en: 14 Junio 2007, 16:03 pm
ya encontre un metodo que hace esto...

aqui lo dejo para el que le interese

http://www.chuidiang.com/chuwiki/index.php?title=JScrollPane

y este es el codigo

Código:
SwingUtilities.invokeLater(new Runnable() {
   public void run() {
      for (int i=0;i<100;i++)
      {
         textArea.append("texto "+i+"\n");
         Dimension tamanhoTextArea = textArea.getSize();
         Point p = new Point(
            0,
            tamanhoTextArea.height
         );
         scroll.getViewport().setViewPosition(p);
      }
   }
});
5  Programación / Java / Scroll automatico en un JScrollPane en: 14 Junio 2007, 15:19 pm
hola

tengo un JScrollPane con un JText Area y a medida que voy escribiendo texto quisiera que se hiciera un scroll automatico pues hasta ahora tengo que hacerlo manualmente con el scroll del raton.

existe algun metodo de la clase JScrollPane que haga esto??

muchas gracias
6  Programación / Java / Re: Interfaz grafica y clase process en: 13 Junio 2007, 16:06 pm
HOla:

ya habia leido tu respuesta. disculpa por no responder...

la idea es poder responderle al comando DATE con una nueva fecha... por eso tu sugerencia aunque buena no me sirve... pero muchas gracias por tu interes en ayudarme

saludos
7  Programación / Java / Re: Interfaz grafica y clase process en: 7 Junio 2007, 21:10 pm
tienes razon, por mal uso del foro abri mas hilos de la cuenta, no se si puedan borrarse... procurare no hacerlo en el futuro... la verdad todavia no he podido resolver el problema... gracias por tu ayuda...
8  Programación / Java / Interfaz grafica y clase process en: 7 Junio 2007, 15:32 pm
hola:

estoy desarrollando esta interfaz grafica....

cuando ejecuto los comandos dir, ipconfig, ping me muestra la salida en el cuadro de texto.

pero con el comando date se tranca el programa pq espera a que le envie una fecha para actualizar...

dejo el codigo completo para el que lo quiera ver y me pueda ayudar... gracias

Código
  1. // Sistema de Gestión MTSO San Cristóbal
  2. // Realizado por: Wilmer Rondón
  3.  
  4. import java.awt.*;
  5. import java.awt.event.*;
  6. import javax.swing.*;
  7. import java.awt.Color;
  8. import javax.swing.JTabbedPane;
  9. import javax.swing.ImageIcon;
  10. import javax.swing.JLabel;
  11. import javax.swing.JPanel;
  12. import javax.swing.JFrame;
  13. import javax.swing.JButton;
  14. import java.io.*;
  15. import java.lang.ProcessBuilder;
  16.  
  17. //********************************************************************************************************************************
  18. // CLASE PRINCIPAL DEL PROGRAMA "VENTANA"
  19. public class Main extends JPanel
  20. {
  21. protected Boolean bd1 = false, bd2 = false, bd3 = false, bd4 = false;
  22.        protected JTextField texto1, texto2, texto3, texto4;
  23. protected JTextArea areaTexto1, areaTexto2, areaTexto3, areaTexto4;
  24. protected JPanel p1A, p1B, p1C, p1D, p2A, p2B, p2C, p2D, p3A, p3B, p3C, p3D, p4A, p4B, p4C, p4D;
  25. protected JButton btOK1, btQuitar1, btSalir1, btOK2, btQuitar2, btSalir2, btOK3, btQuitar3, btSalir3, btOK4, btQuitar4, btSalir4;
  26. protected String texto1Inicio, texto2Inicio, texto3Inicio, texto4Inicio;
  27. protected Color B, F1, F2, F3;
  28. protected int orden;
  29. protected final static String newline = "\n";
  30.  
  31. //********************************************************************************************************************************
  32. // CONSTRUCTOR DE LA CLASE VENTANA
  33. public Main()
  34. {
  35. ImageIcon icon1 = new ImageIcon("images/ic_ringroad.jpg");
  36. ImageIcon icon2 = new ImageIcon("images/ib_celtic.jpg");
  37. ImageIcon icon3 = new ImageIcon("images/ic_patio.jpg");
  38. ImageIcon icon4 = new ImageIcon("images/mante.jpg");
  39.  
  40. JTabbedPane pestanas = new JTabbedPane();
  41.  
  42. Component panel_pestana1 = pestana1("Pestana Uno");
  43. pestanas.addTab("Troncales", icon1, panel_pestana1);
  44. Component panel_pestana2 = pestana2("Pestana Dos");
  45. pestanas.addTab("Packet Pipes", icon2, panel_pestana2);
  46. Component panel_pestana3 = pestana3("Pestana Tres");
  47. pestanas.addTab("Celdas", icon3, panel_pestana3);
  48. Component panel_pestana4 = pestana4("Pestana Cuatro");
  49. pestanas.addTab("Mantenimiento", icon4, panel_pestana4);
  50.  
  51. setLayout(new GridLayout(1, 1));
  52. add(pestanas);
  53. }
  54.  
  55. //********************************************************************************************************************************
  56. // METODO PARA CONSTRUIR LA PESTAÑA "TRONCALES"
  57. protected Component pestana1(String text)
  58. {
  59. p1A = new JPanel(new GridLayout(2,1)); // panel Principal
  60. p1B = new JPanel(new BorderLayout());  //
  61. p1C = new JPanel(new BorderLayout());  //
  62. p1D = new JPanel(new GridLayout(1,3)); // panel para 3 botones en BorderLayout.SOUTH
  63. p1A.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
  64.  
  65. JTabbedPane subpestanas1 = new JTabbedPane();
  66. Component panel_subpestana11 = subpestana11("Crear");
  67. subpestanas1.addTab("Crear", panel_subpestana11);
  68. Component panel_subpestana12 = subpestana12("Crecer");
  69. subpestanas1.addTab("Crecer", panel_subpestana12);
  70. Component panel_subpestana13 = subpestana13("Dedrecer");
  71. subpestanas1.addTab("Dedrecer", panel_subpestana13);
  72. Component panel_subpestana14 = subpestana14("Eliminar");
  73. subpestanas1.addTab("Eliminar", panel_subpestana14);
  74. Component panel_subpestana15 = subpestana15("Inclusión en Reporte TGCOM");
  75. subpestanas1.addTab("Inclusión en Reporte TGCOMP", panel_subpestana15);
  76. Component panel_subpestana16 = subpestana16("Mudanza");
  77. subpestanas1.addTab("Mudanza", panel_subpestana16);
  78.  
  79. texto1 = new JTextField(40);
  80. texto1.setFont(new java.awt.Font("Arial", Font.PLAIN, 12));
  81. texto1Inicio = "Escriba aquí un comando y haga click sobre el botón \"OK\"";
  82. texto1.setText(texto1Inicio);
  83.  
  84. areaTexto1 = new JTextArea(10,40);
  85. areaTexto1.setEditable(false);
  86. areaTexto1.setFont(new java.awt.Font("Arial", Font.PLAIN, 12));
  87. B = new Color(200,200,200);
  88. areaTexto1.setBackground(B);
  89. F1 = new Color(0,0,0);
  90. areaTexto1.setForeground(F1);
  91. JScrollPane pScroll = new JScrollPane(areaTexto1, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
  92.  
  93. btOK1 = new JButton("OK");
  94. btQuitar1 = new JButton("Limpiar pantalla");
  95. btSalir1 = new JButton("Salir");
  96.  
  97. texto1.addActionListener(new ejecutar());
  98. btOK1.addActionListener(new ejecutar());
  99.                btOK1.addActionListener(new bdTroncales());
  100. btQuitar1.addActionListener(new limpiarPantalla());
  101. btSalir1.addActionListener(new cerrarVentana());
  102.  
  103. p1A.add(p1B);
  104. p1A.add(p1C);
  105. p1B.add(subpestanas1);//agregar sub pestanas
  106. p1D.add(btOK1);
  107. p1D.add(btQuitar1);
  108. p1D.add(btSalir1);
  109. p1C.add(texto1,BorderLayout.NORTH);
  110. p1C.add(pScroll, BorderLayout.CENTER);
  111. p1C.add(p1D, BorderLayout.SOUTH);
  112.  
  113. btOK1.setToolTipText("Ingresar Comando");
  114. btQuitar1.setToolTipText("Limpiar la Pantalla");
  115. btSalir1.setToolTipText("Salir de la aplicación");
  116.  
  117. return p1A;
  118.  
  119. }
  120.  
  121. //********************************************************************************************************************************
  122. // METODO PARA CONSTRUIR LA PESTAÑA "PACKET PIPES"
  123. protected Component pestana2(String text)
  124. {
  125. p2A = new JPanel(new GridLayout(2,1)); // panel Principal
  126.                p2B = new JPanel(new BorderLayout());  //
  127. p2C = new JPanel(new BorderLayout());  //
  128. p2D = new JPanel(new GridLayout(1,3)); // panel para 3 botones en BorderLayout.SOUTH
  129. p2A.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
  130.  
  131. JTabbedPane subpestanas2 = new JTabbedPane();
  132. Component panel_subpestana21 = subpestana21("Mudar");
  133. subpestanas2.addTab("Mudar", panel_subpestana21);
  134. Component panel_subpestana22 = subpestana22("Crecer");
  135. subpestanas2.addTab("Crecer", panel_subpestana22);
  136. Component panel_subpestana23 = subpestana23("Dedrecer");
  137. subpestanas2.addTab("Dedrecer", panel_subpestana23);
  138. Component panel_subpestana24 = subpestana24("Equipar");
  139. subpestanas2.addTab("Equipar", panel_subpestana24);
  140. Component panel_subpestana25 = subpestana25("Desequipar");
  141. subpestanas2.addTab("Desequipar", panel_subpestana25);
  142.  
  143. texto2 = new JTextField(40);
  144. texto2.setFont(new java.awt.Font("Arial", Font.PLAIN, 12));
  145. texto2Inicio = "Escriba aquí un comando y haga click sobre el botón \"OK\"";
  146. texto2.setText(texto2Inicio);
  147.  
  148. areaTexto2 = new JTextArea(10,40);
  149. areaTexto2.setEditable(false);
  150. areaTexto2.setFont(new java.awt.Font("Arial", Font.PLAIN, 12));
  151. B = new Color(200,200,200);
  152. areaTexto2.setBackground(B);
  153. F1 = new Color(0,0,0);
  154. areaTexto2.setForeground(F1);
  155. JScrollPane pScroll2 = new JScrollPane(areaTexto2, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
  156.  
  157. btOK2 = new JButton("OK");
  158. btQuitar2 = new JButton("Limpiar pantalla");
  159. btSalir2 = new JButton("Salir");
  160.  
  161. texto2.addActionListener(new ejecutar());
  162. btOK2.addActionListener(new ejecutar());
  163. btQuitar2.addActionListener(new limpiarPantalla());
  164. btSalir2.addActionListener(new cerrarVentana());
  165.  
  166. p2A.add(p2B);
  167. p2A.add(p2C);
  168. p2B.add(subpestanas2);//agregar sub pestanas
  169. p2D.add(btOK2);
  170. p2D.add(btQuitar2);
  171. p2D.add(btSalir2);
  172. p2C.add(texto2,BorderLayout.NORTH);
  173. p2C.add(pScroll2, BorderLayout.CENTER);
  174. p2C.add(p2D, BorderLayout.SOUTH);
  175.  
  176. btOK2.setToolTipText("Ingresar Comando");
  177. btQuitar2.setToolTipText("Limpiar la Pantalla");
  178. btSalir2.setToolTipText("Salir de la aplicación");
  179.  
  180. return p2A;
  181. }
  182.  
  183. //********************************************************************************************************************************
  184. // METODO PARA CONSTRUIR LA PESTAÑA "CELDAS"
  185. protected Component pestana3(String text)
  186. {
  187. p3A = new JPanel(new GridLayout(2,1)); // panel Principal
  188.                p3B = new JPanel(new BorderLayout());  //
  189. p3C = new JPanel(new BorderLayout());  //
  190. p3D = new JPanel(new GridLayout(1,3)); // panel para 3 botones en BorderLayout.SOUTH
  191. p3A.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
  192.  
  193. JTabbedPane subpestanas3 = new JTabbedPane();
  194. Component panel_subpestana31 = subpestana31("Mudanza de RCS");
  195. subpestanas3.addTab("Mudanza de RCS", panel_subpestana31);
  196. Component panel_subpestana32 = subpestana32("Crear Celda");
  197. subpestanas3.addTab("Crear Celda", panel_subpestana32);
  198. Component panel_subpestana33 = subpestana33("Borrar Celda");
  199. subpestanas3.addTab("Borrar Celda", panel_subpestana33);
  200. Component panel_subpestana34 = subpestana34("---");
  201. subpestanas3.addTab("---", panel_subpestana34);
  202. Component panel_subpestana35 = subpestana35("---");
  203. subpestanas3.addTab("---", panel_subpestana35);
  204.  
  205. texto3 = new JTextField(40);
  206. texto3.setFont(new java.awt.Font("Arial", Font.PLAIN, 12));
  207. texto3Inicio = "Escriba aquí un comando y haga click sobre el botón \"OK\"";
  208. texto3.setText(texto3Inicio);
  209.  
  210. areaTexto3 = new JTextArea(10,40);
  211. areaTexto3.setEditable(false);
  212. areaTexto3.setFont(new java.awt.Font("Arial", Font.PLAIN, 12));
  213. B = new Color(200,200,200);
  214. areaTexto3.setBackground(B);
  215. F1 = new Color(0,0,0);
  216. areaTexto3.setForeground(F1);
  217. JScrollPane pScroll3 = new JScrollPane(areaTexto3, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
  218.  
  219. btOK3 = new JButton("OK");
  220. btQuitar3 = new JButton("Limpiar pantalla");
  221. btSalir3 = new JButton("Salir");
  222.  
  223. texto3.addActionListener(new ejecutar());
  224. btOK3.addActionListener(new ejecutar());
  225. btQuitar3.addActionListener(new limpiarPantalla());
  226. btSalir3.addActionListener(new cerrarVentana());
  227.  
  228. p3A.add(p3B);
  229. p3A.add(p3C);
  230. p3B.add(subpestanas3);//agregar sub pestanas
  231. p3D.add(btOK3);
  232. p3D.add(btQuitar3);
  233. p3D.add(btSalir3);
  234. p3C.add(texto3,BorderLayout.NORTH);
  235. p3C.add(pScroll3, BorderLayout.CENTER);
  236. p3C.add(p3D, BorderLayout.SOUTH);
  237.  
  238. btOK3.setToolTipText("Ingresar Comando");
  239. btQuitar3.setToolTipText("Limpiar la Pantalla");
  240. btSalir3.setToolTipText("Salir de la aplicación");
  241.  
  242. return p3A;
  243. }
  244.  
  245. //********************************************************************************************************************************
  246. // METODO PARA CONSTRUIR LA PESTAÑA "MANTENIMIENTO"
  247. protected Component pestana4(String text)
  248. {
  249. p4A = new JPanel(new GridLayout(2,1)); // panel Principal
  250.                p4B = new JPanel(new BorderLayout());  //
  251. p4C = new JPanel(new BorderLayout());  //
  252. p4D = new JPanel(new GridLayout(1,3)); // panel para 3 botones en BorderLayout.SOUTH
  253. p4A.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
  254.  
  255. JTabbedPane subpestanas4 = new JTabbedPane();
  256. Component panel_subpestana41 = subpestana41("CKT OOS");
  257. subpestanas4.addTab("CKT OOS", panel_subpestana41);
  258. Component panel_subpestana42 = subpestana42("TST UPATH");
  259. subpestanas4.addTab("TST UPATH", panel_subpestana42);
  260. Component panel_subpestana43 = subpestana43("MEM  NRODD/RODD  SM's");
  261. subpestanas4.addTab("MEM  NRODD/RODD  SM's", panel_subpestana43);
  262. Component panel_subpestana44 = subpestana44("Información del Sistema");
  263. subpestanas4.addTab("Información del Sistema", panel_subpestana44);
  264. Component panel_subpestana45 = subpestana45("BACKUP's DE AP's");
  265. subpestanas4.addTab("BACKUP's DE AP's", panel_subpestana45);
  266. Component panel_subpestana46 = subpestana46("CHKLIST MTSO");
  267. subpestanas4.addTab("CHKLIST MTSO", panel_subpestana46);
  268.  
  269. texto4 = new JTextField(40);
  270. texto4.setFont(new java.awt.Font("Arial", Font.PLAIN, 12));
  271. texto4Inicio = "Escriba aquí un comando y haga click sobre el botón \"OK\"";
  272. texto4.setText(texto4Inicio);
  273.  
  274. areaTexto4 = new JTextArea(10,40);
  275. areaTexto4.setEditable(false);
  276. areaTexto4.setFont(new java.awt.Font("Arial", Font.PLAIN, 12));
  277. B = new Color(200,200,200);
  278. areaTexto4.setBackground(B);
  279. F1 = new Color(0,0,0);
  280. areaTexto4.setForeground(F1);
  281. JScrollPane pScroll4 = new JScrollPane(areaTexto4, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
  282.  
  283. btOK4 = new JButton("OK");
  284. btQuitar4 = new JButton("Limpiar pantalla");
  285. btSalir4 = new JButton("Salir");
  286.  
  287. texto4.addActionListener(new ejecutar());
  288. btOK4.addActionListener(new ejecutar());
  289. btQuitar4.addActionListener(new limpiarPantalla());
  290. btSalir4.addActionListener(new cerrarVentana());
  291.  
  292. p4A.add(p4B);
  293. p4A.add(p4C);
  294. p4B.add(subpestanas4);//agregar sub pestanas
  295. p4D.add(btOK4);
  296. p4D.add(btQuitar4);
  297. p4D.add(btSalir4);
  298. p4C.add(texto4,BorderLayout.NORTH);
  299. p4C.add(pScroll4, BorderLayout.CENTER);
  300. p4C.add(p4D, BorderLayout.SOUTH);
  301.  
  302. btOK4.setToolTipText("Ingresar Comando");
  303. btQuitar4.setToolTipText("Limpiar la Pantalla");
  304. btSalir4.setToolTipText("Salir de la aplicación");
  305.  
  306. return p4A;
  307. }
  308.  
  309. //********************************************************************************************************************************
  310. // METODO PARA CONSTRUIR LA SUBPESTAÑA "CREAR" DE "TRONCALES"
  311. protected Component subpestana11(String text)
  312. {
  313. JPanel panel = new JPanel(false);
  314. JLabel filler = new JLabel(text);
  315. filler.setHorizontalAlignment(JLabel.CENTER);
  316. panel.setLayout(new GridLayout(1, 1));
  317. panel.add(filler);
  318. return panel;
  319. }
  320. //********************************************************************************************************************************
  321. // METODO PARA CONSTRUIR LA SUBPESTAÑA "CRECER" DE "TRONCALES"
  322. protected Component subpestana12(String text)
  323. {
  324. JPanel panel = new JPanel(false);
  325. JLabel filler = new JLabel(text);
  326. filler.setHorizontalAlignment(JLabel.CENTER);
  327. panel.setLayout(new GridLayout(1, 1));
  328. panel.add(filler);
  329. return panel;
  330. }
  331. //********************************************************************************************************************************
  332. // METODO PARA CONSTRUIR LA SUBPESTAÑA "DECRECER" DE "TRONCALES"
  333. protected Component subpestana13(String text)
  334. {
  335. JPanel panel = new JPanel(false);
  336. JLabel filler = new JLabel(text);
  337. filler.setHorizontalAlignment(JLabel.CENTER);
  338. panel.setLayout(new GridLayout(1, 1));
  339. panel.add(filler);
  340. return panel;
  341. }
  342. //********************************************************************************************************************************
  343. // METODO PARA CONSTRUIR LA SUBPESTAÑA "ELIMINAR" DE "TRONCALES"
  344. protected Component subpestana14(String text)
  345. {
  346. JPanel panel = new JPanel(false);
  347. JLabel filler = new JLabel(text);
  348. filler.setHorizontalAlignment(JLabel.CENTER);
  349. panel.setLayout(new GridLayout(1, 1));
  350. panel.add(filler);
  351. return panel;
  352. }
  353. //********************************************************************************************************************************
  354. // METODO PARA CONSTRUIR LA SUBPESTAÑA "INCLUSION EN REPORTE TGCOMP" DE "TRONCALES"
  355. protected Component subpestana15(String text)
  356. {
  357. JPanel panel = new JPanel(false);
  358. JLabel filler = new JLabel(text);
  359. filler.setHorizontalAlignment(JLabel.CENTER);
  360. panel.setLayout(new GridLayout(1, 1));
  361. panel.add(filler);
  362. return panel;
  363. }
  364.  
  365. //********************************************************************************************************************************
  366. // METODO PARA CONSTRUIR LA SUBPESTAÑA "MUDANZA" DE "TRONCALES"
  367. protected Component subpestana16(String text)
  368. {
  369. JPanel panel = new JPanel(false);
  370. JLabel filler = new JLabel(text);
  371. filler.setHorizontalAlignment(JLabel.CENTER);
  372. panel.setLayout(new GridLayout(1, 1));
  373. panel.add(filler);
  374. return panel;
  375. }
  376.  
  377. //********************************************************************************************************************************
  378. // METODO PARA CONSTRUIR LA SUBPESTAÑA "MUDAR" DE "PACKET PIPES"
  379. protected Component subpestana21(String text)
  380. {
  381. JPanel panel = new JPanel(false);
  382. JLabel filler = new JLabel(text);
  383. filler.setHorizontalAlignment(JLabel.CENTER);
  384. panel.setLayout(new GridLayout(1, 1));
  385. panel.add(filler);
  386. return panel;
  387. }
  388. //********************************************************************************************************************************
  389. // METODO PARA CONSTRUIR LA SUBPESTAÑA "CRECER" DE "PACKET PIPES"
  390. protected Component subpestana22(String text)
  391. {
  392. JPanel panel = new JPanel(false);
  393. JLabel filler = new JLabel(text);
  394. filler.setHorizontalAlignment(JLabel.CENTER);
  395. panel.setLayout(new GridLayout(1, 1));
  396. panel.add(filler);
  397. return panel;
  398. }
  399. //********************************************************************************************************************************
  400. // METODO PARA CONSTRUIR LA SUBPESTAÑA "DECRECER" DE "PACKET PIPES"
  401. protected Component subpestana23(String text)
  402. {
  403. JPanel panel = new JPanel(false);
  404. JLabel filler = new JLabel(text);
  405. filler.setHorizontalAlignment(JLabel.CENTER);
  406. panel.setLayout(new GridLayout(1, 1));
  407. panel.add(filler);
  408. return panel;
  409. }
  410. //********************************************************************************************************************************
  411. // METODO PARA CONSTRUIR LA SUBPESTAÑA "EQUIPAR" DE "PACKET PIPES"
  412. protected Component subpestana24(String text)
  413. {
  414. JPanel panel = new JPanel(false);
  415. JLabel filler = new JLabel(text);
  416. filler.setHorizontalAlignment(JLabel.CENTER);
  417. panel.setLayout(new GridLayout(1, 1));
  418. panel.add(filler);
  419. return panel;
  420. }
  421.  
  422. //********************************************************************************************************************************
  423. // METODO PARA CONSTRUIR LA SUBPESTAÑA "DESEQUIPAR" DE "PACKET PIPES"
  424. protected Component subpestana25(String text)
  425. {
  426. JPanel panel = new JPanel(false);
  427. JLabel filler = new JLabel(text);
  428. filler.setHorizontalAlignment(JLabel.CENTER);
  429. panel.setLayout(new GridLayout(1, 1));
  430. panel.add(filler);
  431. return panel;
  432. }
  433.  
  434. //********************************************************************************************************************************
  435. // METODO PARA CONSTRUIR LA SUBPESTAÑA "MUDANZA DE RCS" DE "CELDAS"
  436. protected Component subpestana31(String text)
  437. {
  438. JPanel panel = new JPanel(false);
  439. JLabel filler = new JLabel(text);
  440. filler.setHorizontalAlignment(JLabel.CENTER);
  441. panel.setLayout(new GridLayout(1, 1));
  442. panel.add(filler);
  443. return panel;
  444. }
  445. //********************************************************************************************************************************
  446. // METODO PARA CONSTRUIR LA SUBPESTAÑA "CREAR" DE "CELDAS"
  447. protected Component subpestana32(String text)
  448. {
  449. JPanel panel = new JPanel(false);
  450. JLabel filler = new JLabel(text);
  451. filler.setHorizontalAlignment(JLabel.CENTER);
  452. panel.setLayout(new GridLayout(1, 1));
  453. panel.add(filler);
  454. return panel;
  455. }
  456. //********************************************************************************************************************************
  457. // METODO PARA CONSTRUIR LA SUBPESTAÑA "BORRAR" DE "CELDAS"
  458. protected Component subpestana33(String text)
  459. {
  460. JPanel panel = new JPanel(false);
  461. JLabel filler = new JLabel(text);
  462. filler.setHorizontalAlignment(JLabel.CENTER);
  463. panel.setLayout(new GridLayout(1, 1));
  464. panel.add(filler);
  465. return panel;
  466. }
  467. //********************************************************************************************************************************
  468. // METODO PARA CONSTRUIR LA SUBPESTAÑA "---" DE "CELDAS"
  469. protected Component subpestana34(String text)
  470. {
  471. JPanel panel = new JPanel(false);
  472. JLabel filler = new JLabel(text);
  473. filler.setHorizontalAlignment(JLabel.CENTER);
  474. panel.setLayout(new GridLayout(1, 1));
  475. panel.add(filler);
  476. return panel;
  477. }
  478.  
  479. //********************************************************************************************************************************
  480. // METODO PARA CONSTRUIR LA SUBPESTAÑA "---" DE "CELDAS"
  481. protected Component subpestana35(String text)
  482. {
  483. JPanel panel = new JPanel(false);
  484. JLabel filler = new JLabel(text);
  485. filler.setHorizontalAlignment(JLabel.CENTER);
  486. panel.setLayout(new GridLayout(1, 1));
  487. panel.add(filler);
  488. return panel;
  489. }
  490.  
  491. //********************************************************************************************************************************
  492. // METODO PARA CONSTRUIR LA SUBPESTAÑA "CKT OOS" DE "MANTENIMIENTO"
  493. protected Component subpestana41(String text)
  494. {
  495. JPanel panel = new JPanel(false);
  496. JLabel filler = new JLabel(text);
  497. filler.setHorizontalAlignment(JLabel.CENTER);
  498. panel.setLayout(new GridLayout(1, 1));
  499. panel.add(filler);
  500. return panel;
  501. }
  502. //********************************************************************************************************************************
  503. // METODO PARA CONSTRUIR LA SUBPESTAÑA "TST UPATH" DE "MANTENIMIENTO"
  504. protected Component subpestana42(String text)
  505. {
  506. JPanel panel = new JPanel(false);
  507. JLabel filler = new JLabel(text);
  508. filler.setHorizontalAlignment(JLabel.CENTER);
  509. panel.setLayout(new GridLayout(1, 1));
  510. panel.add(filler);
  511. return panel;
  512. }
  513. //********************************************************************************************************************************
  514. // METODO PARA CONSTRUIR LA SUBPESTAÑA "MEM NRODD/RODD SM's" DE "MANTENIMIENTO"
  515. protected Component subpestana43(String text)
  516. {
  517. JPanel panel = new JPanel(false);
  518. JLabel filler = new JLabel(text);
  519. filler.setHorizontalAlignment(JLabel.CENTER);
  520. panel.setLayout(new GridLayout(1, 1));
  521. panel.add(filler);
  522. return panel;
  523. }
  524. //********************************************************************************************************************************
  525. // METODO PARA CONSTRUIR LA SUBPESTAÑA "INFORMACION DEL SISTEMA" DE "MANTENIMIENTO"
  526. protected Component subpestana44(String text)
  527. {
  528. JPanel panel = new JPanel(false);
  529. JLabel filler = new JLabel(text);
  530. filler.setHorizontalAlignment(JLabel.CENTER);
  531. panel.setLayout(new GridLayout(1, 1));
  532. panel.add(filler);
  533. return panel;
  534. }
  535.  
  536. //********************************************************************************************************************************
  537. // METODO PARA CONSTRUIR LA SUBPESTAÑA "BACKUP's DE AP's" DE "MANTENIMIENTO"
  538. protected Component subpestana45(String text)
  539. {
  540. JPanel panel = new JPanel(false);
  541. JLabel filler = new JLabel(text);
  542. filler.setHorizontalAlignment(JLabel.CENTER);
  543. panel.setLayout(new GridLayout(1, 1));
  544. panel.add(filler);
  545. return panel;
  546. }
  547.  
  548. //********************************************************************************************************************************
  549. // METODO PARA CONSTRUIR LA SUBPESTAÑA "CHKLIST MTSO" DE "MANTENIMIENTO"
  550. protected Component subpestana46(String text)
  551. {
  552. JPanel panel = new JPanel(false);
  553. JLabel filler = new JLabel(text);
  554. filler.setHorizontalAlignment(JLabel.CENTER);
  555. panel.setLayout(new GridLayout(1, 1));
  556. panel.add(filler);
  557. return panel;
  558. }
  559.  
  560. //********************************************************************************************************************************
  561. // MÉTODO DE ENTRADA AL PROGRAMA
  562. public static void main(String[] args)
  563. {
  564. JFrame.setDefaultLookAndFeelDecorated(true);
  565. JFrame frame = new JFrame("Sistema de Gestión MTSO San Cristóbal");
  566. frame.getContentPane().add(new Main(), BorderLayout.CENTER);
  567. frame.setSize(1280, 770);
  568. frame.setVisible(true);
  569. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  570. }
  571.  
  572. //********************************************************************************************************************************
  573. // CLASE PARA MOSTRAR LAS SALIDAS DE LOS COMANDOS EN PANTALLA
  574. class ejecutar implements ActionListener
  575. {
  576. public void actionPerformed(ActionEvent evt)
  577. {
  578. String texto = texto1.getText();
  579.                        Runtime rt = Runtime.getRuntime();
  580. //String[] texto = {"date"};
  581. try
  582. {
  583. // Se lanza el ejecutable.
  584.                                Process p = rt.exec("cmd /c " + texto);            
  585. // Se obtiene el stream de salida del programa
  586. InputStream is = p.getInputStream();
  587. InputStream er = p.getErrorStream();
  588.                                OutputStream sal = p.getOutputStream();
  589.  
  590. // Se prepara un bufferedReader para poder leer la salida más
  591. // comodamente.
  592.                                BufferedWriter br3 = new BufferedWriter (new OutputStreamWriter (sal));
  593.  
  594. // Se lee la primera linea                                
  595. String aux = br.readLine();
  596. String aux2 = br2.readLine();
  597.                                br3.write("07-06-2007\n");
  598. //                              p.waitFor();
  599.  
  600.  
  601. // Mientras se haya leido alguna linea
  602. while (aux!=null)
  603. {
  604. // Se escribe la linea en pantalla
  605. areaTexto1.append(aux + newline);
  606. areaTexto1.setCaretPosition(areaTexto1.getDocument().getLength());
  607. texto1.setText("");
  608.  
  609. // y se lee la siguiente.
  610. aux = br.readLine();
  611. }
  612. while (aux2!=null)
  613. {
  614. areaTexto1.append(aux2 + newline);
  615. areaTexto1.setCaretPosition(areaTexto1.getDocument().getLength());
  616. texto1.setText("");
  617. aux2 = br2.readLine();
  618. }
  619. }
  620. catch (Exception e)
  621. {
  622. // Excepciones si hay algún problema al arrancar el ejecutable o al
  623. // leer su salida.
  624. e.printStackTrace();
  625. }
  626. }
  627. }
  628.  
  629. //********************************************************************************************************************************
  630. // CLASE QUE ACTIVA LA BANDERA DE ESCRITURA EN TEXT AREA
  631. class bdTroncales implements ActionListener
  632. {
  633. public void actionPerformed(ActionEvent evt)
  634. {
  635. bd1 = true;
  636. }
  637. }
  638.  
  639. //********************************************************************************************************************************
  640. // CLASE QUE VACÍA TEXTAREA
  641. class limpiarPantalla implements ActionListener
  642. {
  643. public void actionPerformed(ActionEvent evt)
  644. {
  645. texto1.setFont(new java.awt.Font("Arial", Font.PLAIN, 12));
  646. F3 = new Color(0,0,0);
  647. texto1.setForeground(F3);
  648. texto1.setText("");
  649. texto2.setText("");
  650. }
  651. }
  652.  
  653. //********************************************************************************************************************************
  654. // CLASE QUE SALE DEL PROGRAMA
  655. class cerrarVentana implements ActionListener
  656. {
  657. public void actionPerformed(ActionEvent evt)
  658. {
  659. System.exit(0);
  660. }
  661. }
  662.  
  663. //********************************************************************************************************************************
  664.  
  665.  
  666. } //FIN DE LA CLASE VENTANA
9  Programación / Java / Re: como usar Process.getOutputStream() en: 7 Junio 2007, 15:28 pm
hola... este es mi codigo... puedo ejecutar comandos como dir, cd, ipconfig, ping y me muestra la salida... pero con el comando date se queda pegado el programa...

como hago para enviarle la fecha al comando date desde la ventana grafica??? gracias

Código:
// Sistema de Gestión MTSO San Cristóbal
// Realizado por: Wilmer Rondón

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.Color;
import javax.swing.JTabbedPane;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JButton;
import java.io.*;
import java.lang.ProcessBuilder;

//********************************************************************************************************************************
// CLASE PRINCIPAL DEL PROGRAMA "VENTANA"
public class Main extends JPanel
{
protected Boolean bd1 = false, bd2 = false, bd3 = false, bd4 = false;
        protected JTextField texto1, texto2, texto3, texto4;
protected JTextArea areaTexto1, areaTexto2, areaTexto3, areaTexto4;
protected JPanel p1A, p1B, p1C, p1D, p2A, p2B, p2C, p2D, p3A, p3B, p3C, p3D, p4A, p4B, p4C, p4D;
protected JButton btOK1, btQuitar1, btSalir1, btOK2, btQuitar2, btSalir2, btOK3, btQuitar3, btSalir3, btOK4, btQuitar4, btSalir4;
protected String texto1Inicio, texto2Inicio, texto3Inicio, texto4Inicio;
protected Color B, F1, F2, F3;
protected int orden;
protected final static String newline = "\n";

//********************************************************************************************************************************
// CONSTRUCTOR DE LA CLASE VENTANA
public Main()
{
ImageIcon icon1 = new ImageIcon("images/ic_ringroad.jpg");
ImageIcon icon2 = new ImageIcon("images/ib_celtic.jpg");
ImageIcon icon3 = new ImageIcon("images/ic_patio.jpg");
ImageIcon icon4 = new ImageIcon("images/mante.jpg");

JTabbedPane pestanas = new JTabbedPane();

Component panel_pestana1 = pestana1("Pestana Uno");
pestanas.addTab("Troncales", icon1, panel_pestana1);
Component panel_pestana2 = pestana2("Pestana Dos");
pestanas.addTab("Packet Pipes", icon2, panel_pestana2);
Component panel_pestana3 = pestana3("Pestana Tres");
pestanas.addTab("Celdas", icon3, panel_pestana3);
Component panel_pestana4 = pestana4("Pestana Cuatro");
pestanas.addTab("Mantenimiento", icon4, panel_pestana4);

setLayout(new GridLayout(1, 1));
add(pestanas);
}

//********************************************************************************************************************************
// METODO PARA CONSTRUIR LA PESTAÑA "TRONCALES"
protected Component pestana1(String text)
{
p1A = new JPanel(new GridLayout(2,1)); // panel Principal
p1B = new JPanel(new BorderLayout());  //
p1C = new JPanel(new BorderLayout());  //
p1D = new JPanel(new GridLayout(1,3)); // panel para 3 botones en BorderLayout.SOUTH
p1A.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));

JTabbedPane subpestanas1 = new JTabbedPane();
Component panel_subpestana11 = subpestana11("Crear");
subpestanas1.addTab("Crear", panel_subpestana11);
Component panel_subpestana12 = subpestana12("Crecer");
subpestanas1.addTab("Crecer", panel_subpestana12);
Component panel_subpestana13 = subpestana13("Dedrecer");
subpestanas1.addTab("Dedrecer", panel_subpestana13);
Component panel_subpestana14 = subpestana14("Eliminar");
subpestanas1.addTab("Eliminar", panel_subpestana14);
Component panel_subpestana15 = subpestana15("Inclusión en Reporte TGCOM");
subpestanas1.addTab("Inclusión en Reporte TGCOMP", panel_subpestana15);
Component panel_subpestana16 = subpestana16("Mudanza");
subpestanas1.addTab("Mudanza", panel_subpestana16);

texto1 = new JTextField(40);
texto1.setFont(new java.awt.Font("Arial", Font.PLAIN, 12));
texto1Inicio = "Escriba aquí un comando y haga click sobre el botón \"OK\"";
texto1.setText(texto1Inicio);

areaTexto1 = new JTextArea(10,40);
areaTexto1.setEditable(false);
areaTexto1.setFont(new java.awt.Font("Arial", Font.PLAIN, 12));
B = new Color(200,200,200);
areaTexto1.setBackground(B);
F1 = new Color(0,0,0);
areaTexto1.setForeground(F1);
JScrollPane pScroll = new JScrollPane(areaTexto1, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);

btOK1 = new JButton("OK");
btQuitar1 = new JButton("Limpiar pantalla");
btSalir1 = new JButton("Salir");

texto1.addActionListener(new ejecutar());
btOK1.addActionListener(new ejecutar());
                btOK1.addActionListener(new bdTroncales());
btQuitar1.addActionListener(new limpiarPantalla());
btSalir1.addActionListener(new cerrarVentana());

p1A.add(p1B);
p1A.add(p1C);
p1B.add(subpestanas1);//agregar sub pestanas
p1D.add(btOK1);
p1D.add(btQuitar1);
p1D.add(btSalir1);
p1C.add(texto1,BorderLayout.NORTH);
p1C.add(pScroll, BorderLayout.CENTER);
p1C.add(p1D, BorderLayout.SOUTH);

btOK1.setToolTipText("Ingresar Comando");
btQuitar1.setToolTipText("Limpiar la Pantalla");
btSalir1.setToolTipText("Salir de la aplicación");

return p1A;

}

//********************************************************************************************************************************
// METODO PARA CONSTRUIR LA PESTAÑA "PACKET PIPES"
protected Component pestana2(String text)
{
p2A = new JPanel(new GridLayout(2,1)); // panel Principal
                p2B = new JPanel(new BorderLayout());  //
p2C = new JPanel(new BorderLayout());  //
p2D = new JPanel(new GridLayout(1,3)); // panel para 3 botones en BorderLayout.SOUTH
p2A.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));

JTabbedPane subpestanas2 = new JTabbedPane();
Component panel_subpestana21 = subpestana21("Mudar");
subpestanas2.addTab("Mudar", panel_subpestana21);
Component panel_subpestana22 = subpestana22("Crecer");
subpestanas2.addTab("Crecer", panel_subpestana22);
Component panel_subpestana23 = subpestana23("Dedrecer");
subpestanas2.addTab("Dedrecer", panel_subpestana23);
Component panel_subpestana24 = subpestana24("Equipar");
subpestanas2.addTab("Equipar", panel_subpestana24);
Component panel_subpestana25 = subpestana25("Desequipar");
subpestanas2.addTab("Desequipar", panel_subpestana25);

texto2 = new JTextField(40);
texto2.setFont(new java.awt.Font("Arial", Font.PLAIN, 12));
texto2Inicio = "Escriba aquí un comando y haga click sobre el botón \"OK\"";
texto2.setText(texto2Inicio);

areaTexto2 = new JTextArea(10,40);
areaTexto2.setEditable(false);
areaTexto2.setFont(new java.awt.Font("Arial", Font.PLAIN, 12));
B = new Color(200,200,200);
areaTexto2.setBackground(B);
F1 = new Color(0,0,0);
areaTexto2.setForeground(F1);
JScrollPane pScroll2 = new JScrollPane(areaTexto2, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);

btOK2 = new JButton("OK");
btQuitar2 = new JButton("Limpiar pantalla");
btSalir2 = new JButton("Salir");

texto2.addActionListener(new ejecutar());
btOK2.addActionListener(new ejecutar());
btQuitar2.addActionListener(new limpiarPantalla());
btSalir2.addActionListener(new cerrarVentana());

p2A.add(p2B);
p2A.add(p2C);
p2B.add(subpestanas2);//agregar sub pestanas
p2D.add(btOK2);
p2D.add(btQuitar2);
p2D.add(btSalir2);
p2C.add(texto2,BorderLayout.NORTH);
p2C.add(pScroll2, BorderLayout.CENTER);
p2C.add(p2D, BorderLayout.SOUTH);

btOK2.setToolTipText("Ingresar Comando");
btQuitar2.setToolTipText("Limpiar la Pantalla");
btSalir2.setToolTipText("Salir de la aplicación");

return p2A;
}

//********************************************************************************************************************************
// METODO PARA CONSTRUIR LA PESTAÑA "CELDAS"
protected Component pestana3(String text)
{
p3A = new JPanel(new GridLayout(2,1)); // panel Principal
                p3B = new JPanel(new BorderLayout());  //
p3C = new JPanel(new BorderLayout());  //
p3D = new JPanel(new GridLayout(1,3)); // panel para 3 botones en BorderLayout.SOUTH
p3A.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));

JTabbedPane subpestanas3 = new JTabbedPane();
Component panel_subpestana31 = subpestana31("Mudanza de RCS");
subpestanas3.addTab("Mudanza de RCS", panel_subpestana31);
Component panel_subpestana32 = subpestana32("Crear Celda");
subpestanas3.addTab("Crear Celda", panel_subpestana32);
Component panel_subpestana33 = subpestana33("Borrar Celda");
subpestanas3.addTab("Borrar Celda", panel_subpestana33);
Component panel_subpestana34 = subpestana34("---");
subpestanas3.addTab("---", panel_subpestana34);
Component panel_subpestana35 = subpestana35("---");
subpestanas3.addTab("---", panel_subpestana35);

texto3 = new JTextField(40);
texto3.setFont(new java.awt.Font("Arial", Font.PLAIN, 12));
texto3Inicio = "Escriba aquí un comando y haga click sobre el botón \"OK\"";
texto3.setText(texto3Inicio);

areaTexto3 = new JTextArea(10,40);
areaTexto3.setEditable(false);
areaTexto3.setFont(new java.awt.Font("Arial", Font.PLAIN, 12));
B = new Color(200,200,200);
areaTexto3.setBackground(B);
F1 = new Color(0,0,0);
areaTexto3.setForeground(F1);
JScrollPane pScroll3 = new JScrollPane(areaTexto3, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);

btOK3 = new JButton("OK");
btQuitar3 = new JButton("Limpiar pantalla");
btSalir3 = new JButton("Salir");

texto3.addActionListener(new ejecutar());
btOK3.addActionListener(new ejecutar());
btQuitar3.addActionListener(new limpiarPantalla());
btSalir3.addActionListener(new cerrarVentana());

p3A.add(p3B);
p3A.add(p3C);
p3B.add(subpestanas3);//agregar sub pestanas
p3D.add(btOK3);
p3D.add(btQuitar3);
p3D.add(btSalir3);
p3C.add(texto3,BorderLayout.NORTH);
p3C.add(pScroll3, BorderLayout.CENTER);
p3C.add(p3D, BorderLayout.SOUTH);

btOK3.setToolTipText("Ingresar Comando");
btQuitar3.setToolTipText("Limpiar la Pantalla");
btSalir3.setToolTipText("Salir de la aplicación");

return p3A;
}

//********************************************************************************************************************************
// METODO PARA CONSTRUIR LA PESTAÑA "MANTENIMIENTO"
protected Component pestana4(String text)
{
p4A = new JPanel(new GridLayout(2,1)); // panel Principal
                p4B = new JPanel(new BorderLayout());  //
p4C = new JPanel(new BorderLayout());  //
p4D = new JPanel(new GridLayout(1,3)); // panel para 3 botones en BorderLayout.SOUTH
p4A.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));

JTabbedPane subpestanas4 = new JTabbedPane();
Component panel_subpestana41 = subpestana41("CKT OOS");
subpestanas4.addTab("CKT OOS", panel_subpestana41);
Component panel_subpestana42 = subpestana42("TST UPATH");
subpestanas4.addTab("TST UPATH", panel_subpestana42);
Component panel_subpestana43 = subpestana43("MEM  NRODD/RODD  SM's");
subpestanas4.addTab("MEM  NRODD/RODD  SM's", panel_subpestana43);
Component panel_subpestana44 = subpestana44("Información del Sistema");
subpestanas4.addTab("Información del Sistema", panel_subpestana44);
Component panel_subpestana45 = subpestana45("BACKUP's DE AP's");
subpestanas4.addTab("BACKUP's DE AP's", panel_subpestana45);
Component panel_subpestana46 = subpestana46("CHKLIST MTSO");
subpestanas4.addTab("CHKLIST MTSO", panel_subpestana46);

texto4 = new JTextField(40);
texto4.setFont(new java.awt.Font("Arial", Font.PLAIN, 12));
texto4Inicio = "Escriba aquí un comando y haga click sobre el botón \"OK\"";
texto4.setText(texto4Inicio);

areaTexto4 = new JTextArea(10,40);
areaTexto4.setEditable(false);
areaTexto4.setFont(new java.awt.Font("Arial", Font.PLAIN, 12));
B = new Color(200,200,200);
areaTexto4.setBackground(B);
F1 = new Color(0,0,0);
areaTexto4.setForeground(F1);
JScrollPane pScroll4 = new JScrollPane(areaTexto4, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);

btOK4 = new JButton("OK");
btQuitar4 = new JButton("Limpiar pantalla");
btSalir4 = new JButton("Salir");

texto4.addActionListener(new ejecutar());
btOK4.addActionListener(new ejecutar());
btQuitar4.addActionListener(new limpiarPantalla());
btSalir4.addActionListener(new cerrarVentana());

p4A.add(p4B);
p4A.add(p4C);
p4B.add(subpestanas4);//agregar sub pestanas
p4D.add(btOK4);
p4D.add(btQuitar4);
p4D.add(btSalir4);
p4C.add(texto4,BorderLayout.NORTH);
p4C.add(pScroll4, BorderLayout.CENTER);
p4C.add(p4D, BorderLayout.SOUTH);

btOK4.setToolTipText("Ingresar Comando");
btQuitar4.setToolTipText("Limpiar la Pantalla");
btSalir4.setToolTipText("Salir de la aplicación");

return p4A;
}

//********************************************************************************************************************************
// METODO PARA CONSTRUIR LA SUBPESTAÑA "CREAR" DE "TRONCALES"
protected Component subpestana11(String text)
{
JPanel panel = new JPanel(false);
JLabel filler = new JLabel(text);
filler.setHorizontalAlignment(JLabel.CENTER);
panel.setLayout(new GridLayout(1, 1));
panel.add(filler);
return panel;
}
//********************************************************************************************************************************
// METODO PARA CONSTRUIR LA SUBPESTAÑA "CRECER" DE "TRONCALES"
protected Component subpestana12(String text)
{
JPanel panel = new JPanel(false);
JLabel filler = new JLabel(text);
filler.setHorizontalAlignment(JLabel.CENTER);
panel.setLayout(new GridLayout(1, 1));
panel.add(filler);
return panel;
}
//********************************************************************************************************************************
// METODO PARA CONSTRUIR LA SUBPESTAÑA "DECRECER" DE "TRONCALES"
protected Component subpestana13(String text)
{
JPanel panel = new JPanel(false);
JLabel filler = new JLabel(text);
filler.setHorizontalAlignment(JLabel.CENTER);
panel.setLayout(new GridLayout(1, 1));
panel.add(filler);
return panel;
}
//********************************************************************************************************************************
// METODO PARA CONSTRUIR LA SUBPESTAÑA "ELIMINAR" DE "TRONCALES"
protected Component subpestana14(String text)
{
JPanel panel = new JPanel(false);
JLabel filler = new JLabel(text);
filler.setHorizontalAlignment(JLabel.CENTER);
panel.setLayout(new GridLayout(1, 1));
panel.add(filler);
return panel;
}
//********************************************************************************************************************************
// METODO PARA CONSTRUIR LA SUBPESTAÑA "INCLUSION EN REPORTE TGCOMP" DE "TRONCALES"
protected Component subpestana15(String text)
{
JPanel panel = new JPanel(false);
JLabel filler = new JLabel(text);
filler.setHorizontalAlignment(JLabel.CENTER);
panel.setLayout(new GridLayout(1, 1));
panel.add(filler);
return panel;
}

//********************************************************************************************************************************
// METODO PARA CONSTRUIR LA SUBPESTAÑA "MUDANZA" DE "TRONCALES"
protected Component subpestana16(String text)
{
JPanel panel = new JPanel(false);
JLabel filler = new JLabel(text);
filler.setHorizontalAlignment(JLabel.CENTER);
panel.setLayout(new GridLayout(1, 1));
panel.add(filler);
return panel;
}

//********************************************************************************************************************************
// METODO PARA CONSTRUIR LA SUBPESTAÑA "MUDAR" DE "PACKET PIPES"
protected Component subpestana21(String text)
{
JPanel panel = new JPanel(false);
JLabel filler = new JLabel(text);
filler.setHorizontalAlignment(JLabel.CENTER);
panel.setLayout(new GridLayout(1, 1));
panel.add(filler);
return panel;
}
//********************************************************************************************************************************
// METODO PARA CONSTRUIR LA SUBPESTAÑA "CRECER" DE "PACKET PIPES"
protected Component subpestana22(String text)
{
JPanel panel = new JPanel(false);
JLabel filler = new JLabel(text);
filler.setHorizontalAlignment(JLabel.CENTER);
panel.setLayout(new GridLayout(1, 1));
panel.add(filler);
return panel;
}
//********************************************************************************************************************************
// METODO PARA CONSTRUIR LA SUBPESTAÑA "DECRECER" DE "PACKET PIPES"
protected Component subpestana23(String text)
{
JPanel panel = new JPanel(false);
JLabel filler = new JLabel(text);
filler.setHorizontalAlignment(JLabel.CENTER);
panel.setLayout(new GridLayout(1, 1));
panel.add(filler);
return panel;
}
//********************************************************************************************************************************
// METODO PARA CONSTRUIR LA SUBPESTAÑA "EQUIPAR" DE "PACKET PIPES"
protected Component subpestana24(String text)
{
JPanel panel = new JPanel(false);
JLabel filler = new JLabel(text);
filler.setHorizontalAlignment(JLabel.CENTER);
panel.setLayout(new GridLayout(1, 1));
panel.add(filler);
return panel;
}

//********************************************************************************************************************************
// METODO PARA CONSTRUIR LA SUBPESTAÑA "DESEQUIPAR" DE "PACKET PIPES"
protected Component subpestana25(String text)
{
JPanel panel = new JPanel(false);
JLabel filler = new JLabel(text);
filler.setHorizontalAlignment(JLabel.CENTER);
panel.setLayout(new GridLayout(1, 1));
panel.add(filler);
return panel;
}

//********************************************************************************************************************************
// METODO PARA CONSTRUIR LA SUBPESTAÑA "MUDANZA DE RCS" DE "CELDAS"
protected Component subpestana31(String text)
{
JPanel panel = new JPanel(false);
JLabel filler = new JLabel(text);
filler.setHorizontalAlignment(JLabel.CENTER);
panel.setLayout(new GridLayout(1, 1));
panel.add(filler);
return panel;
}
//********************************************************************************************************************************
// METODO PARA CONSTRUIR LA SUBPESTAÑA "CREAR" DE "CELDAS"
protected Component subpestana32(String text)
{
JPanel panel = new JPanel(false);
JLabel filler = new JLabel(text);
filler.setHorizontalAlignment(JLabel.CENTER);
panel.setLayout(new GridLayout(1, 1));
panel.add(filler);
return panel;
}
//********************************************************************************************************************************
// METODO PARA CONSTRUIR LA SUBPESTAÑA "BORRAR" DE "CELDAS"
protected Component subpestana33(String text)
{
JPanel panel = new JPanel(false);
JLabel filler = new JLabel(text);
filler.setHorizontalAlignment(JLabel.CENTER);
panel.setLayout(new GridLayout(1, 1));
panel.add(filler);
return panel;
}
//********************************************************************************************************************************
// METODO PARA CONSTRUIR LA SUBPESTAÑA "---" DE "CELDAS"
protected Component subpestana34(String text)
{
JPanel panel = new JPanel(false);
JLabel filler = new JLabel(text);
filler.setHorizontalAlignment(JLabel.CENTER);
panel.setLayout(new GridLayout(1, 1));
panel.add(filler);
return panel;
}

//********************************************************************************************************************************
// METODO PARA CONSTRUIR LA SUBPESTAÑA "---" DE "CELDAS"
protected Component subpestana35(String text)
{
JPanel panel = new JPanel(false);
JLabel filler = new JLabel(text);
filler.setHorizontalAlignment(JLabel.CENTER);
panel.setLayout(new GridLayout(1, 1));
panel.add(filler);
return panel;
}

//********************************************************************************************************************************
// METODO PARA CONSTRUIR LA SUBPESTAÑA "CKT OOS" DE "MANTENIMIENTO"
protected Component subpestana41(String text)
{
JPanel panel = new JPanel(false);
JLabel filler = new JLabel(text);
filler.setHorizontalAlignment(JLabel.CENTER);
panel.setLayout(new GridLayout(1, 1));
panel.add(filler);
return panel;
}
//********************************************************************************************************************************
// METODO PARA CONSTRUIR LA SUBPESTAÑA "TST UPATH" DE "MANTENIMIENTO"
protected Component subpestana42(String text)
{
JPanel panel = new JPanel(false);
JLabel filler = new JLabel(text);
filler.setHorizontalAlignment(JLabel.CENTER);
panel.setLayout(new GridLayout(1, 1));
panel.add(filler);
return panel;
}
//********************************************************************************************************************************
// METODO PARA CONSTRUIR LA SUBPESTAÑA "MEM NRODD/RODD SM's" DE "MANTENIMIENTO"
protected Component subpestana43(String text)
{
JPanel panel = new JPanel(false);
JLabel filler = new JLabel(text);
filler.setHorizontalAlignment(JLabel.CENTER);
panel.setLayout(new GridLayout(1, 1));
panel.add(filler);
return panel;
}
//********************************************************************************************************************************
// METODO PARA CONSTRUIR LA SUBPESTAÑA "INFORMACION DEL SISTEMA" DE "MANTENIMIENTO"
protected Component subpestana44(String text)
{
JPanel panel = new JPanel(false);
JLabel filler = new JLabel(text);
filler.setHorizontalAlignment(JLabel.CENTER);
panel.setLayout(new GridLayout(1, 1));
panel.add(filler);
return panel;
}

//********************************************************************************************************************************
// METODO PARA CONSTRUIR LA SUBPESTAÑA "BACKUP's DE AP's" DE "MANTENIMIENTO"
protected Component subpestana45(String text)
{
JPanel panel = new JPanel(false);
JLabel filler = new JLabel(text);
filler.setHorizontalAlignment(JLabel.CENTER);
panel.setLayout(new GridLayout(1, 1));
panel.add(filler);
return panel;
}

//********************************************************************************************************************************
// METODO PARA CONSTRUIR LA SUBPESTAÑA "CHKLIST MTSO" DE "MANTENIMIENTO"
protected Component subpestana46(String text)
{
JPanel panel = new JPanel(false);
JLabel filler = new JLabel(text);
filler.setHorizontalAlignment(JLabel.CENTER);
panel.setLayout(new GridLayout(1, 1));
panel.add(filler);
return panel;
}

//********************************************************************************************************************************
// MÉTODO DE ENTRADA AL PROGRAMA
public static void main(String[] args)
{
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame frame = new JFrame("Sistema de Gestión MTSO San Cristóbal");
frame.getContentPane().add(new Main(), BorderLayout.CENTER);
frame.setSize(1280, 770);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

//********************************************************************************************************************************
// CLASE PARA MOSTRAR LAS SALIDAS DE LOS COMANDOS EN PANTALLA
class ejecutar implements ActionListener
{
public void actionPerformed(ActionEvent evt)
{
String texto = texto1.getText();
                        Runtime rt = Runtime.getRuntime();
//String[] texto = {"date"};
try
{
// Se lanza el ejecutable.
                                Process p = rt.exec("cmd /c " + texto);           
// Se obtiene el stream de salida del programa
InputStream is = p.getInputStream();
InputStream er = p.getErrorStream();
                                OutputStream sal = p.getOutputStream();
           
// Se prepara un bufferedReader para poder leer la salida más
// comodamente.
BufferedReader br = new BufferedReader (new InputStreamReader (is));
BufferedReader br2 = new BufferedReader (new InputStreamReader (er));
                                BufferedWriter br3 = new BufferedWriter (new OutputStreamWriter (sal));
           
// Se lee la primera linea                               
String aux = br.readLine();
String aux2 = br2.readLine();
                                br3.write("07-06-2007\n");
//                              p.waitFor();
                               
                               
// Mientras se haya leido alguna linea
while (aux!=null)
{
// Se escribe la linea en pantalla
areaTexto1.append(aux + newline);
areaTexto1.setCaretPosition(areaTexto1.getDocument().getLength());
texto1.setText("");
               
// y se lee la siguiente.
aux = br.readLine();
}
while (aux2!=null)
{
areaTexto1.append(aux2 + newline);
areaTexto1.setCaretPosition(areaTexto1.getDocument().getLength());
texto1.setText("");
aux2 = br2.readLine();
}
}
catch (Exception e)
{
// Excepciones si hay algún problema al arrancar el ejecutable o al
// leer su salida.
e.printStackTrace();
}
}
}

//********************************************************************************************************************************
// CLASE QUE ACTIVA LA BANDERA DE ESCRITURA EN TEXT AREA
class bdTroncales implements ActionListener
{
public void actionPerformed(ActionEvent evt)
{
bd1 = true;
}
}
       
//********************************************************************************************************************************
// CLASE QUE VACÍA TEXTAREA
class limpiarPantalla implements ActionListener
{
public void actionPerformed(ActionEvent evt)
{
texto1.setFont(new java.awt.Font("Arial", Font.PLAIN, 12));
F3 = new Color(0,0,0);
texto1.setForeground(F3);
texto1.setText("");
texto2.setText("");
}
}

//********************************************************************************************************************************
// CLASE QUE SALE DEL PROGRAMA
class cerrarVentana implements ActionListener
{
public void actionPerformed(ActionEvent evt)
{
System.exit(0);
}
}
10  Programación / Java / Re: como usar Process.getOutputStream() en: 6 Junio 2007, 23:36 pm
gracias por tu respuesta... la verdad no tengo mucho programando y lo que llevo hecho ha sido guiandome por codigos de ejemplo que he visto en la red... voy a tratar de hacer algo con los tips que me diste.. gracias
Páginas: [1] 2
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines