java Application 中 JBUTTON 为啥不能慢慢移动

joan933 joan933 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
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);
}
}


...全文
评论 2
收藏 已收藏
分享
返回顶部
joan933
Java 51,407 成员 86,130 内容