Eccomi qui....
ho fatto un codice del genere...ma non so se è esatto
codice:
String elegibleChars = "ABCDEFGHILMNOPQRSTUVZXJKW123456789";
int circlesToDraw = 10;
int linesToDraw = 5;
int charsToPrint = 6;
int fontSize = 22;
Color backgroundColor = new Color(204, 255, 51);
Color textColor = new Color(0, 123, 0);
Color circleColor = new Color(0, 200, 0);
Color lineColor = Color.GREEN;
String text;
int width = 150;
int height = 45;
try {
Font textFont = new Font("Arial", Font.BOLD, fontSize);
float horizMargin = 20.0f;
double rotationRange = 0.8;
BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D g = (Graphics2D) bufferedImage.getGraphics();
g.setColor(backgroundColor);
g.fillRect(0, 0, width, height);
g.setColor(circleColor);
for(int i=0; i<circlesToDraw; i++) {
int circleRadius = (int) (Math.random() * height / 2.0);
int circleX = (int) (Math.random() * width - circleRadius);
int circleY = (int) (Math.random() * height - circleRadius);
g.drawOval(circleX, circleY, circleRadius * 2, circleRadius * 2);
}
g.setColor(lineColor);
for(int i=0; i<linesToDraw; i++) {
g.drawLine(0, i*(height/linesToDraw)+1, width, i*(height/linesToDraw)+1);
}
g.setColor(textColor);
g.setFont(textFont);
FontMetrics fontMetrics = g.getFontMetrics();
int maxAdvance = fontMetrics.getMaxAdvance();
int fontHeight = fontMetrics.getHeight();
char[] chars = elegibleChars.toCharArray();
float spaceForLetters = -horizMargin * 2 + width;
float spacePerChar = spaceForLetters / (charsToPrint - 1.0f);
StringBuffer finalString = new StringBuffer();
for(int i=0; i<charsToPrint; i++) {
double randomValue = Math.random();
int randomIndex = (int) Math.round(randomValue * (chars.length - 1));
char characterToShow = chars[randomIndex];
finalString.append(characterToShow);
text = finalString.toString();
int charWidth = fontMetrics.charWidth(characterToShow);
int charDim = Math.max(maxAdvance, fontHeight);
int halfCharDim = (int) (charDim / 2);
BufferedImage charImage = new BufferedImage(charDim, charDim, BufferedImage.TYPE_INT_ARGB);
Graphics2D charGraphics = charImage.createGraphics();
charGraphics.translate(halfCharDim, halfCharDim);
double angle = (Math.random() - 0.5) * rotationRange;
charGraphics.transform(AffineTransform.getRotateInstance(angle));
charGraphics.translate(-halfCharDim,-halfCharDim);
charGraphics.setColor(textColor);
charGraphics.setFont(textFont);
int charX = (int) (0.5 * charDim - 0.5 * charWidth);
charGraphics.drawString("" + characterToShow, charX, (int) ((charDim - fontMetrics.getAscent()) / 2 + fontMetrics.getAscent()));
float x = horizMargin + spacePerChar * (i) - charDim / 2.0f;
int y = (int) ((height - charDim) / 2);
g.drawImage(charImage, (int) x, y, charDim, charDim, null, null);
charGraphics.dispose();
}
} catch (Exception e) { }
compila correttamente senza errori...
ma quando lancio mi da questo errore:
java.lang.NoClassDefFoundError: sun.awt.X11GraphicsEnvironment
qualcuno sa aiutarmi?????