要是 swing 的button 的話
創(chuàng)新互聯(lián)公司主營(yíng)長(zhǎng)洲網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營(yíng)網(wǎng)站建設(shè)方案,成都app軟件開(kāi)發(fā),長(zhǎng)洲h5重慶小程序開(kāi)發(fā)公司搭建,長(zhǎng)洲網(wǎng)站營(yíng)銷推廣歡迎長(zhǎng)洲等地區(qū)企業(yè)咨詢
setBounds
public void setBounds(int x,
int y,
int width,
int height)移動(dòng)組件并調(diào)整其大小。由 x 和 y 指定左上角的新位置,由 width 和 height 指定新的大小。
參數(shù):
x - 組件的新 x 坐標(biāo)
y - 組件的新 y 坐標(biāo)
width - 組件的新 width
height - 組件的新 height
button.setBonds(button.getBonds().getX(),button.getBonds().getY()-50,button.getBonds().getWidth
(),button.getBonds().getHeight() )
button.getBonds().getY()-50, 就是向上移動(dòng)坐標(biāo)的關(guān)鍵
java是可以實(shí)現(xiàn)心跳的程序的。
心跳顧名思義就是每隔一段時(shí)間執(zhí)行,或者輪詢查詢狀態(tài),可以使用timer來(lái)實(shí)現(xiàn),代碼如下:
定時(shí)器可以實(shí)現(xiàn)
//1000毫秒,固定時(shí)間,每隔1秒鐘執(zhí)行一次actionPerformed方法
javax.swing.Timer?clock?=?new?javax.swing.Timer(1000,new?ActionListener(){
public?void?actionPerformed(ActionEvent?e)?{
//執(zhí)行心跳方法
/**...*/
//調(diào)用其他方法
/**...*/
}
});
clock.start();
可以獨(dú)立用個(gè)線程管理,也可以直接寫在主線程中
假如有兩個(gè)frame,分別為frame1,frame2,frame1加個(gè)按鈕實(shí)現(xiàn)跳轉(zhuǎn).frame1代碼如下
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
public class frame1 extends JFrame implements ActionListener{
/**
* @param args
*/
private JButton jb;
public frame1()
{
this.setSize(300, 200);
this.setLocation(300, 400);
jb=new JButton("跳轉(zhuǎn)");
this.add(jb);
jb.addActionListener(this);//加入事件監(jiān)聽(tīng)
this.setVisible(true);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
frame1 frame=new frame1();
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getSource()==jb)
{
this.dispose();//點(diǎn)擊按鈕時(shí)frame1銷毀,new一個(gè)frame2
new frame2();
}
}
}
frame2是個(gè)單純的界面
import javax.swing.JButton;
import javax.swing.JFrame;
public class frame2 extends JFrame{
/**
* @param args
*/
public frame2()
{
this.setSize(300, 200);
this.setLocation(300, 400);
this.setVisible(true);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
frame2 frame=new frame2();
}
}
名稱欄目:跳一跳Java代碼實(shí)現(xiàn) 跳一跳代碼c
文章網(wǎng)址:http://chinadenli.net/article36/dogsssg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站制作、外貿(mào)網(wǎng)站建設(shè)、、網(wǎng)站改版、網(wǎng)站排名、虛擬主機(jī)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)