Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java SE 综合讨论区 » 编程/算法/API  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 Java初学者-关于图像,算法,loop的一些实例问题
obdiwing





发贴: 2
积分: 0
于 2008-07-05 06:20 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
以前提的问题已经解决,现在就是在sin上animate一个球,怎么样可以让这个球与frame window向切? 请大家帮忙~~

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;

public class SineCurve extends JFrame
{
  public void lauchFrame()
  {
    int Row,Col;
    Toolkit MyKit = Toolkit.getDefaultToolkit();
    Dimension XY = MyKit.getScreenSize();
    Row = XY.width;
    Col = XY.height;
    Image MyImage = MyKit.getImage(":");
    this.setIconImage(MyImage);
    this.setTitle("JButton-Sun-Rise Color Test");
    
    this.setSize(7*Row/8, 7*Col/8);
    this.setLocation(Row/32,Col/32);
    this.setTitle("Sine");
    this.setResizable(false);
    
    MyPanel Panel01 = new MyPanel();
    Container ContentPanel01 = getContentPane();
    ContentPanel01.add(Panel01);
    
    this.addWindowListener(new WindowAdapter()
    {
      public void windowClosing(WindowEvent e)
      {
        System.exit(0);
      }  
    });
    setVisible(true);
  }
  private class MyPanel extends JPanel
  {
    public void paint(Graphics g)
    {
      super.paintPresent;
      Graphics2D gr = (Graphics2D) g;
      
      int X, Y, x1, x2, y1, y2;
      int Row, Col;
      double Frequency;
      
      Dimension RowCol;
      
      RowCol = getSize();
      Row = RowCol.width;
      Col = RowCol.height;
      g.setColor(Color.green);
      g.drawRect(1,1,Row-2,Col-2);
      g.setColor(Color.blue);
      g.drawLine(0,Col/2,Row,Col/2);
      g.drawLine(Row/2,0,Row/2,Col);
      g.setColor(Color.red);
      
      Frequency = 1;
      Radius = 20;
      x1 = Action;
      y1 = Col/2 - (int)(Col/2*Math.sin(Frequency*2.0*Math.PI/(Row)*x1));
      
      /*if (Action < Row/2)
      {
        x1 = Action+Radius;
        y1 = Col/2+Radius - (int)(Col/2*Math.sin(Frequency*2.0*Math.PI/(Row)*x1));
      }*/
      
      g.setColor(new Color(0,150,150));
      Ellipse2D C1 = new Ellipse2D.Double();
      C1.setFrameFromCenter(x1,y1,x1+Radius,y1+Radius);
      gr.fill(C1);
    }
    public MyPanel()
    {
      Action = 0;
      JButton StartButton = new JButton("Start Running");
      add(StartButton);
      
      ClickStart Start = new ClickStart();
      StartButton.addActionListener(Start);
    }
    private class ClickStart implements ActionListener
    {
      public void actionPerformed(ActionEvent e)
      {
        ActionListener WakeUp = new TimeStamp();
        Timer T = new Timer(10,WakeUp);
        T.start();
      }
      private class TimeStamp implements ActionListener
      {
        public void actionPerformed(ActionEvent e)
        {
          Action ++;
          repaint();
          if (Action == Row-40)
          {
            Action = 0;
          }
        }
      }
    }
    private int Action,Frequency,y2,Row,Radius;
  }
}


obdiwing edited on 2008-07-08 04:09


话题树型展开
人气 标题 作者 字数 发贴时间
8824 Java初学者-关于图像,算法,loop的一些实例问题 obdiwing 2622 2008-07-05 06:20

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923