From @Carr, 4 Days ago, written in Java.
Embed
  1. /**
  2.  * @CArr
  3.  * 9-11-19
  4.  */
  5. import java.awt.Font;
  6. import java.awt.Graphics;
  7. import java.awt.Color;
  8. import java.awt.Container;
  9. import javax.swing.JFrame;
  10. import javax.swing.JPanel;
  11. import javax.swing.Timer;
  12. import java.awt.event.ActionListener;
  13. import java.awt.event.ActionEvent;
  14.  
  15. public class Banner extends JPanel
  16.                  implements ActionListener
  17. {
  18.   private int xPos, yPos;  // hold the coordinates of the message
  19.  
  20.   // Called automatically after a repaint request
  21.   public void paintComponent(Graphics g)
  22.   {
  23.     super.paintComponent(g); // Paint the background
  24.     g.setColor(Color.RED);
  25.     g.drawString("Hello, Action!", xPos, yPos);
  26.   }
  27.  
  28.   // Called automatically when the timer "fires"
  29.   public void actionPerformed(ActionEvent e)
  30.   {
  31.     // Adjust the horizontal position of the message:
  32.     xPos--;  // subtract 1
  33.     if (xPos < -100)
  34.       xPos = getWidth();
  35.  
  36.     repaint();
  37.   }
  38.  
  39.   public static void main(String[] args)
  40.   {
  41.     JFrame window = new JFrame("Action Demo");
  42.  
  43.     // Set this window's location and size:
  44.     // upper-left corner at 300, 300; width 300, height 100
  45.     window.setBounds(300, 300, 300, 100);
  46.  
  47.     //  Create panel, a Banner object, which is a kind of JPanel:
  48.     Banner panel = new Banner();
  49.     panel.setBackground(Color.CYAN);  // the default color is light gray
  50.  
  51.     // Add panel to window:
  52.     Container c = window.getContentPane();
  53.     c.add(panel);
  54.  
  55.     window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  56.     window.setVisible(true);
  57.  
  58.     // Set the initial position of the message:
  59.     panel.xPos = panel.getWidth();
  60.     panel.yPos = panel.getHeight() / 2;
  61.  
  62.     // Create a Timer object that fires every 30 milliseconds;
  63.     // attach it to panel so that panel "listens to" and
  64.     // processes the timer events; start the timer:
  65.     Timer clock = new Timer(30, panel);
  66.     clock.start();
  67.   }
  68. }
  69.