Para dibujar un cuadrado en Java se usa la clase JFrame y JPanel.
- Código
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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); } } - Más
Links:
0.03
¿cómo se podría hacer en una clase hija?
ResponderBorrarcomo puedo seguir rellenando el cuadrado por dentro con lineas?
ResponderBorrar