Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.MouseEvent;
- import java.awt.event.MouseListener;
- public class DrawTest extends JFrame implements MouseListener {
- public DrawTest(){
- setSize(300,300);
- setVisible(true);
- addMouseListener(this);
- }
- private static final long seriaVersionUID =1L;
- int x,y;
- int x1 = 20;
- int x2 = 20;
- public void paint(Graphics g){
- // g.drawLine(x,y,x+100, y+100);
- //Horizontale
- g.drawLine(40,90,150,90);
- g.drawLine(40,120,150,120);
- //barre du bas
- g.drawLine(40,150,150,150);
- //cotê gauche
- g.drawLine(40,150,40,90);
- //cotê droit
- g.drawLine(150,90,150,150);
- //Milleu
- g.drawLine(95,90,95,150);
- // horizontal -> x1 et x2
- // vertical -> y1 et Y2
- }
- public void affect(int x,int y) {
- this.x =x;
- this.y =y;
- repaint();//redissiner
- }
- public void mouseClicked(MouseEvent e) {
- int x = e.getX();
- int y = e.getY();
- affect(x,y);
- }
- @Override
- public void mousePressed(MouseEvent e) {
- }
- @Override
- public void mouseReleased(MouseEvent e) {
- }
- @Override
- public void mouseEntered(MouseEvent e) {
- }
- @Override
- public void mouseExited(MouseEvent e) {
- }
- public static void main(String[] args) {
- DrawTest d1 = new DrawTest();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement