|
Dibujar un cuadrado con Java
Ejemplo:
import javax.swing.JPanel;
import javax.swing.JFrame;
import java.awt.Graphics;
public class Main {
public static void main(String arg[]) {
JFrame frame = new JFrame("Cuadrado");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
miCuadrado jp = new miCuadrado();
frame.add(jp);
frame.setSize(500, 300);
frame.setVisible(true);
}
}
class miCuadrado extends JPanel {
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawRect(20, 10, 100, 100);
}
}
|
|