Guest User

Untitled

a guest
Apr 25th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. import java.awt.EventQueue;
  2.  
  3. import javax.swing.JFrame;
  4. import javax.swing.JLabel;
  5. import javax.swing.JButton;
  6. import java.awt.event.ActionListener;
  7. import java.awt.event.ActionEvent;
  8.  
  9. public class pruebaText {
  10.  
  11. private JFrame frame;
  12. private JLabel lblText;
  13. int cont = 0;
  14. private JLabel lblText5;
  15.  
  16. /**
  17. * Launch the application.
  18. */
  19. public static void main(String[] args) {
  20. EventQueue.invokeLater(new Runnable() {
  21. public void run() {
  22. try {
  23. pruebaText window = new pruebaText();
  24. window.frame.setVisible(true);
  25. } catch (Exception e) {
  26. e.printStackTrace();
  27. }
  28. }
  29. });
  30. }
  31.  
  32. /**
  33. * Create the application.
  34. */
  35. public pruebaText() {
  36. initialize();
  37.  
  38. }
  39.  
  40. /**
  41. * Initialize the contents of the frame.
  42. */
  43. private void initialize() {
  44. frame = new JFrame();
  45. frame.setBounds(100, 100, 450, 300);
  46. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  47. frame.getContentPane().setLayout(null);
  48.  
  49. lblText = new JLabel("");
  50. lblText.setBounds(89, 66, 46, 14);
  51. frame.getContentPane().add(lblText);
  52.  
  53. JButton btnNewButton = new JButton("New button");
  54. btnNewButton.addActionListener(new ActionListener() {
  55. public void actionPerformed(ActionEvent e) {
  56. try{
  57. while (cont<10) {
  58. Thread.sleep(1000);
  59. cont++;
  60. System.out.println(cont);
  61. if (cont==5) {
  62. lblText.setText("hola");
  63. }
  64. }
  65.  
  66. }catch (Exception e1) {
  67. // TODO: handle exception
  68. System.out.println(e1);
  69. }
  70. }
  71.  
  72. });
  73. btnNewButton.setBounds(89, 197, 89, 23);
  74. frame.getContentPane().add(btnNewButton);
  75.  
  76. lblText5 = new JLabel("");
  77. lblText5.setBounds(341, 38, 46, 14);
  78. frame.getContentPane().add(lblText5);
  79. }
  80. }
  81.  
  82. public static void mostarTexto() {
  83. for (int i = 0; i < 10; i++) {
  84. try {
  85. Thread.sleep(1000);
  86. //Para ver la evulocion de i en Console de eclipe
  87. System.out.println(i);
  88.  
  89. if (i / 2 == 0) {
  90. lblTexto.setText("hola");
  91. } else {
  92. lblTexto.setText(" ");
  93. }
  94. } catch (InterruptedException e) {
  95. // TODO Auto-generated catch block
  96. e.printStackTrace();
  97. }
  98.  
  99. }
  100.  
  101. }
Add Comment
Please, Sign In to add comment