Advertisement
Guest User

Untitled

a guest
May 24th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. import java.awt.BorderLayout;
  2. import java.awt.Color;
  3. import java.awt.Graphics;
  4. import java.awt.event.ActionEvent;
  5. import java.awt.event.ActionListener;
  6. import java.awt.event.MouseEvent;
  7. import java.awt.event.MouseMotionListener;
  8.  
  9. import javax.swing.JButton;
  10. import javax.swing.JColorChooser;
  11. import javax.swing.JFrame;
  12.  
  13. public class Draw extends JFrame implements MouseMotionListener,ActionListener{
  14. JColorChooser jc = new JColorChooser();
  15. Graphics g;
  16. Color bg;
  17. JButton eraser = new JButton("erase");
  18. public Draw(){
  19. this.setTitle("GPaint");
  20. this.setSize(800,800);
  21. this.setLayout(new BorderLayout());
  22. // this.add(jc,BorderLayout.NORTH);
  23. // this.add(eraser,BorderLayout.SOUTH);
  24. this.setVisible(true);
  25. this.addMouseMotionListener(this);
  26. g=this.getGraphics();
  27. g.setColor(Color.orange);
  28. this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
  29. }
  30. public static void main(String[] args) {
  31. // TODO Auto-generated method stub
  32. Draw a = new Draw();
  33. System.out.println(a.getWidth());
  34. }
  35.  
  36.  
  37. @Override
  38. public void actionPerformed(ActionEvent arg0) {
  39. // TODO Auto-generated method stub
  40.  
  41. }
  42.  
  43. @Override
  44. public void mouseDragged(MouseEvent arg0) {
  45. // TODO Auto-generated method stub
  46. g.setColor(Color.red);
  47. g.fillOval(arg0.getX(), arg0.getY(), 10, 10);
  48. }
  49.  
  50. @Override
  51. public void mouseMoved(MouseEvent arg0) {
  52. // TODO Auto-generated method stub
  53.  
  54. }
  55. public void paint(Graphics g){
  56. g.setColor(Color.red);
  57. int y[]=new int[400];
  58. double r=20;
  59. for(r=20;r<400;r+=40){
  60. for(int x=0;x<400;x++)
  61. // y[x]=x*x/10;
  62. y[x]=(int)Math.sqrt(Math.pow(r, 2)-Math.pow(x, 2));
  63. for(int x=0;x<399;x++){
  64. g.drawLine(x+this.getWidth()/2, -y[x]+this.getHeight()/2, x+this.getWidth()/2, -y[x+1]+this.getHeight()/2);
  65. g.drawLine(-x+this.getWidth()/2, -y[x]+this.getHeight()/2,-x+this.getWidth()/2, -y[x+1]+this.getHeight()/2);
  66. g.drawLine(-x+this.getWidth()/2, +y[x]+this.getHeight()/2,-x+this.getWidth()/2, +y[x+1]+this.getHeight()/2);
  67. g.drawLine(+x+this.getWidth()/2, +y[x]+this.getHeight()/2,+x+this.getWidth()/2, +y[x+1]+this.getHeight()/2);
  68. }}
  69. for(r=10;r<400;r+=10){
  70. for(int x=0;x<400;x++)
  71. // y[x]=x*x/10;
  72. y[x]=(int)Math.sqrt(Math.pow(r, 2)-Math.pow(x, 2));
  73. for(int x=0;x<399;x++){
  74. g.drawLine(x+this.getWidth()/2, -y[x]+this.getHeight()/2, x+this.getWidth()/2, -y[x+1]+this.getHeight()/2);
  75. g.drawLine(-x+this.getWidth()/2, -y[x]+this.getHeight()/2,-x+this.getWidth()/2, -y[x+1]+this.getHeight()/2);
  76. g.drawLine(-x+this.getWidth()/2, +y[x]+this.getHeight()/2,-x+this.getWidth()/2, +y[x+1]+this.getHeight()/2);
  77. g.drawLine(+x+this.getWidth()/2, +y[x]+this.getHeight()/2,+x+this.getWidth()/2, +y[x+1]+this.getHeight()/2);
  78. }}
  79. g.drawLine(0, this.getHeight()/2, this.getWidth(), this.getHeight()/2);
  80. g.drawLine(this.getWidth()/2, 0, this.getWidth()/2, this.getHeight());
  81. }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement