Advertisement
daniv1

Untitled

Apr 9th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.11 KB | None | 0 0
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import java.awt.geom.*;
  4. import java.math.*;
  5. import java.lang.*;
  6.  
  7. public class ForWhile extends Frame {
  8.    
  9.  
  10. public void paint(Graphics g) {
  11.     Graphics2D graph = (Graphics2D)g;
  12.       graph.setStroke(new BasicStroke(3.0f));
  13.       graph.setColor(Color.black);
  14.      double x1 = 200;
  15.      double x2 =200;
  16.      double y1 = 200;
  17.     double y2 = 300;
  18.      
  19.       for(int i = 1 ; i<=10 ; i++)
  20.       {
  21.           graph.setColor(new Color((int)(Math.random()*255),(int)(Math.random()*255),(int)(Math.random()*255)));
  22.          if(i%2 == 0) {
  23.              x1+=100;
  24.           Line2D line = new Line2D.Double(x1 , y1 , x2 , y2);
  25.        
  26.           graph.draw(line);
  27.          
  28.          }
  29.          else
  30.          {
  31.              x2+=100;
  32.               Line2D line = new Line2D.Double(x2 , y2 , x1 , y1);
  33.                
  34.               graph.draw(line);
  35.          }
  36.              }
  37.       }
  38.  
  39.    
  40.      
  41.  
  42.     public static void main(String[] args) {
  43.           Frame frame = new ForWhile();
  44.          
  45.           frame.addWindowListener(
  46.                   new WindowAdapter(){
  47.                       public void windowClosing(WindowEvent we){
  48.                       System.exit(0);
  49.                      }
  50.                     }
  51.                   );
  52.           frame.setSize(1000, 1000);
  53.           frame.setVisible(true);
  54.     }
  55.    
  56.    
  57.    
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement