Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 12th, 2012  |  syntax: None  |  size: 27.09 KB  |  hits: 18  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Passing current Date
  2. import java.awt.*;
  3. import java.awt.event.ActionEvent;
  4. import java.awt.event.ActionListener;
  5. import java.awt.image.BufferedImage;
  6. import java.util.ArrayList;
  7. import java.util.Random;
  8. import java.util.Vector;
  9. import java.util.regex.Pattern;
  10. import javax.swing.*;
  11. import javax.swing.table.*;
  12.  
  13. public class OneTwoThree implements Runnable {
  14.  
  15.     private String testS;
  16.     private JFrame frame = new JFrame("frameTitle");
  17.     private JScrollPane tblS = new JScrollPane();
  18.     private JTable tbl;
  19.     private Vector<String> rOrH;
  20.     private long t1 = 0L;
  21.     private long t2 = 0L;
  22.     private AlphaChars aChars = new AlphaChars();
  23.     private GradientViewPortOriginal tableViewPort;
  24.     private JViewport viewport = new JViewport();
  25.     private Random random = new Random();
  26.     private Vector<Vector<Integer>> vec = new Vector<Vector<Integer>>();
  27.     private boolean bolo = false;
  28.  
  29.     public OneTwoThree() {
  30.         t1 = System.currentTimeMillis();
  31.         int regLenght = 3500;
  32.         int chars = 0;
  33.         testS = aChars.getNext(regLenght);
  34.         rOrH = new Vector<String>();
  35.         Vector<Vector<String>> rowD = new Vector<Vector<String>>();
  36.         for (int e = 0; e < regLenght;) {
  37.             chars++;
  38.             if (chars > 50) {
  39.                 chars = 1;
  40.                 rowD.add(rOrH);
  41.                 rOrH = new Vector<String>();
  42.             }
  43.             String str = (testS.substring(e, (e + 1))).toString();
  44.             if (str != null) {
  45.                 rOrH.add(str);
  46.             } else {
  47.                 rOrH.add("");
  48.             }
  49.             e++;
  50.         }
  51.         rOrH = new Vector<String>();
  52.         for (int i = 0; i < 50; i++) {
  53.             rOrH.add(String.valueOf(i + 1));
  54.         }
  55.         tbl = new JTable(rowD, rOrH);
  56.         TableColumnModel tcm = tbl.getColumnModel();
  57.         for (int i = 0; i < (tcm.getColumnCount()); i++) {
  58.             tcm.getColumn(i).setPreferredWidth(4);
  59.         }
  60.         tbl.setGridColor(tbl.getBackground());
  61.         tbl.setRowHeight(10);
  62.         tbl.setTableHeader(null);
  63.         tbl.setPreferredScrollableViewportSize(tbl.getPreferredSize());
  64.         tbl.setRowSelectionAllowed(false);
  65.         tbl.setColumnSelectionAllowed(false);
  66.         tableViewPort = new GradientViewPortOriginal(tbl);
  67.         viewport = tableViewPort.getViewport();
  68.         RepaintManager.setCurrentManager(new RepaintManager() {
  69.  
  70.             @Override
  71.             public void addDirtyRegion(JComponent c, int x, int y, int w, int h) {
  72.                 Container con = c.getParent();
  73.                 while (con instanceof JComponent) {
  74.                     if (!con.isVisible()) {
  75.                         return;
  76.                     }
  77.                     if (con instanceof GradientViewPortOriginal) {
  78.                         c = (JComponent) con;
  79.                         x = 0;
  80.                         y = 0;
  81.                         w = con.getWidth();
  82.                         h = con.getHeight();
  83.                     }
  84.                     con = con.getParent();
  85.                 }
  86.                 super.addDirtyRegion(c, x, y, w, h);
  87.             }
  88.         });
  89.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  90.         frame.add(tableViewPort, BorderLayout.CENTER);
  91.         frame.setLocation(20, 20);
  92.         frame.pack();
  93.         frame.setVisible(true);
  94.         addColumnRenderes();
  95.         for (int i = 0; i < 35; i++) {
  96.             Star star = new Star(new Point(random.nextInt(490), random.nextInt(490)));
  97.             star.setColor(new Color(100 + random.nextInt(155), 100 + random.nextInt(155), 100 + random.nextInt(155)));
  98.             star.setxIncr(-3 + random.nextInt(7));
  99.             star.setyIncr(-3 + random.nextInt(7));
  100.             tableViewPort.add(star);
  101.         }
  102.     }
  103.  
  104.     private void addColumnRenderes() {
  105.         for (int i = 0; i < tbl.getColumnCount(); i++) {
  106.             RowColorRenderer rowRenderer = new RowColorRenderer(i);
  107.             TableColumn column = tbl.getColumnModel().getColumn(i);
  108.             column.setCellRenderer(rowRenderer);
  109.         }
  110.         addTableData();
  111.     }
  112.  
  113.     private void addTableData() {
  114.         tbl.setValueAt("8", 4, 25);tbl.setValueAt("4", 5, 24);tbl.setValueAt("1", 5, 25);tbl.setValueAt("4", 5, 26);
  115.         tbl.setValueAt("4", 6, 23);tbl.setValueAt("4", 6, 25);tbl.setValueAt("1", 6, 26);tbl.setValueAt("4", 6, 27);
  116.         tbl.setValueAt("1", 6, 28);tbl.setValueAt("1", 7, 21);tbl.setValueAt("4", 7, 22);tbl.setValueAt("1", 7, 23);
  117.         tbl.setValueAt("4", 7, 24);tbl.setValueAt("1", 7, 27);tbl.setValueAt("8", 7, 28);tbl.setValueAt("4", 8, 23);
  118.         tbl.setValueAt("1", 8, 24);tbl.setValueAt("1", 8, 25);tbl.setValueAt("8", 8, 26);tbl.setValueAt("8", 8, 27);
  119.         tbl.setValueAt("7", 9, 24);tbl.setValueAt("1", 9, 26);tbl.setValueAt("4", 9, 25);tbl.setValueAt("4", 10, 24);
  120.         tbl.setValueAt("1", 10, 25);tbl.setValueAt("8", 10, 26);tbl.setValueAt("4", 11, 23);tbl.setValueAt("4", 11, 27);
  121.         tbl.setValueAt("1", 12, 21);tbl.setValueAt("4", 12, 22);tbl.setValueAt("8", 12, 28);tbl.setValueAt("4", 13, 21);
  122.         tbl.setValueAt("8", 13, 29);tbl.setValueAt("1", 14, 19);tbl.setValueAt("4", 14, 20);tbl.setValueAt("8", 14, 30);
  123.         tbl.setValueAt("4", 15, 19);tbl.setValueAt("4", 15, 20);tbl.setValueAt("4", 15, 21);tbl.setValueAt("1", 15, 22);
  124.         tbl.setValueAt("4", 15, 23);tbl.setValueAt("1", 15, 31);tbl.setValueAt("1", 15, 32);tbl.setValueAt("4", 16, 22);
  125.         tbl.setValueAt("4", 17, 21);tbl.setValueAt("4", 18, 20);tbl.setValueAt("4", 19, 20);tbl.setValueAt("4", 20, 19);
  126.         tbl.setValueAt("4", 21, 17);tbl.setValueAt("4", 21, 18);tbl.setValueAt("4", 22, 16);tbl.setValueAt("4", 22, 17);
  127.         tbl.setValueAt("4", 22, 18);tbl.setValueAt("4", 22, 19);tbl.setValueAt("4", 22, 20);tbl.setValueAt("4", 24, 18);
  128.         tbl.setValueAt("4", 25, 17);tbl.setValueAt("4", 25, 17);tbl.setValueAt("4", 26, 16);tbl.setValueAt("4", 27, 15);
  129.         tbl.setValueAt("4", 27, 16);tbl.setValueAt("4", 27, 18);tbl.setValueAt("4", 28, 17);tbl.setValueAt("4", 29, 16);
  130.         tbl.setValueAt("4", 30, 15);tbl.setValueAt("4", 31, 14);tbl.setValueAt("4", 32, 13);tbl.setValueAt("4", 33, 12);
  131.         tbl.setValueAt("4", 33, 13);tbl.setValueAt("4", 33, 14);tbl.setValueAt("4", 33, 18);tbl.setValueAt("4", 34, 17);
  132.         tbl.setValueAt("4", 35, 16);tbl.setValueAt("4", 36, 15);tbl.setValueAt("4", 37, 14);tbl.setValueAt("4", 38, 13);
  133.         tbl.setValueAt("4", 39, 12);tbl.setValueAt("4", 40, 11);tbl.setValueAt("4", 41, 10);tbl.setValueAt("4", 42, 9);
  134.         tbl.setValueAt("4", 42, 10);tbl.setValueAt("4", 42, 11);tbl.setValueAt("4", 38, 18);tbl.setValueAt("4", 39, 18);
  135.         tbl.setValueAt("4", 40, 18);tbl.setValueAt("4", 41, 17);tbl.setValueAt("4", 42, 16);tbl.setValueAt("4", 43, 15);
  136.         tbl.setValueAt("4", 44, 14);tbl.setValueAt("4", 46, 13);tbl.setValueAt("4", 47, 12);tbl.setValueAt("4", 48, 11);
  137.         tbl.setValueAt("4", 49, 10);tbl.setValueAt("4", 50, 9);tbl.setValueAt("4", 51, 8);tbl.setValueAt("4", 52, 7);
  138.         tbl.setValueAt("4", 53, 6);tbl.setValueAt("4", 54, 5);tbl.setValueAt("4", 55, 4);tbl.setValueAt("4", 56, 6);
  139.         tbl.setValueAt("4", 56, 8);tbl.setValueAt("4", 56, 9);tbl.setValueAt("4", 56, 10);tbl.setValueAt("4", 56, 12);
  140.         tbl.setValueAt("4", 56, 13);tbl.setValueAt("4", 58, 10);tbl.setValueAt("4", 59, 11);tbl.setValueAt("4", 59, 12);
  141.         tbl.setValueAt("4", 60, 13);tbl.setValueAt("4", 61, 15);tbl.setValueAt("4", 61, 16);tbl.setValueAt("4", 59, 17);
  142.         tbl.setValueAt("4", 58, 18);tbl.setValueAt("4", 57, 19);tbl.setValueAt("4", 62, 18);tbl.setValueAt("4", 63, 19);
  143.         tbl.setValueAt("4", 63, 20);tbl.setValueAt("3", 62, 23);tbl.setValueAt("3", 63, 23);tbl.setValueAt("3", 64, 23);
  144.         tbl.setValueAt("3", 65, 23);tbl.setValueAt("3", 66, 23);tbl.setValueAt("3", 67, 23);tbl.setValueAt("3", 62, 28);
  145.         tbl.setValueAt("3", 63, 28);tbl.setValueAt("3", 64, 28);tbl.setValueAt("3", 65, 28);tbl.setValueAt("3", 66, 28);
  146.         tbl.setValueAt("3", 67, 28);tbl.setValueAt("8", 14, 26);tbl.setValueAt("8", 14, 27);tbl.setValueAt("8", 16, 27);
  147.         tbl.setValueAt("8", 16, 28);tbl.setValueAt("8", 17, 29);tbl.setValueAt("8", 18, 30);tbl.setValueAt("8", 19, 31);
  148.         tbl.setValueAt("8", 20, 32);tbl.setValueAt("8", 21, 31);tbl.setValueAt("8", 22, 30);tbl.setValueAt("8", 22, 29);
  149.         tbl.setValueAt("3", 20, 27);tbl.setValueAt("3", 21, 26);tbl.setValueAt("3", 22, 25);tbl.setValueAt("3", 23, 24);
  150.         tbl.setValueAt("3", 24, 24);tbl.setValueAt("3", 24, 25);tbl.setValueAt("3", 24, 26);tbl.setValueAt("8", 22, 32);
  151.         tbl.setValueAt("8", 23, 33);tbl.setValueAt("8", 24, 34);tbl.setValueAt("8", 25, 35);tbl.setValueAt("8", 26, 36);
  152.         tbl.setValueAt("8", 27, 37);tbl.setValueAt("8", 29, 34);tbl.setValueAt("8", 29, 35);tbl.setValueAt("8", 28, 36);
  153.         tbl.setValueAt("8", 30, 32);tbl.setValueAt("8", 31, 33);tbl.setValueAt("8", 32, 34);tbl.setValueAt("8", 33, 35);
  154.         tbl.setValueAt("8", 34, 36);tbl.setValueAt("8", 34, 37);tbl.setValueAt("3", 27, 30);tbl.setValueAt("3", 28, 29);
  155.         tbl.setValueAt("3", 29, 28);tbl.setValueAt("3", 30, 28);tbl.setValueAt("3", 31, 29);tbl.setValueAt("3", 32, 30);
  156.         tbl.setValueAt("3", 31, 24);tbl.setValueAt("3", 32, 23);tbl.setValueAt("3", 33, 22);tbl.setValueAt("3", 34, 22);
  157.         tbl.setValueAt("3", 34, 23);tbl.setValueAt("3", 34, 24);tbl.setValueAt("3", 37, 20);tbl.setValueAt("3", 38, 19);
  158.         tbl.setValueAt("3", 39, 18);tbl.setValueAt("3", 40, 18);tbl.setValueAt("3", 41, 19);tbl.setValueAt("3", 42, 20);
  159.         tbl.setValueAt("3", 36, 34);tbl.setValueAt("3", 37, 33);tbl.setValueAt("3", 38, 32);tbl.setValueAt("3", 39, 32);
  160.         tbl.setValueAt("3", 39, 33);tbl.setValueAt("3", 39, 34);tbl.setValueAt("3", 40, 24);tbl.setValueAt("3", 41, 23);
  161.         tbl.setValueAt("3", 42, 22);tbl.setValueAt("3", 43, 22);tbl.setValueAt("3", 43, 23);tbl.setValueAt("3", 43, 24);
  162.         tbl.setValueAt("3", 42, 30);tbl.setValueAt("3", 43, 29);tbl.setValueAt("3", 44, 28);tbl.setValueAt("3", 45, 28);
  163.         tbl.setValueAt("3", 46, 29);tbl.setValueAt("3", 47, 30);tbl.setValueAt("3", 50, 21);tbl.setValueAt("3", 51, 20);
  164.         tbl.setValueAt("3", 52, 19);tbl.setValueAt("3", 53, 19);tbl.setValueAt("3", 53, 20);tbl.setValueAt("3", 53, 21);
  165.         tbl.setValueAt("3", 50, 31);tbl.setValueAt("3", 51, 30);tbl.setValueAt("3", 52, 29);tbl.setValueAt("3", 53, 29);
  166.         tbl.setValueAt("3", 53, 30);tbl.setValueAt("3", 53, 31);tbl.setValueAt("3", 47, 15);tbl.setValueAt("3", 48, 14);
  167.         tbl.setValueAt("3", 49, 13);tbl.setValueAt("3", 50, 13);tbl.setValueAt("3", 51, 14);tbl.setValueAt("3", 52, 15);
  168.         tbl.setValueAt("3", 51, 25);tbl.setValueAt("3", 52, 24);tbl.setValueAt("3", 53, 23);tbl.setValueAt("3", 54, 23);
  169.         tbl.setValueAt("3", 55, 24);tbl.setValueAt("3", 46, 25);tbl.setValueAt("3", 50, 38);tbl.setValueAt("3", 51, 37);
  170.         tbl.setValueAt("3", 52, 36);tbl.setValueAt("3", 53, 36);tbl.setValueAt("3", 54, 37);tbl.setValueAt("3", 55, 38);
  171.         tbl.setValueAt("3", 58, 28);tbl.setValueAt("3", 59, 27);tbl.setValueAt("3", 60, 26);tbl.setValueAt("3", 58, 26);
  172.         tbl.setValueAt("3", 59, 27);tbl.setValueAt("3", 60, 28);tbl.setValueAt("8", 37, 36);tbl.setValueAt("8", 38, 37);
  173.         tbl.setValueAt("8", 38, 38);tbl.setValueAt("8", 40, 39);tbl.setValueAt("8", 41, 40);tbl.setValueAt("8", 42, 41);
  174.         tbl.setValueAt("8", 43, 41);tbl.setValueAt("8", 44, 38);tbl.setValueAt("8", 44, 39);tbl.setValueAt("8", 44, 40);
  175.         tbl.setValueAt("8", 43, 35);tbl.setValueAt("8", 44, 36);tbl.setValueAt("8", 45, 37);tbl.setValueAt("8", 46, 38);
  176.         tbl.setValueAt("8", 47, 39);tbl.setValueAt("8", 48, 40);tbl.setValueAt("8", 49, 41);tbl.setValueAt("8", 50, 42);
  177.         tbl.setValueAt("8", 51, 43);tbl.setValueAt("8", 52, 44);tbl.setValueAt("8", 53, 45);tbl.setValueAt("8", 54, 43);
  178.         tbl.setValueAt("8", 55, 42);tbl.setValueAt("8", 56, 41);tbl.setValueAt("8", 59, 31);tbl.setValueAt("8", 60, 32);
  179.         tbl.setValueAt("8", 61, 33);tbl.setValueAt("8", 62, 34);tbl.setValueAt("8", 58, 36);tbl.setValueAt("8", 59, 37);
  180.         tbl.setValueAt("8", 60, 38);tbl.setValueAt("8", 61, 39);tbl.setValueAt("8", 62, 40);tbl.setValueAt("8", 62, 41);
  181.         tbl.setValueAt("8", 60, 35);tbl.setValueAt("8", 61, 36);tbl.setValueAt("8", 62, 37);tbl.setValueAt("8", 58, 45);
  182.         tbl.setValueAt("8", 59, 42);tbl.setValueAt("8", 59, 43);tbl.setValueAt("8", 59, 44);tbl.setValueAt("8", 62, 40);
  183.         frame.setTitle(" - - >   Merry Christmast   < - - ");
  184.         t2 = System.currentTimeMillis();
  185.         System.out.println("miliSec:" + (t2 - t1)); //aver. 32 miliSec.
  186.         new Thread(this).start();
  187.     }
  188.  
  189.     @Override
  190.     public void run() {
  191.         while (true) {
  192.             try {
  193.                 Thread.sleep(1000);
  194.             } catch (Exception e) {
  195.                 e.printStackTrace();
  196.             }
  197.             if (!bolo) {
  198.                 for (int i = 0; i < 30; i++) {
  199.                     Vector<Integer> vecLocal = new Vector<Integer>();
  200.                     final int r1 = random.nextInt(tbl.getRowCount() - 1);
  201.                     final int c1 = random.nextInt(tbl.getColumnCount() - 1);
  202.                     vecLocal.add(r1);
  203.                     vecLocal.add(c1);
  204.                     vec.add(vecLocal);
  205.                     addSnowFlag();
  206.                     try {
  207.                         Thread.sleep(250);
  208.                     } catch (Exception e) {
  209.                         e.printStackTrace();
  210.                     }
  211.                 }
  212.                 bolo = true;
  213.             } else {
  214.                 Vector<Integer> vecLocal = new Vector<Integer>();
  215.                 final int r = random.nextInt(tbl.getRowCount() - 1);
  216.                 final int c = random.nextInt(tbl.getColumnCount() - 1);
  217.                 vecLocal.add(r);
  218.                 vecLocal.add(c);
  219.                 vec.add(vecLocal);
  220.                 addSnowFlag();
  221.                 try {
  222.                     Thread.sleep(500);
  223.                 } catch (Exception e) {
  224.                     e.printStackTrace();
  225.                 }
  226.             }
  227.         }
  228.     }
  229.  
  230.     private void addSnowFlag() {
  231.         if (vec.size() > -1) {
  232.             Vector<Integer> vecLocal = vec.elementAt(vec.size() - 1);
  233.             final int r = vecLocal.elementAt(0);
  234.             final int c = vecLocal.elementAt(1);
  235.             String str = String.valueOf(tbl.getValueAt(r, c));
  236.             if (!str.isEmpty()) {
  237.                 if (!Pattern.compile("\d").matcher(str).find()) {
  238.                     if (!Pattern.compile("[123456789]").matcher(str).find()) {
  239.                         Runnable doRun = new Runnable() {
  240.  
  241.                             @Override
  242.                             public void run() {
  243.                                 tbl.setValueAt("9", r, c);
  244.                             }
  245.                         };
  246.                         SwingUtilities.invokeLater(doRun);
  247.                         if (bolo) {
  248.                             Vector<Integer> vecLocal1 = vec.elementAt(0);
  249.                             final int r1 = vecLocal1.elementAt(0);
  250.                             final int c1 = vecLocal1.elementAt(1);
  251.                             Runnable doRun1 = new Runnable() {
  252.  
  253.                                 @Override
  254.                                 public void run() {
  255.                                     tbl.setValueAt(aChars.getNext(1), r1, c1);
  256.                                     vec.removeElementAt(0);
  257.                                 }
  258.                             };
  259.                             SwingUtilities.invokeLater(doRun1);
  260.                         }
  261.                     }
  262.                 }
  263.             }
  264.         }
  265.     }
  266.  
  267.     private class GradientViewPortOriginal extends JScrollPane {
  268.  
  269.         private static final long serialVersionUID = 1L;
  270.         private final int h = 80;
  271.         private BufferedImage img = null;
  272.         private BufferedImage shadow = new BufferedImage(1, h, BufferedImage.TYPE_INT_ARGB);
  273.         private JViewport viewPort;
  274.         private ArrayList<Star> stars = new ArrayList<Star>();
  275.  
  276.         public GradientViewPortOriginal(JComponent com) {
  277.             super(com);
  278.             viewPort = this.getViewport();
  279.             viewPort.setScrollMode(JViewport.BLIT_SCROLL_MODE);
  280.             viewPort.setScrollMode(JViewport.BACKINGSTORE_SCROLL_MODE);
  281.             viewPort.setScrollMode(JViewport.SIMPLE_SCROLL_MODE);
  282.             setPreferredSize(this.getPreferredSize());
  283.             paintBackGround(new Color(250, 250, 150));
  284.         }
  285.  
  286.         public void add(Star star) {
  287.             stars.add(star);
  288.         }
  289.         //
  290.         private Timer timer = new Timer(33, new ActionListener() {
  291.  
  292.             @Override
  293.             public void actionPerformed(ActionEvent e) {
  294.                 for (Star star : stars) {
  295.                     star.move();
  296.                 }
  297.                 repaint();
  298.             }
  299.         });
  300.  
  301.         public void startAnimation() {
  302.             if (!timer.isRunning()) {
  303.                 timer.start();
  304.             }
  305.         }
  306.  
  307.         @Override
  308.         public void addNotify() {
  309.             super.addNotify();
  310.             timer.start();
  311.         }
  312.  
  313.         private void paintBackGround(Color g) {
  314.             Graphics2D g2 = shadow.createGraphics();
  315.             g2.setPaint(g);
  316.             g2.fillRect(0, 0, 1, h);
  317.             g2.setComposite(AlphaComposite.DstIn);
  318.             g2.setPaint(new GradientPaint(0, 0, new Color(0, 0, 0, 0f), 0, h,
  319.                     new Color(0.8f, 0.8f, 0.8f, 0.5f)));
  320.             g2.fillRect(0, 0, 1, h);
  321.             g2.dispose();
  322.         }
  323.  
  324.         @Override
  325.         public void paint(Graphics g) {
  326.             if (img == null || img.getWidth() != getWidth() || img.getHeight() != getHeight()) {
  327.                 img = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB);
  328.             }
  329.             Graphics2D g2 = img.createGraphics();
  330.             super.paint(g2);
  331.             ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  332.             Rectangle bounds = getViewport().getVisibleRect();
  333.             g2.scale(bounds.getWidth(), -1);
  334.             int y = (getColumnHeader() == null) ? 0 : getColumnHeader().getHeight();
  335.             g2.drawImage(shadow, bounds.x, -bounds.y - y - h, null);
  336.             g2.scale(1, -1);
  337.             g2.drawImage(shadow, bounds.x, bounds.y + bounds.height - h + y, null);
  338.             g2.dispose();
  339.             g.drawImage(img, 0, 0, null);
  340.             for (Star star : stars) {
  341.                 g.setColor(star.getColor());
  342.                 g.fillPolygon(star);
  343.             }
  344.         }
  345.     }
  346.  
  347.     private class RowColorRenderer extends DefaultTableCellRenderer {
  348.  
  349.         private static final long serialVersionUID = 1L;
  350.         private int colNo = 0;
  351.  
  352.         RowColorRenderer(int col) {
  353.             colNo = col;
  354.         }
  355.  
  356.         @Override
  357.         public Component getTableCellRendererComponent(JTable table, Object value,
  358.                 boolean isSelected, boolean hasFocus, int row, int column) {
  359.             Component comp = super.getTableCellRendererComponent(table, value,
  360.                     isSelected, hasFocus, row, column);
  361.             if (!isSelected) {
  362.                 if (table.getValueAt(row, colNo) != null) {
  363.                     String str = table.getValueAt(row, colNo).toString();
  364.                     if (!str.isEmpty()) {
  365.                         if (Pattern.compile("\d").matcher(str).find()) {
  366.                             if (((Pattern.compile("[9]").matcher(str).find()))) {
  367.                                 setBackground(new Color(250, 250, 150));
  368.                                 setForeground(new Color(250, 250, 150));
  369.                                 setFont(new Font("Serif", Font.BOLD, 9));
  370.                             } else if (((Pattern.compile("[1]").matcher(str).find()))) {
  371.                                 setBackground(tbl.getBackground());
  372.                                 setForeground(Color.orange);
  373.                                 setFont(new Font("Serif", Font.BOLD, 8));
  374.                             } else {
  375.                                 setBackground(tbl.getBackground());
  376.                                 setForeground(Color.gray);
  377.                                 setFont(new Font("Serif", Font.BOLD, 9));
  378.                             }
  379.                         } else {
  380.                             setBackground(tbl.getBackground());
  381.                             setForeground(Color.lightGray);
  382.                             setFont(new Font("Serif", Font.PLAIN, 6));
  383.                         }
  384.                     }
  385.                 }
  386.             }
  387.             setHorizontalAlignment(CENTER);
  388.             return this;
  389.         }
  390.     }
  391.  
  392.     private class AlphaChars {
  393.  
  394.         public static final int MIN_LENGTH = 2000;
  395.         private java.util.Random rand = new java.util.Random();
  396.         private char[] AlphaChars = {
  397.             'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
  398.             'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',};
  399.         /*'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q',
  400.         'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
  401.         '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '+', '-', '*', '/', '<', '>', '&',
  402.         '#', '@', '{', '}', '?', ':', '_', '"', '!', ')', '('};*/
  403.  
  404.         public String getNext() {
  405.             StringBuilder strbuf = new StringBuilder();
  406.             for (int i = 0; i < MIN_LENGTH; i++) {
  407.                 strbuf.append(getAlphaChars()[getRand().nextInt(getAlphaChars().length)]);
  408.             }
  409.             return strbuf.toString();
  410.         }
  411.  
  412.         public String getNext(int reqLenght) {
  413.             StringBuilder strbuf = new StringBuilder();
  414.             for (int i = 0; i < reqLenght; i++) {
  415.                 strbuf.append(getAlphaChars()[getRand().nextInt(getAlphaChars().length)]);
  416.             }
  417.             return strbuf.toString();
  418.         }
  419.  
  420.         public java.util.Random getRand() {
  421.             return rand;
  422.         }
  423.  
  424.         public void setRand(java.util.Random aRand) {
  425.             rand = aRand;
  426.         }
  427.  
  428.         public char[] getAlphaChars() {
  429.             return AlphaChars;
  430.         }
  431.  
  432.         public void setAlphaChars(char[] aAlphaChars) {
  433.             AlphaChars = aAlphaChars;
  434.         }
  435.     }
  436.  
  437.     private class Star extends Polygon {
  438.  
  439.         private static final long serialVersionUID = 1L;
  440.         private Point location = null;
  441.         private Color color = Color.YELLOW;
  442.         private int xIncr, yIncr;
  443.         static final int WIDTH = 500, HEIGHT = 500;
  444.  
  445.         Star(Point location) {
  446.             int x = location.x;
  447.             int y = location.y;
  448.             this.location = location;
  449.             this.addPoint(x, y + 8);
  450.             this.addPoint(x + 8, y + 8);
  451.             this.addPoint(x + 11, y);
  452.             this.addPoint(x + 14, y + 8);
  453.             this.addPoint(x + 22, y + 8);
  454.             this.addPoint(x + 17, y + 12);
  455.             this.addPoint(x + 21, y + 20);
  456.             this.addPoint(x + 11, y + 14);
  457.             this.addPoint(x + 3, y + 20);
  458.             this.addPoint(x + 6, y + 12);
  459.         }
  460.  
  461.         public void setColor(Color color) {
  462.             this.color = color;
  463.         }
  464.  
  465.         public void move() {
  466.             if (location.x < 0 || location.x > WIDTH) {
  467.                 xIncr = -xIncr;
  468.             }
  469.             if (location.y < 0 || location.y > WIDTH) {
  470.                 yIncr = -yIncr;
  471.             }
  472.             translate(xIncr, yIncr);
  473.             location.setLocation(location.x + xIncr, location.y + yIncr);
  474.         }
  475.  
  476.         public void setxIncr(int xIncr) {
  477.             this.xIncr = xIncr;
  478.         }
  479.  
  480.         public void setyIncr(int yIncr) {
  481.             this.yIncr = yIncr;
  482.         }
  483.  
  484.         public Color getColor() {
  485.             return color;
  486.         }
  487.     }
  488.  
  489.     public static void main(String args[]) {
  490.         Runnable doRun = new Runnable() {
  491.  
  492.             @Override
  493.             public void run() {
  494.                 OneTwoThree hnvit = new OneTwoThree();
  495.             }
  496.         };
  497.         SwingUtilities.invokeLater(doRun);
  498.     }
  499. }
  500.        
  501. public void move() {
  502.     if (location.x < 0 || location.x > frame.getContentPane().getWidth() - 20) {
  503.         xIncr = -xIncr;
  504.     }
  505.     if (location.y < 0 || location.y > frame.getContentPane().getHeight() - 20) {
  506.         yIncr = -yIncr;
  507.     }
  508.     translate(xIncr, yIncr);
  509.     location.setLocation(location.x + xIncr, location.y + yIncr);
  510. }
  511.        
  512. package merrychristmas;
  513.  
  514. import java.awt.AlphaComposite;
  515. import java.awt.Color;
  516. import java.awt.Dimension;
  517. import java.awt.EventQueue;
  518. import java.awt.Graphics;
  519. import java.awt.Graphics2D;
  520. import java.awt.RenderingHints;
  521. import java.awt.event.ActionEvent;
  522. import java.awt.event.ActionListener;
  523. import java.awt.event.ComponentAdapter;
  524. import java.awt.event.ComponentEvent;
  525. import java.util.LinkedList;
  526. import java.util.Queue;
  527. import java.util.Random;
  528. import javax.swing.JFrame;
  529. import javax.swing.JPanel;
  530. import javax.swing.Timer;
  531.  
  532. public class Baubles extends JPanel implements ActionListener {
  533.  
  534.     private static final int MAX = 64;
  535.     private static final String TITLE = "Baubles";
  536.     private static final Random rnd = new Random();
  537.     private static final AlphaComposite ac =
  538.         AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.75f);
  539.     private final Timer timer = new Timer(100, this);
  540.     private final Queue<Bauble> queue = new LinkedList<Bauble>();
  541.  
  542.     public static void main(String[] args) {
  543.         EventQueue.invokeLater(new Runnable() {
  544.  
  545.             @Override
  546.             public void run() {
  547.                 JFrame f = new JFrame(TITLE);
  548.                 f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  549.                 Baubles dt = new Baubles();
  550.                 f.add(dt);
  551.                 f.pack();
  552.                 f.setLocationRelativeTo(null);
  553.                 f.setVisible(true);
  554.             }
  555.         });
  556.     }
  557.  
  558.     public Baubles() {
  559.         this.setPreferredSize(new Dimension(8 * MAX, 8 * MAX));
  560.         this.addComponentListener(new ComponentAdapter() {
  561.  
  562.             @Override // relocate any outliers
  563.             public void componentResized(ComponentEvent e) {
  564.                 for (Bauble bauble : queue) {
  565.                     if (bauble.x > getWidth() || bauble.y > getHeight()) {
  566.                         bauble.x = rnd.nextInt(getWidth());
  567.                         bauble.y = rnd.nextInt(getHeight());
  568.                     }
  569.                 }
  570.             }
  571.         });
  572.         timer.start();
  573.     }
  574.  
  575.     @Override
  576.     public void actionPerformed(ActionEvent e) {
  577.         if (queue.isEmpty()) {
  578.             for (int i = 0; i < MAX; i++) {
  579.                 queue.add(randomBauble());
  580.             }
  581.         }
  582.         queue.add(randomBauble());
  583.         queue.remove();
  584.         this.repaint();
  585.     }
  586.  
  587.     @Override
  588.     public void paintComponent(Graphics g) {
  589.         Graphics2D g2d = (Graphics2D) g;
  590.         g2d.setRenderingHint(
  591.             RenderingHints.KEY_ANTIALIASING,
  592.             RenderingHints.VALUE_ANTIALIAS_ON);
  593.         g2d.setColor(Color.black);
  594.         g2d.fillRect(0, 0, getWidth(), this.getHeight());
  595.         g2d.setComposite(ac);
  596.         for (Bauble b : queue) {
  597.             g2d.setColor(b.c);
  598.             g2d.fillOval(b.x, b.y, b.d, b.d);
  599.         }
  600.     }
  601.  
  602.     private Bauble randomBauble() {
  603.         int x = rnd.nextInt(getWidth());
  604.         int y = rnd.nextInt(getHeight());
  605.         int r = rnd.nextInt(MAX) + MAX / 2;
  606.         Color c = new Color(rnd.nextInt());
  607.         return new Bauble(x, y, r, c);
  608.     }
  609.  
  610.     private static class Bauble {
  611.  
  612.         private int x, y, d;
  613.         private Color c;
  614.  
  615.         public Bauble(int x, int y, int r, Color c) {
  616.             this.x = x - r;
  617.             this.y = y - r;
  618.             this.d = 2 * r;
  619.             this.c = c;
  620.         }
  621.     }
  622. }