Advertisement
AnoTest

Java_draw_grid

Oct 27th, 2021
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.50 KB | None | 0 0
  1. import javax.swing.*;
  2. import java.awt.*;
  3. import java.awt.event.MouseEvent;
  4. import java.awt.event.MouseListener;
  5.  
  6. public class DrawTest  extends JFrame implements MouseListener {
  7.  
  8.  
  9.     public DrawTest(){
  10.         setSize(300,300);
  11.         setVisible(true);
  12.         addMouseListener(this);
  13.     }
  14.  
  15.     private static final long seriaVersionUID =1L;
  16.     int x,y;
  17.     int x1 = 20;
  18.     int x2 = 20;
  19.     public  void  paint(Graphics g){
  20.  
  21. //        g.drawLine(x,y,x+100, y+100);
  22.         //Horizontale
  23.         g.drawLine(40,90,150,90);
  24.         g.drawLine(40,120,150,120);
  25.  
  26.         //barre du bas
  27.         g.drawLine(40,150,150,150);
  28.  
  29.         //cotê gauche
  30.         g.drawLine(40,150,40,90);
  31.  
  32.         //cotê droit
  33.         g.drawLine(150,90,150,150);
  34.         //Milleu
  35.         g.drawLine(95,90,95,150);
  36.  
  37.         // horizontal -> x1 et x2
  38.         // vertical -> y1 et Y2
  39.     }
  40.  
  41.     public void affect(int x,int y) {
  42.         this.x =x;
  43.         this.y =y;
  44.         repaint();//redissiner
  45.     }
  46.     public void mouseClicked(MouseEvent e) {
  47.         int x = e.getX();
  48.         int y = e.getY();
  49.         affect(x,y);
  50.     }
  51.  
  52.     @Override
  53.     public void mousePressed(MouseEvent e) {
  54.  
  55.     }
  56.  
  57.     @Override
  58.     public void mouseReleased(MouseEvent e) {
  59.  
  60.     }
  61.  
  62.     @Override
  63.     public void mouseEntered(MouseEvent e) {
  64.  
  65.     }
  66.  
  67.     @Override
  68.     public void mouseExited(MouseEvent e) {
  69.  
  70.     }
  71.  
  72.  
  73.     public static void main(String[] args) {
  74.         DrawTest d1 = new DrawTest();
  75.     }
  76.  
  77. }
  78.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement