永发信息网

java 椭圆算法

答案:1  悬赏:80  手机版
解决时间 2021-04-15 00:16
java画的
画布大小900,600
中点算法要求输入坐标x,y,长轴,短轴,得到椭圆。
brensenham算法,输入坐标x,y,圆半径,得到圆。
最佳答案
以下代码,将输出一个椭圆,再有问题,我可远程助你。如下:

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Lipse 
{
 public static void main(String[] args)
 {
  new MainFrame();
 }
}
class MainFrame extends JFrame implements ActionListener
{
 JPanel pane=new JPanel();
 JTextField T_a,T_b;
 JButton Draw,Show;
 JLabel L_a,L_b;
 int a,b;
 MainFrame()
 {
  super("DrawLipse Window");
  Container con=this.getContentPane();
  con.setLayout(null);

  pane.setBounds(20,20,850,550);
  pane.setBackground(new Color(100,156,200));
  con.add(pane);

  L_a=new JLabel("请输入长半径:a");
  L_a.setBounds(180,580,100,20);
  con.add(L_a);

  L_b=new JLabel("请输入短半径:b");
  L_b.setBounds(180,630,100,20);
  con.add(L_b);


  T_a=new JTextField();
  T_a.setBounds(300,580,50,20);
  con.add(T_a);

  T_b=new JTextField();
  T_b.setBounds(300,630,50,20);
  con.add(T_b);

  Draw=new JButton("画椭圆");
  Draw.setBounds(550,580,90,30);
  Draw.addActionListener(this);
  con.add(Draw);

  Show=new JButton("显示坐标");
  Show.setBounds(550,620,90,30);
  Show.addActionListener(this);
  con.add(Show);

  this.addWindowListener(new CloseWindow());
  this.setBounds(20,20,900,700);
  this.setVisible(true);
  this.setResizable(false);

 }
 public void actionPerformed(ActionEvent e)
 {
     if(e.getSource()==Draw)
     {
      a=Integer.parseInt(T_a.getText().trim());
      b=Integer.parseInt(T_b.getText().trim());
      Line line=new Line(this);
      line.drawLipse(a,b); 
     }
     if(e.getSource()==Show)
     {
       Graphics g1=this.pane.getGraphics();
          g1.setColor(Color.PINK);
          g1.drawLine(0,300,920,300);//----x---
          g1.drawLine(410,0,410,720);//----y---
          g1.dispose();
     }

 }
}
class Line
{
 MainFrame jb;
 Line(MainFrame jb)
 {
  this.jb=jb;
 }
 public void drawLipse(int a,int b)
 {
  int x,y;
  double d1,d2;
  x=0;  y=b;
  d1=b*b+a*a*(-b+0.25);
  Graphics g=jb.pane.getGraphics();
  g.setColor(Color.red);
  g.drawLine(x+410,y+300,x+410,y+300);
  g.drawLine(-x+410,-y+300,-x+410,-y+300);
  g.drawLine(-x+410,y+300,x+410,-y+300);
  g.drawLine(x+410,-y+300,x+410,-y+300);
  try
  {
   while(b*b*(x+1)0)
      {
     if(d2<=0)
       {
       d2+=b*b*(2*x+2)+a*a*(-2*y+3);
       x++;
          y--;
        }
        else
        {
        d2+=a*a*(-2*y+3);
        y--;
        }
        g.drawLine(x+410,y+300,x+410,y+300);
           g.drawLine(-x+410,-y+300,-x+410,-y+300);
           g.drawLine(-x+410,y+300,x+410,-y+300);
           g.drawLine(x+410,-y+300,x+410,-y+300);
           Thread.sleep(30);
        }

     }catch(Exception e){}

 }  

}
class CloseWindow extends WindowAdapter
{
 public void windowClosing(WindowEvent e)
 {
  System.exit(0);
 }
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
驾驶证异地可以检证吗?怎么检?
威锋源地址是什么,cydia里威锋源的地址是什么
如图,⊙O中,已知弧AB=弧BC,且弧AB:弧AmC=
公安县麻豪口镇黄岭村村民委员会在哪里啊,我
李准基的CD哪里有卖…不要离南京太远!
苹果4苹果4sqq聊天记录后面写着不漫游是啥意
最好的礼物是什么
咋关闭宠物图标乐、
填上适当的数,使下面的式子成立:440÷_____
利欲熏心的意思是什么,利欲熏心的拼音
蒲城农机公司销售中心在哪里啊,我有事要去这
世界上什么东西最容易让人误会
九层妖塔是个什么东西,三杯鸡的菜品特色
保定十方海龙电子城买水货手机靠谱么?
桃园农家这个地址在什么地方,我要处理点事
推荐资讯
阿甘正传经典语句英文,英语论文改句子 150分
有人说南开考研对本校的学生非常照顾,是非常
华为手机g7plus如何取消优酷连续包月会员
德安县华明服装厂怎么去啊,有知道地址的么
居住证才刚刚办的,签证的话一定如果6个月以
2012年2月德化经济工作会议提出:德化在下一
fdy音响好不好,好吗
中孟北路/南龙道(路口)地址在哪,我要去那里
冬天咋这么冷啊, 天哪
装完windows7再装回XP电脑就卡了怎么回事?
山水云天厚德广场停车场地址在哪,我要去那里
国道209线3318公里100米在哪里?
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?