Pfeffer 2017-11-01 19:02 采纳率: 50%
浏览 2077
已结题

想在一个小窗口中实现画一个点并且当点的坐标变化的时候,能自动移动

 import java.awt.Color;

import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Panel;




class punkt extends Panel
{
    public void paint(Graphics g) {

        super.paint(g);
        g.setColor(Color.RED);
        g.drawLine(50, 50, 51, 51);
    }
}



class FrameDemo extends Frame
{

    public FrameDemo(String title)
    {
    super(title);
    }

    public void init() {

    this.setSize(700,700);
    this.setBackground(Color.GREEN);
    this.setBounds(100,100,300,300);

    this.setLayout(null);
    Panel panel = new Panel();
    panel.setLayout(null);
    panel.setBackground(Color.blue);
    panel.setBounds(10,0,200,200);
    this.add(panel);
    this.add(new punkt());
    this.setVisible(true);
    }

}





class DrawPunkt
{
public static void main(String[] args)
{
     new FrameDemo("FrameDemo");



}
}




求大神修改以下我的程序,我现在连点都没有。 下连接在一起面是我写的一个和没有和awt放在一起的点的移动的库,求大神指点

 class punkt
    {
    private int x,y;  

    punkt()

    }

    punkt (int x , int y)
    {
        this.x =x;
        this.y =y;

    }


    punkt(punkt p)

    {
        p.x = 10;
        p.y = 20;

    }


    public int getX() {
        return x;
    }

    public void setX(int x) { 
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    // void setlocation....

    void print(int x, int y)
    {
        System.out.println();
        System.out.println("die Koordinate ist (" +x+","+y+ ")");

    }

    void setLocation(int x, int y)
    {
        this.x = x;
        this.y = y;

    String a = this.toString(this.x,this.y);
    System.out.print("Die Koordinate ist (");
    for( int i=0;i<a.length();i++ )
    {
        System.out.print( a.charAt(i) );
    }


    System.out.print(")");  

    }
    // String toString

    public String toString(int A, int B)


        String a = String.valueOf(A);
        String b = String.valueOf(B);
        String s = a+","+b;


        return s;
    }

    // void translate(int dx, int dy)
    void translate(int dx, int dy)
    {
       this.x=this.x + dx;
       this.y=this.y + dx;
       this.print(this.x, this.y);

    }

    }

    public class Uebung5 {

    public static void main(String[] args) {
        punkt p = new punkt();

        p = new punkt(20,30);

        p.setLocation(100,200); 
        p.translate(-20,+30);
        // TODO Auto-generated method stub



    }

}

  • 写回答

2条回答 默认 最新

  • 胆小鬼345X 2017-11-02 01:53
    关注

    这个点是在地图上移动,就调地图API接口吧,不在地图上移动,那就先布一个画布,用画笔把点在画布上移动就行了

    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料