Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.JMenu;
- import javax.swing.JFrame;
- import javax.swing.JButton;
- import javax.swing.JOptionPane;
- import javax.swing.JMenuBar;
- import javax.swing.JTextField;
- import javax.swing.AbstractAction;
- import java.awt.GridLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- public class SimpleBench extends JFrame implements ActionListener, Runnable {
- public static void main(String[] args) {
- SimpleBench jframe = new SimpleBench();
- jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- jframe.setVisible(true);
- jframe.setResizable(false);
- }
- SimpleBench() {
- setTitle("Простой Java Benchmark");
- setSize(400, 300);
- GridLayout gl = new GridLayout(2, 1);
- setLayout(gl);
- JMenu fileMenu = new JMenu("Файл");
- JMenu aboutMenu = new JMenu("Информация");
- fileMenu.add(new AbstractAction("Выход (Alt + F4)") {
- @Override
- public void actionPerformed(ActionEvent event) {
- System.exit(0);
- }
- });
- aboutMenu.add(new AbstractAction("Об Авторе") {
- @Override
- public void actionPerformed(ActionEvent event) {
- JOptionPane
- .showConfirmDialog(
- null,
- "Евгений Осипов, 2012 год. \n"
- + "[email protected], www.fastandclever.ru",
- "Об Авторе", JOptionPane.PLAIN_MESSAGE,
- JOptionPane.PLAIN_MESSAGE);
- }
- });
- jb = new JButton("Начать Benchmark!");
- jb.addActionListener(this);
- jtf = new JTextField();
- jtf.setEditable(false);
- JMenuBar menuBar = new JMenuBar();
- setJMenuBar(menuBar);
- menuBar.add(fileMenu);
- menuBar.add(aboutMenu);
- add(jb);
- add(jtf);
- }
- @Override
- public void actionPerformed(ActionEvent e) {
- thd = new Thread(this);
- thd.start();
- }
- @Override
- public void run() {
- jb.setEnabled(false);
- int i;
- double epochS = System.currentTimeMillis();
- for (i = 0; i < 10000000; i++) {
- jb.setText("(0-9999999): " + i);
- }
- double epochF = System.currentTimeMillis();
- double resms = epochF - epochS;
- double ress = resms / 1000;
- jtf.setText(i + " tics // " + resms + " ms ~ " + ress + " s");
- jb.setEnabled(true);
- }
- private Thread thd = null;
- private JButton jb = null;
- private JTextField jtf = null;
- }
Advertisement
Add Comment
Please, Sign In to add comment