Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.BorderLayout;
- import java.awt.Color;
- import java.awt.Graphics;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.MouseEvent;
- import java.awt.event.MouseMotionListener;
- import javax.swing.JButton;
- import javax.swing.JColorChooser;
- import javax.swing.JFrame;
- public class Draw extends JFrame implements MouseMotionListener,ActionListener{
- JColorChooser jc = new JColorChooser();
- Graphics g;
- Color bg;
- JButton eraser = new JButton("erase");
- public Draw(){
- this.setTitle("GPaint");
- this.setSize(800,800);
- this.setLayout(new BorderLayout());
- // this.add(jc,BorderLayout.NORTH);
- // this.add(eraser,BorderLayout.SOUTH);
- this.setVisible(true);
- this.addMouseMotionListener(this);
- g=this.getGraphics();
- g.setColor(Color.orange);
- this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
- }
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Draw a = new Draw();
- System.out.println(a.getWidth());
- }
- @Override
- public void actionPerformed(ActionEvent arg0) {
- // TODO Auto-generated method stub
- }
- @Override
- public void mouseDragged(MouseEvent arg0) {
- // TODO Auto-generated method stub
- g.setColor(Color.red);
- g.fillOval(arg0.getX(), arg0.getY(), 10, 10);
- }
- @Override
- public void mouseMoved(MouseEvent arg0) {
- // TODO Auto-generated method stub
- }
- public void paint(Graphics g){
- g.setColor(Color.red);
- int y[]=new int[400];
- double r=20;
- for(r=20;r<400;r+=40){
- for(int x=0;x<400;x++)
- // y[x]=x*x/10;
- y[x]=(int)Math.sqrt(Math.pow(r, 2)-Math.pow(x, 2));
- for(int x=0;x<399;x++){
- g.drawLine(x+this.getWidth()/2, -y[x]+this.getHeight()/2, x+this.getWidth()/2, -y[x+1]+this.getHeight()/2);
- g.drawLine(-x+this.getWidth()/2, -y[x]+this.getHeight()/2,-x+this.getWidth()/2, -y[x+1]+this.getHeight()/2);
- g.drawLine(-x+this.getWidth()/2, +y[x]+this.getHeight()/2,-x+this.getWidth()/2, +y[x+1]+this.getHeight()/2);
- g.drawLine(+x+this.getWidth()/2, +y[x]+this.getHeight()/2,+x+this.getWidth()/2, +y[x+1]+this.getHeight()/2);
- }}
- for(r=10;r<400;r+=10){
- for(int x=0;x<400;x++)
- // y[x]=x*x/10;
- y[x]=(int)Math.sqrt(Math.pow(r, 2)-Math.pow(x, 2));
- for(int x=0;x<399;x++){
- g.drawLine(x+this.getWidth()/2, -y[x]+this.getHeight()/2, x+this.getWidth()/2, -y[x+1]+this.getHeight()/2);
- g.drawLine(-x+this.getWidth()/2, -y[x]+this.getHeight()/2,-x+this.getWidth()/2, -y[x+1]+this.getHeight()/2);
- g.drawLine(-x+this.getWidth()/2, +y[x]+this.getHeight()/2,-x+this.getWidth()/2, +y[x+1]+this.getHeight()/2);
- g.drawLine(+x+this.getWidth()/2, +y[x]+this.getHeight()/2,+x+this.getWidth()/2, +y[x+1]+this.getHeight()/2);
- }}
- g.drawLine(0, this.getHeight()/2, this.getWidth(), this.getHeight()/2);
- g.drawLine(this.getWidth()/2, 0, this.getWidth()/2, this.getHeight());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement