I am using NetBeans8 IDE .
Here is a java scrippt function from this Fiddle
function animate() {
xnow = parseInt(item.style.left);
item.style.left = (xnow+1)+'px';
ynow = parseInt(item.style.top);
item.style.top = (ynow+Math.sin(2*Math.PI*(xnow/50))*10) + "px";
setTimeout(animate,20);
}
Here the programmer creates s moving sine wave using java script.
And with the same idea, by making some slight changes, I create a java program using timer t
.The equation is exactly the same as above.But my jRadioButton
is going somewhere uncontrollable.
Is it possible to create a moving sine wave by this method ?
Kindly help me to solve this..Thanks in advance.
Here is my bit of java code
Timer t = new Timer(10, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//AL1 is the name given to radiobutton
int xnow=AL1.getX()+1;
int ynow=AL1.getY();
ynow=(int) (ynow+Math.sin(2*Math.PI*(xnow/50))*10);
AL1.setLocation(xnow, ynow);
}
});
private void formWindowOpened(java.awt.event.WindowEvent evt) {
// TODO add your handling code here:
AL1.setLocation(0, 200);
t.start();
}
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(Lpne, javax.swing.GroupLayout.DEFAULT_SIZE, 1030, Short.MAX_VALUE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(Lpne, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 551, Short.MAX_VALUE)
);
Please try to make my jRadioButton
under control..
Thanks to all... IT IS THE FINAL RESULT