Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.awt.event.*;
- import java.awt.geom.*;
- import java.math.*;
- import java.lang.*;
- public class ForWhile extends Frame {
- public void paint(Graphics g) {
- Graphics2D graph = (Graphics2D)g;
- graph.setStroke(new BasicStroke(3.0f));
- graph.setColor(Color.black);
- double x1 = 200;
- double x2 =200;
- double y1 = 200;
- double y2 = 300;
- for(int i = 1 ; i<=10 ; i++)
- {
- graph.setColor(new Color((int)(Math.random()*255),(int)(Math.random()*255),(int)(Math.random()*255)));
- if(i%2 == 0) {
- x1+=100;
- Line2D line = new Line2D.Double(x1 , y1 , x2 , y2);
- graph.draw(line);
- }
- else
- {
- x2+=100;
- Line2D line = new Line2D.Double(x2 , y2 , x1 , y1);
- graph.draw(line);
- }
- }
- }
- public static void main(String[] args) {
- Frame frame = new ForWhile();
- frame.addWindowListener(
- new WindowAdapter(){
- public void windowClosing(WindowEvent we){
- System.exit(0);
- }
- }
- );
- frame.setSize(1000, 1000);
- frame.setVisible(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement