「java停止语句」java中暂停程序怎么写

博主:adminadmin 2023-01-16 14:42:13 444

本篇文章给大家谈谈java停止语句,以及java中暂停程序怎么写对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

java语句暂停

给你改了一下,在你所示的地方,加了一个线程。

---------------------------------------------------------------------------------------------------

public class xiancheng extends javax.swing.JFrame {

/** Creates new form xiancheng */

public xiancheng() {

initComponents();

}

/**

* This method is called from within the constructor to initialize the form.

* WARNING: Do NOT modify this code. The content of this method is always

* regenerated by the Form Editor.

*/

// GEN-BEGIN:initComponents

// editor-fold defaultstate="collapsed" desc="Generated Code"

private void initComponents() {

jButton1 = new javax.swing.JButton();

jButton2 = new javax.swing.JButton();

jButton3 = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

getContentPane().setLayout(null);

jButton1.setText("jButton1");

jButton1.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

jButton1ActionPerformed(evt);

}

});

getContentPane().add(jButton1);

jButton1.setBounds(30, 40, 81, 25);

jButton2.setText("jButton2");

getContentPane().add(jButton2);

jButton2.setBounds(120, 100, 81, 25);

jButton2.setVisible(false);

jButton3.setText("jButton3");

getContentPane().add(jButton3);

jButton3.setBounds(190, 190, 81, 25);

jButton3.setVisible(false);

setMinimumSize(new java.awt.Dimension(300, 300));

pack();

}// /editor-fold

// GEN-END:initComponents

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

jButton2.setVisible(true);

// Thread.sleep(5000);// -----在这里加线程暂停是没用的!请问要如何解决这个问题

new Thread(new Runnable() {

public void run() {

try {

Thread.sleep(5000);

jButton3.setVisible(true);

} catch (InterruptedException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}).start();

}

/**

* @param args

* the command line arguments

*/

public static void main(String args[]) {

java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {

new xiancheng().setVisible(true);

}

});

}

// GEN-BEGIN:variables

// Variables declaration - do not modify

private javax.swing.JButton jButton1;

private javax.swing.JButton jButton2;

private javax.swing.JButton jButton3;

// End of variables declaration//GEN-END:variables

}

Java程序中,什么关键词可以终止程序

break语句用在switch中,如果是别的中断的话,可以直接用个return即可解决,希望能帮到你。

java里什么语句能停止执行之后的语句,而不退出程序。

你可以在要停止的部分这样写

if(true){

    return ;//或者其他的操作,这样就会退出当前的方法,不执行后面的语句而且不退出程序

}

Java 单击按钮控制while循环停止

我告诉你方法,选我吧!、

1,你肯定是启动了main方法,循环执行某些任务,由于time0 是一个true条件,所以你一直关闭不了。

2,即使加了一个标记位,如一个按钮使得time0,但是在点按钮的时候却没有反应

3,这种问题就是多线程问题,你只有启动另外一个线程,当点击按钮时,改变那个标记位time的值 time=-1;这样才可以

关于java停止语句和java中暂停程序怎么写的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。