java Application 中 JBUTTON 为啥不能慢慢移动
java Application 中 JBUTTON 为啥不能慢慢移动?
能帮我看看吗?已经三星期了,还是不知如何做。
package image_test;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.net.*;
public class Frame2 extends JFrame {
JPanel contentPane;
BorderLayout borderLayout1 = new BorderLayout();
JButton jButton1 = new JButton();
//Construct the frame
public Frame2() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
contentPane = (JPanel) this.getContentPane();
jButton1.setBounds(new Rectangle(162, 65, 192, 66));
contentPane.setLayout(null);
this.setSize(new Dimension(400, 300));
this.setTitle("Frame Title");
jButton1.setText("jButton1");
contentPane.addMouseListener(new Frame2_contentPane_mouseAdapter(this));
contentPane.add(jButton1, null);
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
void contentPane_mouseClicked(MouseEvent e) {
for(int i=55; i>2; i=i-5){
try{
Thread.sleep(2000);
System.out.println(i);
this.getContentPane(). setLayout(null);
// jButton1.setBounds(new Rectangle(80, 69, 206, 53));
jButton1.setLocation(i,115);
// jButton1.repaint();
this.getContentPane().add(jButton1, null);
contentPane.repaint();
//this.repaint();
}catch(InterruptedException exception) {
System.err.println(exception.toString());
}
}//end for
}//// end contentPanel mouse_clicked
}
class Frame2_contentPane_mouseAdapter extends java.awt.event.MouseAdapter {
Frame2 adaptee;
Frame2_contentPane_mouseAdapter(Frame2 adaptee) {
this.adaptee = adaptee;
}
public void mouseClicked(MouseEvent e) {
adaptee.contentPane_mouseClicked(e);
}
}