import java.util.*; import javax.swing.*; import java.awt.*; import java.util.UUID; /** * Classe di utility */ public class HashUtil { /* * Visualizza il grafico points */ public static void show(java.util.List plot) throws Exception { JFrame f = new JFrame(); Container cp = f.getContentPane(); MyJPanel mp = new MyJPanel(plot); cp.add(mp, BorderLayout.CENTER); mp.setPreferredSize(new Dimension(800, 600)); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.pack(); f.setVisible(true); } /* * Metodo di generazione delle chiavi esadecimali */ public static String randomKey() { String uuid = UUID.randomUUID().toString(); return uuid.substring(0,8); } /* * Classe grafica */ static class MyJPanel extends JPanel { private static final int ticlen = 20; private static final Color[] colors = {Color.BLACK, Color.RED, Color.GREEN}; java.util.List plot; public MyJPanel(java.util.List plot) { super(); this.plot = plot; } public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; g2.setStroke(new BasicStroke(10)); g2.scale(1,-1); g2.translate(0,-getHeight()); int c = 0; for (int[] points : plot) { g2.setColor(colors[c++ % colors.length]); for (int i = 0; i < points.length-1; i++) { g.drawLine( i *ticlen, points[i]*ticlen, (i+1)*ticlen, points[i+1]*ticlen); } } } } }