java钟摆_钟摆问题。求大神解答

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

import java.awt.EventQueue;

import java.awt.Graphics;

import javax.swing.JFrame;

import javax.swing.JPanel;

import java.awt.BorderLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

public class DD implements ActionListener{

private JFrame frame;

private javax.swing.Timer timer =new javax.swing.Timer(50,this);

private MyPanel20 panel ;

int count;

/**

* Launch the application.

*/

public static void main(String[] args) {

EventQueue.invokeLater(new Runnable() {

public void run() {

try {

DD window = new DD();

window.frame.setVisible(true);

} catch (Exception e) {

e.printStackTrace();

}

}

});

}

/**

* Create the application.

*/

public DD() {

initialize();

}

/**

* Initialize the contents of the frame.

*/

private void initialize() {

frame = new JFrame();

frame.setBounds(100, 100, 419, 302);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

panel = new MyPanel20();

frame.getContentPane().add(panel, BorderLayout.CENTER);

timer.start();

}

@Override

public void actionPerformed(ActionEvent e) {

// TODO Auto-generated method stub

panel.arc1 = panel.arc1 - 5*2*Math.PI/360;

//逆时针转

panel.repaint();

}

class MyPanel20 extends JPanel{

double arc1 = 300*2*Math.PI/360;

protected void paintComponent(Graphics g){

super.paintComponent(g);

int x1 = this.getWidth()/2;

int r1 = x1-15;

g.fillOval(x1-2, 20, 4, 4);

g.drawLine(x1, 20, (int)(x1-x1*Math.cos(arc1)), (int)(20-x1*Math.sin(arc1)));

g.fillOval((int)(r1-x1*Math.cos(arc1)), (int)(10-x1*Math.sin(arc1)), 30, 30);

}

}

}

只能逆时针转,如何才能来回摆动?求点拨

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值