RANDOM FIGURES MADE EASY JAVA This tutorial will show you how to do a JFrame with random rectangles INTRODUCTION Java has the ability to draw text and graphics using GUI. Graphics can only work by importing AWT package allow us to draw primitive geometric types like rectangle line and circle. Other than this it can also display text. This tutorial will explain various functions of Graphics class used to draw shapes and text. Simple rectangle example: The paint method is the most important one, now for the random figures you just do your random function. Now there are two main options, either the figures are placed in random positions or in random shapes Getting X & Y (next int is necessary for not repeating numbers) import java.awt.Graphics; import java.util.Random; import javax.swing.JFrame; import javax.swing.JPanel; public class DrawRect extends JFrame { static JPanel pnl = ...
Comentarios
Publicar un comentario