Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package padrinho;
- import java.awt.Color;
- import java.awt.Graphics2D;
- import java.awt.RenderingHints;
- import java.util.HashMap;
- import java.util.Random;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- public class Padrinho {
- private static HashMap<Character, Color> map;
- private static String pedido;
- private static char[] letras;
- private static void init() {
- map = new HashMap<Character, Color>();
- pedido = "senhor veterano, aceita ser meu padrinho?";
- letras = pedido.toCharArray();
- for (char l : letras) {
- if (!map.containsKey(l)) {
- map.put(l, getRandomColor());
- }
- }
- JFrame frame = new JFrame();
- frame.setSize(500, 500);
- frame.setVisible(true);
- JPanel j = new JPanel() {
- public void paint(java.awt.Graphics g1) {
- Graphics2D g = (Graphics2D) g1;
- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
- RenderingHints.VALUE_ANTIALIAS_ON);
- int x = 10;
- int y = 10;
- for (char l : letras) {
- if (!(l+"").equals(" ")) {
- Character c = (Character) l;
- g.setColor(Color.BLACK);
- g.fillOval(x - 1, y - 1, 42, 42);
- g.setColor(map.get(c));
- g.fillOval(x, y, 40, 40);
- x += 50;
- if (x > 450) {
- x = 10;
- y += 50;
- }
- }
- }
- };
- };
- frame.setContentPane(j);
- }
- private static Color getRandomColor() {
- Random rng = new Random();
- return new Color(rng.nextInt(255), rng.nextInt(255), rng.nextInt(255));
- }
- public static void main(String[] args) {
- init();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement