Full width home advertisement

HTML

Tech News

Ad

  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package clgPracticals;
  7.  
  8. import java.awt.Color;
  9. import java.awt.Dimension;
  10. import java.awt.Font;
  11. import java.awt.Frame;
  12. import java.awt.Graphics;
  13. import java.awt.event.WindowAdapter;
  14. import java.awt.event.WindowEvent;
  15.  
  16. /**
  17.  *
  18.  * @author smit
  19.  */
  20. class MyFrame extends Frame implements Runnable {
  21.  
  22. Thread t;
  23. int c, m = 1, x;
  24. Dimension d;
  25.  
  26. MyFrame() {
  27. t = new Thread(this);
  28. setSize(500, 500);
  29. d = getSize();
  30. c = 0;
  31. x = 0;
  32. t.start();
  33. addWindowListener(new WindowAdapter() {
  34. public void windowActivated(WindowEvent we) {
  35. t.resume();
  36. }
  37.  
  38. public void windowDeactivated(WindowEvent we) {
  39. t.suspend();
  40. }
  41.  
  42. public void windowClosing(WindowEvent we) {
  43. dispose();
  44. }
  45. });
  46. setVisible(true);
  47. }
  48.  
  49. public void run() {
  50. try {
  51. while (true) {
  52. Thread.sleep(100);
  53. repaint();
  54. }
  55. } catch (Exception a) {
  56. }
  57. }
  58.  
  59. public void paint(Graphics g) {
  60. if (m == 1) {
  61.  
  62. g.setColor(Color.darkGray);
  63. g.drawString("Hello", x, 250);
  64. x += 5;
  65. if (x >= d.width) {
  66. m = 0;
  67. }
  68. }
  69. if (m == 0) {
  70. g.setColor(Color.black);
  71. g.drawString("Hello", x, 250);
  72. x -= 5;
  73. if (x - 10 < 0) {
  74. m = 1;
  75. }
  76. }
  77. }
  78. }
  79.  
  80. class PR15 {
  81.  
  82. public static void main(String[] args) {
  83. MyFrame fr = new MyFrame();
  84. }
  85. }
  86.  

No comments:

Post a Comment

Bottom Ad [Post Page]