0% found this document useful (0 votes)
26 views4 pages

Correccion2 C

The document defines a Java program that creates a graphical user interface with buttons to draw shapes on a canvas when clicked. It contains classes for the main frame, button listeners, and a panel to hold the drawings.

Uploaded by

jeff yupanqui
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views4 pages

Correccion2 C

The document defines a Java program that creates a graphical user interface with buttons to draw shapes on a canvas when clicked. It contains classes for the main frame, button listeners, and a panel to hold the drawings.

Uploaded by

jeff yupanqui
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

/*

*/

package Dibujo;

import javax.swing.*;

import java.awt.*;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

/**

* @author YUPANQUI CASTELLANOS

*/

public class Dibujo extends JFrame {

private JButton b1;

private JButton b2;

public Dibujo(){

setTitle("ventana");

setSize(500, 400);

setDefaultCloseOperation(EXIT_ON_CLOSE);

setLocationRelativeTo(null);

setVisible(true);

Lamina miLamina = new Lamina();

add(miLamina);

b1 = new JButton("PINTAR RECTANGULO");


b2 = new JButton("PINTAR TRIANGULO");

b1.setBounds(50, 200, 175, 50);

b2.setBounds(275, 200, 175, 50);

miLamina.setLayout(null);

miLamina.add(b1);

miLamina.add(b2);

Oyente1 o1 = new Oyente1();

b1.addActionListener(o1);

Oyente2 o2 = new Oyente2();

b2.addActionListener(o2);

private class Oyente1 implements ActionListener {

@Override

public void actionPerformed(ActionEvent ae){

private class Oyente2 implements ActionListener{

@Override
public void actionPerformed(ActionEvent ae) {

package Dibujo;

import java.awt.Graphics;

import javax.swing.JPanel;

/**

* @author YUPANQUI CASTELLANOS

*/

public class Lamina extends JPanel {

@Override

public void paintComponent(Graphics g){

super.paintComponent(g);

g.drawRect(50, 50, 200, 100);

int [] vx1 = {375,300,450};

int [] vy1 = {50,150,150};

g.drawPolygon(vx1, vy1, 3);

}
package Dibujo;

/**

* @author YUPANQUI CASTELLANOS

*/

public class Principal {

public static void main(String[] args) {

new Dibujo();

COMPILACION:

You might also like