Este muestra el tablero del gato
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
@SuppressWarnings("serial")
public class gatoTablero extends JFrame implements ActionListener {
JButton boton;
JPanel panel;
public static void main(String[] args) {
gatoTablero marco = new gatoTablero();
marco.setSize(250, 350);
marco.setTitle("Tablero del gato");
marco.dibujaGUI();
marco.setLocationRelativeTo(null);
marco.setVisible(true);
}
public void dibujaGUI() {
setDefaultCloseOperation(EXIT_ON_CLOSE);
Container ventana = getContentPane();
ventana.setLayout(new FlowLayout());
panel = new JPanel();
panel.setPreferredSize(new Dimension(230, 280));
panel.setBackground(Color.white);
ventana.add(panel);
boton = new JButton("Haz click");
ventana.add(boton);
boton.addActionListener(this);
}
public void actionPerformed(ActionEvent evento) {
Graphics papel = panel.getGraphics();
papel.drawLine(50, 100, 50, 10);
papel.drawLine(100, 100, 100, 10);
papel.drawLine(10, 40, 140, 40);
papel.drawLine(10, 70, 140, 70);
}
}
No hay comentarios:
Publicar un comentario