< prev index next >

src/demo/share/java2d/J2DBench/src/j2dbench/J2DBench.java

Print this page


   1 /*
   2  * Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.
   3  *
   4  * Redistribution and use in source and binary forms, with or without
   5  * modification, are permitted provided that the following conditions
   6  * are met:
   7  *
   8  *   - Redistributions of source code must retain the above copyright
   9  *     notice, this list of conditions and the following disclaimer.
  10  *
  11  *   - Redistributions in binary form must reproduce the above copyright
  12  *     notice, this list of conditions and the following disclaimer in the
  13  *     documentation and/or other materials provided with the distribution.
  14  *
  15  *   - Neither the name of Oracle nor the names of its
  16  *     contributors may be used to endorse or promote products derived
  17  *     from this software without specific prior written permission.
  18  *
  19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  20  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  21  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  23  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  24  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  25  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  26  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  27  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  28  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  29  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30  */
  31 
  32 /*
  33  * This source code is provided to illustrate the usage of a given feature
  34  * or technique and has been deliberately simplified. Additional steps
  35  * required for a production-quality application, such as security checks,
  36  * input validation and proper error handling, might not be present in
  37  * this sample code.
  38  */
  39 
  40 
  41 package j2dbench;
  42 


  43 import java.io.PrintWriter;
  44 import java.io.FileReader;
  45 import java.io.FileWriter;
  46 import java.io.LineNumberReader;
  47 import java.io.FileNotFoundException;
  48 import java.io.IOException;
  49 import java.io.File;
  50 import java.awt.Frame;
  51 import java.awt.Dimension;
  52 import java.awt.BorderLayout;
  53 import java.awt.event.ActionListener;
  54 import java.awt.event.ActionEvent;
  55 import java.awt.event.WindowAdapter;
  56 import java.awt.event.WindowEvent;
  57 import javax.swing.JFrame;
  58 import javax.swing.JButton;
  59 import javax.swing.JPanel;
  60 import javax.swing.BoxLayout;
  61 import javax.swing.JFileChooser;
  62 import javax.swing.JOptionPane;


 763                     lastResults = null;
 764                 }
 765             }
 766         });
 767         p.add(b);
 768 
 769         b = new JButton("Quit");
 770         b.addActionListener(new ActionListener() {
 771             public void actionPerformed(ActionEvent e) {
 772                 if (!saveOrDiscardLastResults()) {
 773                     return;
 774                 }
 775                 System.exit(0);
 776             }
 777         });
 778         p.add(b);
 779 
 780         f.getContentPane().add(p, BorderLayout.SOUTH);
 781         f.pack();
 782         f.setLocationRelativeTo(null);
 783         f.show();



 784     }
 785 
 786     public static void runTests(boolean showresults) {
 787         final TestEnvironment env = new TestEnvironment();
 788         Frame f = null;
 789         if (showresults) {
 790             f = new Frame("J2DBench test run");
 791             f.addWindowListener(new WindowAdapter() {
 792                 public void windowClosing(WindowEvent e) {
 793                     env.stop();
 794                 }
 795             });
 796             f.add(env.getCanvas());
 797             f.pack();
 798             f.show();
 799         }
 800         for (int i = 0; i < 5; i++) {
 801             env.idle();
 802         }
 803         env.runAllTests();
   1 /*
   2  * Copyright (c) 2002, 2020, Oracle and/or its affiliates. All rights reserved.
   3  *
   4  * Redistribution and use in source and binary forms, with or without
   5  * modification, are permitted provided that the following conditions
   6  * are met:
   7  *
   8  *   - Redistributions of source code must retain the above copyright
   9  *     notice, this list of conditions and the following disclaimer.
  10  *
  11  *   - Redistributions in binary form must reproduce the above copyright
  12  *     notice, this list of conditions and the following disclaimer in the
  13  *     documentation and/or other materials provided with the distribution.
  14  *
  15  *   - Neither the name of Oracle nor the names of its
  16  *     contributors may be used to endorse or promote products derived
  17  *     from this software without specific prior written permission.
  18  *
  19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  20  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  21  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  23  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  24  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  25  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  26  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  27  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  28  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  29  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30  */
  31 
  32 /*
  33  * This source code is provided to illustrate the usage of a given feature
  34  * or technique and has been deliberately simplified. Additional steps
  35  * required for a production-quality application, such as security checks,
  36  * input validation and proper error handling, might not be present in
  37  * this sample code.
  38  */
  39 
  40 
  41 package j2dbench;
  42 
  43 import java.awt.GraphicsEnvironment;
  44 import java.awt.Rectangle;
  45 import java.io.PrintWriter;
  46 import java.io.FileReader;
  47 import java.io.FileWriter;
  48 import java.io.LineNumberReader;
  49 import java.io.FileNotFoundException;
  50 import java.io.IOException;
  51 import java.io.File;
  52 import java.awt.Frame;
  53 import java.awt.Dimension;
  54 import java.awt.BorderLayout;
  55 import java.awt.event.ActionListener;
  56 import java.awt.event.ActionEvent;
  57 import java.awt.event.WindowAdapter;
  58 import java.awt.event.WindowEvent;
  59 import javax.swing.JFrame;
  60 import javax.swing.JButton;
  61 import javax.swing.JPanel;
  62 import javax.swing.BoxLayout;
  63 import javax.swing.JFileChooser;
  64 import javax.swing.JOptionPane;


 765                     lastResults = null;
 766                 }
 767             }
 768         });
 769         p.add(b);
 770 
 771         b = new JButton("Quit");
 772         b.addActionListener(new ActionListener() {
 773             public void actionPerformed(ActionEvent e) {
 774                 if (!saveOrDiscardLastResults()) {
 775                     return;
 776                 }
 777                 System.exit(0);
 778             }
 779         });
 780         p.add(b);
 781 
 782         f.getContentPane().add(p, BorderLayout.SOUTH);
 783         f.pack();
 784         f.setLocationRelativeTo(null);
 785         Rectangle usable = GraphicsEnvironment.getLocalGraphicsEnvironment()
 786                 .getMaximumWindowBounds().intersection(f.getBounds());
 787         f.setBounds(usable);
 788         f.setVisible(true);
 789     }
 790 
 791     public static void runTests(boolean showresults) {
 792         final TestEnvironment env = new TestEnvironment();
 793         Frame f = null;
 794         if (showresults) {
 795             f = new Frame("J2DBench test run");
 796             f.addWindowListener(new WindowAdapter() {
 797                 public void windowClosing(WindowEvent e) {
 798                     env.stop();
 799                 }
 800             });
 801             f.add(env.getCanvas());
 802             f.pack();
 803             f.show();
 804         }
 805         for (int i = 0; i < 5; i++) {
 806             env.idle();
 807         }
 808         env.runAllTests();
< prev index next >