
正文
java中椭圆实现代码 js椭圆旋转代码
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
JAVA中如何通过鼠标拖拽画椭圆
写一个鼠标事件处理程序,当鼠标按下时记录下所在位置,当松开时记录下所在位置,2点就都得到了。如果想实现拖曳的效果,那么当鼠标按下时就开始,每隔一段时间记录鼠标所在位置,根据2点画椭圆,直到鼠标松开为止,获得最终椭圆
2点确定椭圆和2点确定矩形是一样的,这个椭圆就是被这个矩形包围的最大椭圆,矩形宽为椭圆短轴,长为长轴,矩形中心为椭圆圆心。
相关问答
Q1: 编java代码求椭圆和长方形的面积和周长。
没明白isLargeThan是什么意思,能说得详细点儿么?
先把满足前四个条件的程序发给你,你看看行不行。
注:一个类一个java文件,运行Test3类执行。
public class Point {
private double x;
private double y;
public Point() {
x=0;
y=0;
}
public Point(double x,double y){
this.x=x;
this.y=y;
}
public double getX(){
return this.x;
}
public double getY(){
return this.y;
}
public void setX(double x){
this.x=x;
}
public void setY(double y){
this.y=y;
}
public Point translate(double u,double v){
this.x=this.x+u;
this.y=this.y+v;
return new Point (this.x,this.y);
}
}
public class Rectangle extends Point {
private double height;
private double wideth;
public Rectangle() {
super();
}
public Rectangle(Point p,double h,double w){
super(p.getX(),p.getY());
this.height=h;
this.wideth=w;
}
public double getPerimeter(){
return 2*(height+wideth);
}
public double getArea(){
return height*wideth;
}
}
public class Ellipse extends Point{
private double height;
private double wideth;
public Ellipse() {
super();
}
public Ellipse(Point p,double h,double w){
super(p.getX(),p.getY());
this.height=h;
this.wideth=w;
}
public double getPerimeter(){
return 2*3.14*Math.sqrt((height*height+wideth*wideth)/2);
}
public double getArea(){
return 3.14*height*wideth;
}
}
public class Test3 {
public static void main(String[] args) {
Point p=new Point(1.2,4.6);
Rectangle r=new Rectangle(p,9.2,8.7);
Ellipse e=new Ellipse(p,3.2,9.2);
Point p1=p.translate(2.8,2.9);
System.out.println("移动后的点为x="+p1.getX()+" y="+p1.getY());
System.out.println("长方形的周长为:"+r.getPerimeter());
System.out.println("长方形的面积为:"+r.getArea());
System.out.println("椭圆形的周长为:"+e.getPerimeter());
System.out.println("椭圆形的面积为:"+e.getArea());
}
}
Q2: Java如何编译椭圆周长的程序
publicclassCircle{圆的半径,privatedoublemRadius,publicCircle(doublemRadius){,this.mRadius=mRadius,}获取圆的周长,publicdoublegetLength,{return2Math.PImRadius,},获取圆的面积publicdoublegetArea{returnMath.PImRadiusmRadius。这样即可在Java编译椭圆周长的程序。
Q3: java编写一个实现如下功能的Applet:在Applet窗口中以鼠标左键点击处为圆心,画椭圆
代码:亲测可用 汗 刚看错了..
import java.applet.Applet;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class TuoYuan extends Applet {
private static final long serialVersionUID = 1L;
/**
* 绘制椭圆
*/
public void init() {
addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e) {
paintTuoYuan(e.getX(), e.getY());
}
});
}
public void paintTuoYuan(int x,int y){
getGraphics().drawOval(x-60, y-40, 120, 80);
}
}
Q4: java 如何用字体沿椭圆排列
java中椭圆实现代码我java中椭圆实现代码的实现java中椭圆实现代码,做了两次String的翻转java中椭圆实现代码,然后进行比较~
import java.util.Arrays;
public class MySort {
public static void main(String[] args) {
String[] ary = { "as", "sa", "ads", "dsa" };
for (String tmp : ary) {
tmp = new StringBuilder(tmp).reverse().toString();//做字符串的翻转
}
Arrays.sort(ary);//进行排序~
for (String tmp : ary) {
tmp = new StringBuilder(tmp).reverse().toString();//翻转回字符串原来的样子~
System.out.print(tmp + " ");
}
}
}
Q5: java 椭圆算法
以下代码,将输出一个椭圆,再有问题,我可远程助你。如下:
/**
*(300,100)(400,100)
*
*/
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);
}/*MainFrame()*/
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();
}
}/*method actionPerformed*/
}
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)a*a*(y-0.5))
{
if(d1=0)
{
d1+=b*b*(2*x+3);
x++;
}
else
{
d1+=(b*b*(2*x+3)+a*a*(-2*y+2));
x++;
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);
}// top of while
}catch(Exception e){}
d2=b*b*(x+0.5)*(x+0.5)+a*a*(y-1)*(y-1)-a*a*b*b;
try
{
while(y0)
{
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);
}/* bottom of while*/
}catch(Exception e){}
} /*DrawLipse*/
}
class CloseWindow extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
java中椭圆实现代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于js椭圆旋转代码、java中椭圆实现代码的信息别忘了在本站进行查找喔。








