profilerswingtest.java

来自「精通NetBeans光盘源代码,很好很好的资料」· Java 代码 · 共 142 行

JAVA
142
字号
/*
 * ProfilerSwingTest.java
 *
 * Created on 2006年3月24日, 下午3:42
 */

package org.netbeans.profiler.profilerswing;

/**
 *
 * @author  Administrator
 */
public class ProfilerSwingTest extends javax.swing.JFrame {
    
    /** Creates new form ProfilerSwingTest */
    public ProfilerSwingTest() {
        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.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        jSpinner1 = new javax.swing.JSpinner();
        jLabel1 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Swing\u7ebf\u7a0b");
        setResizable(false);
        jSpinner1.setFont(new java.awt.Font("Courier", 0, 14));

        jLabel1.setFont(new java.awt.Font("宋体", 0, 14));
        jLabel1.setText("\u8ba1\u7b97\u7684\u79d2\u6570");

        jButton1.setText("\u542f\u52a8");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("\u5173\u95ed\u7a97\u4f53");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .add(34, 34, 34)
                .add(jLabel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 78, Short.MAX_VALUE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jSpinner1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 171, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(21, 21, 21))
            .add(layout.createSequentialGroup()
                .add(66, 66, 66)
                .add(jButton1)
                .add(36, 36, 36)
                .add(jButton2)
                .addContainerGap(64, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(24, 24, 24)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 29, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jSpinner1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 30, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(26, 26, 26)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jButton1)
                    .add(jButton2))
                .addContainerGap(30, Short.MAX_VALUE))
        );
        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
// TODO add your handling code here:
       /*  seconds=Integer.parseInt(this.jSpinner1.getValue().toString());
           long breakTime = System.currentTimeMillis() + (seconds*1000);
            while (true) {
                if (System.currentTimeMillis() >= breakTime) {
                    break;
                }
            }
          notifyUser(seconds);    */
           
        (new Thread()
           {
               public void run()
               {
                  seconds=Integer.parseInt(jSpinner1.getValue().toString());
                  long breakTime = System.currentTimeMillis() + (seconds*1000);
                  while (true) {
                      if (System.currentTimeMillis() >= breakTime) {
                        break;
                    }                
                  }  
                 notifyUser(seconds);
               }
           }).start();          
           
           
    }//GEN-LAST:event_jButton1ActionPerformed

    
    
    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
// TODO add your handling code here:
        System.exit(0);
    }//GEN-LAST:event_jButton2ActionPerformed
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {

    }

    private void notifyUser(int seconds) {
        javax.swing.JOptionPane.showConfirmDialog(this,"一共运行了"+seconds+"秒!","信息提示",javax.swing.JOptionPane.PLAIN_MESSAGE);
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JSpinner jSpinner1;
    // End of variables declaration//GEN-END:variables
    private int seconds;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?