Ⅰ java 設置一個按鈕,點擊該按鈕,程序重新從初始狀態開始執行
你好:
如果是表單的話可以很簡單
<inputtype="reset"value="重置"/>
Ⅱ java 線程開始,暫停,重新開始的問題。
private boolean isStart = true; //是否開啟自動翻頁
private int current = 1; //你的當前頁數
你的線程方法
run(){
if(isStart){ //如果開始自動翻頁,把當前頁數+1
current ++;
}
Thread.sleep(10000);
}
你點擊暫停的時候,把isStart改為false,點擊恢復的時候,再改為true
這用的是sleep睡眠,使用定時器是一樣的
Ⅲ Java 如何實現」是否重新開始(y/n)」
do {
。。。。
} while ()
當括弧中的表達式 為真 跳出停止循環
again == false 為真 所以只循環了一次 不會出錯但沒起任何作用
最簡單while(true){ }
可以加一點人性化設計 比如 輸入 -1 退出 等等
Ⅳ java for 循環 滿足某個條件從新開始執行
可以使用帶標簽的continue ,break跳轉到指定的位置。
一下僅供參考
packagecom.kidd.test.;
importjava.util.Random;
publicclassMain{
publicstaticvoidmain(String[]args){
outer:for(inti=0;i<10;i++){
System.out.println(" outer_loop:"+i);
inner:for(intk=0;i<10;k++){
System.out.print(k+"");
intx=newRandom().nextInt(10);
if(x>7){
System.out.print(">>x=="+x+",結束inner循環,繼續迭代執行outer循環了!");
continueouter;
}
if(x==1){
System.out.print(">>x==1,跳出並結束整個outer和inner循環!");
breakouter;
}
}
}
System.out.println("------>>>所有循環執行完畢!");
}
}
Ⅳ java大作業 下面是我的代碼,求大神幫忙添加一個重新開始的按鈕並實現這個按鈕的功能
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
public class yingyu extends JFrame {
private JTextField word;
private JLabel label;
private JButton next;
private JButton restart;
private int index = 0;
int i=1;
private String[] words;
private int score = 0;
public yingyu(){
words = new String[] {"蘋果", "香蕉", "狗", "貓", "水"};
word = new JTextField();
Dimension size = new Dimension(60, 30);
word.setPreferredSize(size );
label = new JLabel(words[0]);
next = new JButton("下一道");
restart = new JButton("重新開始");
next.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(i<words.length){
label.setText(words[i]);
i++;}
else {i=1;
label.setText(words[0]);}
}
});
restart.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
label.setText(words[0]);
i=1;
}
});
setLayout(new FlowLayout(FlowLayout.CENTER, 3, 3));
add(label);
add(word);
add(next);
add(restart);
setBounds(100, 100, 300, 300);
setVisible(true);
}
public static void main(String[] args){
yingyu yingyu =new yingyu();
}
public void reload(){
label.setText(words[index]);
repaint();
}
}
Ⅵ java程序如何讓程序重新再跑一遍,就是我寫的這個游戲如何實現重新開始
使用方法調用,配合循環
寫一段偽代碼,可能會幫你理清思路:
do{
游戲開始運行;
...
..
//循環中可以用方法調用來運行游戲
//游戲失敗,給用戶提示
再玩一次?
接受用戶的選擇
//如果用戶選擇"是",再次循環,游戲重新開始
//如果用戶選擇」否",退出循環,游戲結束
}while(真);
Ⅶ 如何重新開始學java
可以在網上找些基礎教程,自己買些書學習,建議先學習VFP,是其他語言的基礎
Ⅷ 怎麼讓java 程序重新執行 從頭開始 輸入Y然後重新開始程序
quit到當前線程然後重新啟動新線程執行代碼!
沒學到線程就把你的功能寫到方法裡面!
按Y退出當前方法然後重新調用方法。
Ⅸ java 添加重新開始按鈕的方法
給按鈕添加一個監聽事件,監聽方法里實現當按下按鈕後結束當前進程,把所有參數都設置為初始值。