profilermethodtest.java

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

JAVA
150
字号
/*
 * ProfilerMethodTest.java
 *
 * Created on 2006年3月30日, 上午9:02
 */

package org.netbeans.profiler.profilermethod;

import java.text.ParseException;
import javax.swing.text.MaskFormatter;

/**
 *
 * @author  Administrator
 */
public class ProfilerMethodTest extends javax.swing.JFrame {
    
    /** Creates new form ProfilerMethodTest */
    public ProfilerMethodTest() {
        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() {
        jLabel1 = new javax.swing.JLabel();
        jFormattedTextField1 = new javax.swing.JFormattedTextField(getFormatter());
        jCheckBox1 = new javax.swing.JCheckBox();
        jButton1 = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("\u6c42\u7d20\u6570");
        setResizable(false);
        jLabel1.setFont(new java.awt.Font("宋体", 0, 14));
        jLabel1.setText("\u8bf7\u8f93\u5165\u4e00\u4e2a\u6574\u6570");

        jFormattedTextField1.setFont(new java.awt.Font("SansSerif", 0, 14));

        jCheckBox1.setFont(new java.awt.Font("宋体", 0, 14));
        jCheckBox1.setText("\u4f18\u5316");
        jCheckBox1.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        jCheckBox1.setMargin(new java.awt.Insets(0, 0, 0, 0));

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

        jLabel2.setFont(new java.awt.Font("宋体", 0, 14));

        jLabel3.setFont(new java.awt.Font("宋体", 0, 14));

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .add(jLabel1)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .add(jFormattedTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 150, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(7, 7, 7)
                        .add(jCheckBox1)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jButton1)
                        .add(25, 25, 25))
                    .add(layout.createSequentialGroup()
                        .add(jLabel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 370, Short.MAX_VALUE)
                        .add(24, 24, 24))
                    .add(layout.createSequentialGroup()
                        .add(jLabel3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 370, Short.MAX_VALUE)
                        .add(24, 24, 24))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(15, 15, 15)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jButton1)
                    .add(jFormattedTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jCheckBox1)
                    .add(jLabel1))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jLabel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jLabel3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(20, Short.MAX_VALUE))
        );
        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
          int max=Integer.parseInt(this.jFormattedTextField1.getText().trim());
          boolean optmize=this.jCheckBox1.isSelected();
          long timeMs = -1;
          timeMs=System.currentTimeMillis();
          int result=doCountPrimeNumbers (max, optmize);
          timeMs = System.currentTimeMillis() - timeMs;
          String time = (timeMs/1000) + " 秒," + (timeMs % 1000) + "毫秒。";  
          this.jLabel2.setText("比"+max+"小的最大素数为"+result+"。");
          this.jLabel3.setText("用时:"+time);
    }//GEN-LAST:event_jButton1ActionPerformed
    private int doCountPrimeNumbers (int max, boolean isOptimized ) {
        if(!isOptimized || calculator == null)  {
          calculator = new PrimeNumbers ();
        }        
        if( isOptimized == true )
        return calculator.calculateOptmize (max); 
        else
        return calculator.calculate (max); 
    }
    private MaskFormatter getFormatter(){
      MaskFormatter mFormatter=null;
      try{
        mFormatter=new MaskFormatter("*****");//其中s为掩码字符串
        mFormatter.setValidCharacters("0123456789");
        mFormatter.setPlaceholderCharacter('0');   
      }
      catch(java.text.ParseException e){
      System.out.println(e.getMessage());
      }
      return mFormatter;
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JFormattedTextField jFormattedTextField1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    // End of variables declaration//GEN-END:variables
    PrimeNumbers calculator;
}

⌨️ 快捷键说明

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