Advertisement
hikespect

paint 3.0

Jan 27th, 2020
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.74 KB | None | 0 0
  1. package modul2;
  2.  
  3. import javax.swing.*;
  4. import java.awt.*;
  5. import java.awt.event.*;
  6.  
  7. public class hashiramaloh {
  8.    
  9. public static void main(String[] args) {
  10.  
  11. okno window = new okno();
  12.  
  13. }
  14. }
  15.  
  16. class okno extends JFrame
  17. {
  18.     public okno()
  19.     {
  20.         setBounds (0,0,800,600);
  21.     setTitle("Paint 2.5");
  22.  
  23. panel pan = new panel();
  24.    
  25.     Container con = getContentPane();
  26.    
  27.     con.add(pan);
  28.    
  29.     setVisible(true);
  30.     }
  31.     }
  32.     class panel extends JPanel
  33.     {
  34.     Color[] masColor;  
  35.     int tCol = 0;
  36.     int mX,mY;
  37.     Boolean flag=false;
  38.     public class myMouse1 implements MouseListener
  39.     {
  40.         public void mouseClicked(MouseEvent e)
  41.         {
  42.         }
  43.         public void mousePressed(MouseEvent e)
  44.         {
  45.         }
  46.         public void mouseReleased(MouseEvent e)
  47.         {
  48.         }
  49.         public void mouseEntered(MouseEvent e)
  50.         {
  51.         }
  52.         public void mouseExited(MouseEvent e)
  53.         {
  54.         }
  55.  
  56.        
  57.         }
  58.         public class myMouse2 implements MouseMotionListener
  59.         {
  60.         public void mouseDragged(MouseEvent e)
  61.         {
  62.         }
  63.         public void mouseMoved(MouseEvent e)
  64.         {
  65.         }
  66.         }
  67.         public void mouseMoved(MouseEvent e)
  68.         {
  69.             System.out.println(e.getX()+" "+e.getY());
  70.         }
  71.     public panel()
  72.     {
  73.         addMouseListener(new myMouse1());
  74.         addMouseMotionListener(new myMouse2());
  75.         setFocusable (true);   
  76.         masColor = new Color [7];
  77.         masColor[0] = Color.BLACK ;
  78.         masColor[1] = Color.WHITE ;
  79.         masColor[2] = Color.GREEN ;
  80.         masColor[3] = Color.BLUE ;
  81.         masColor[4] = Color.RED ;
  82.         masColor[5] = Color.ORANGE ;
  83.         masColor[6] = Color.YELLOW;
  84.     }
  85.    
  86.     public void paintComponent(Graphics gr)
  87.     {
  88.         for (int i=0; i<7; i++) {
  89.            
  90.             gr.setColor(masColor[i]);
  91.            
  92.             gr.fillRect(i * 100,0,100,50);
  93.            
  94.         }
  95.         if (flag == true) {
  96.            
  97.             gr.setColor(masColor[tCol]);
  98.            
  99.             gr.fillRect(mX,mY,15,15);
  100.         }
  101.        
  102.        
  103.         {
  104.  
  105.            
  106.         }
  107.     }
  108.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement