diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8194aff --- /dev/null +++ b/.gitignore @@ -0,0 +1,56 @@ +# +# Project specific excludes +# + +tomcat + +# +# Default excludes +# + +# Binaries +*.7z +*.dmg +*.gz +*.iso +*.jar +*.rar +*.tar +*.zip +*.war +*.ear +*.sar +*.class + +# Maven +target/ + +# IntelliJ project files +*.iml +*.iws +*.ipr +.idea/ + +# eclipse project file +.settings/ +.classpath +.project + +# NetBeans specific +nbproject/private/ +build/ +nbbuild/ +dist/ +nbdist/ +nbactions.xml +nb-configuration.xml + + +# OS +.DS_Store + +# Misc +*.swp +release.properties +pom.xml.releaseBackup +pom.xml.tag diff --git a/README.md b/README.md new file mode 100644 index 0000000..a6ea072 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# Countdown for streaming +#### Use this simple Java app to add a countdown to your stream! +When you start the countdown it creates a .txt file, called timer.txt, in the same directory where the .jar file is and you must read it using your favourite streaming software (OBS, XSplit, etc). diff --git a/build.xml b/build.xml new file mode 100644 index 0000000..bb77df6 --- /dev/null +++ b/build.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + Builds, tests, and runs the project Cronometro. + + + diff --git a/manifest.mf b/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml new file mode 100644 index 0000000..e23bafb --- /dev/null +++ b/nbproject/build-impl.xml @@ -0,0 +1,1420 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No tests executed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + Must select one file in the IDE or set profile.class + This target only works when run from inside the NetBeans IDE. + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + + + Must select some files in the IDE or set test.includes + + + + + Must select one file in the IDE or set run.class + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + Must select some files in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + Must select one file in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties new file mode 100644 index 0000000..dcc5483 --- /dev/null +++ b/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=21fdb6ac +build.xml.script.CRC32=8092b1de +build.xml.stylesheet.CRC32=8064a381@1.80.1.48 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=21fdb6ac +nbproject/build-impl.xml.script.CRC32=b48c38da +nbproject/build-impl.xml.stylesheet.CRC32=830a3534@1.80.1.48 diff --git a/nbproject/project.properties b/nbproject/project.properties new file mode 100644 index 0000000..dd22949 --- /dev/null +++ b/nbproject/project.properties @@ -0,0 +1,80 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=Cronometro +application.vendor=Gianluca +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# Files in build.classes.dir which should be excluded from distribution jar +dist.archive.excludes= +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/Cronometro.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +file.reference.FileManager.jar=lib\\FileManager.jar +includes=** +jar.compress=false +javac.classpath=\ + ${libs.absolutelayout.classpath}:\ + ${file.reference.FileManager.jar} +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.external.vm=true +javac.processorpath=\ + ${javac.classpath} +javac.source=1.8 +javac.target=1.8 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=cronometro.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +project.license=mit +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project. +# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. +# To set system properties for unit tests define test-sys-prop.name=value: +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/nbproject/project.xml b/nbproject/project.xml new file mode 100644 index 0000000..8d88bee --- /dev/null +++ b/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + Cronometro + + + + + + + + + diff --git a/src/cronometro/Main.form b/src/cronometro/Main.form new file mode 100644 index 0000000..b693121 --- /dev/null +++ b/src/cronometro/Main.form @@ -0,0 +1,294 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/cronometro/Main.java b/src/cronometro/Main.java new file mode 100644 index 0000000..589bad6 --- /dev/null +++ b/src/cronometro/Main.java @@ -0,0 +1,417 @@ +/* + * The MIT License + * + * Copyright 2018 Acerbis Gianluca . + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package cronometro; + +import com.acerbisgianluca.filemanager.FileManager; +import java.io.IOException; +import java.util.Timer; +import java.util.TimerTask; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.swing.JOptionPane; + +/** + * + * @author Acerbis Gianluca + */ +public class Main extends javax.swing.JFrame { + + private long time; + private boolean isRunning; + private Timer cron; + + private long totalSecs; + private Timer timer; + private FileManager fm; + + /** + * Creates new form Main + */ + public Main() { + initComponents(); + + time = 0; + isRunning = false; + cron = new Timer(); + + totalSecs = 0; + fm = new FileManager(); + } + + /** + * 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. + */ + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + tabbedPane = new javax.swing.JTabbedPane(); + panelCron = new javax.swing.JPanel(); + lblCron = new javax.swing.JLabel(); + lblIsRunning = new javax.swing.JLabel(); + btnStart = new javax.swing.JButton(); + btnPause = new javax.swing.JButton(); + btnStop = new javax.swing.JButton(); + panelTimer = new javax.swing.JPanel(); + lblTimer = new javax.swing.JLabel(); + txtTimer = new javax.swing.JFormattedTextField(); + lblSet = new javax.swing.JLabel(); + btnSet = new javax.swing.JButton(); + checkSave = new javax.swing.JCheckBox(); + btnReset = new javax.swing.JButton(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + setTitle("Cronometro e Timer per Stream!"); + setName("main"); // NOI18N + + tabbedPane.setTabLayoutPolicy(javax.swing.JTabbedPane.SCROLL_TAB_LAYOUT); + tabbedPane.setPreferredSize(new java.awt.Dimension(600, 600)); + + lblCron.setFont(new java.awt.Font("Impact", 1, 70)); // NOI18N + lblCron.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + lblCron.setText("00:00:00"); + lblCron.setToolTipText(""); + lblCron.setAlignmentX(100.0F); + lblCron.setAlignmentY(0.0F); + lblCron.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); + lblCron.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); + + lblIsRunning.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N + lblIsRunning.setForeground(new java.awt.Color(255, 0, 0)); + lblIsRunning.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + lblIsRunning.setText(" "); + lblIsRunning.setAlignmentY(0.0F); + + btnStart.setFont(new java.awt.Font("Calibri", 0, 18)); // NOI18N + btnStart.setText("Inizia"); + btnStart.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + btnStartActionPerformed(evt); + } + }); + + btnPause.setFont(new java.awt.Font("Calibri", 0, 18)); // NOI18N + btnPause.setText("Pausa"); + btnPause.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + btnPauseActionPerformed(evt); + } + }); + + btnStop.setFont(new java.awt.Font("Calibri", 0, 18)); // NOI18N + btnStop.setText("Stop"); + btnStop.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + btnStopActionPerformed(evt); + } + }); + + javax.swing.GroupLayout panelCronLayout = new javax.swing.GroupLayout(panelCron); + panelCron.setLayout(panelCronLayout); + panelCronLayout.setHorizontalGroup( + panelCronLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(panelCronLayout.createSequentialGroup() + .addGap(73, 73, 73) + .addGroup(panelCronLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(lblIsRunning, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGroup(panelCronLayout.createSequentialGroup() + .addComponent(btnStart, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 72, Short.MAX_VALUE) + .addComponent(btnPause, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(65, 65, 65) + .addComponent(btnStop, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addComponent(lblCron, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addGap(61, 61, 61)) + ); + panelCronLayout.setVerticalGroup( + panelCronLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelCronLayout.createSequentialGroup() + .addGap(34, 34, 34) + .addComponent(lblCron) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(lblIsRunning) + .addGap(18, 18, 18) + .addGroup(panelCronLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(btnPause) + .addComponent(btnStop) + .addComponent(btnStart)) + .addContainerGap(16, Short.MAX_VALUE)) + ); + + tabbedPane.addTab("Cronometro", panelCron); + + lblTimer.setFont(new java.awt.Font("Impact", 1, 70)); // NOI18N + lblTimer.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + lblTimer.setText("00:00:00"); + lblTimer.setToolTipText(""); + lblTimer.setAlignmentX(100.0F); + lblTimer.setAlignmentY(0.0F); + lblTimer.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); + lblTimer.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); + + try { + txtTimer.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##:##:##"))); + } catch (java.text.ParseException ex) { + ex.printStackTrace(); + } + txtTimer.setHorizontalAlignment(javax.swing.JTextField.LEFT); + txtTimer.setText("00:00:00 "); + txtTimer.setFont(new java.awt.Font("Calibri", 0, 18)); // NOI18N + + lblSet.setFont(new java.awt.Font("Calibri", 0, 18)); // NOI18N + lblSet.setText("Inserisci il timer (hh:mm:ss)"); + + btnSet.setFont(new java.awt.Font("Calibri", 0, 18)); // NOI18N + btnSet.setText("Imposta"); + btnSet.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + btnSetActionPerformed(evt); + } + }); + + checkSave.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N + checkSave.setText("Salva su file (si trova nella stessa cartella del programma)"); + + btnReset.setFont(new java.awt.Font("Calibri", 0, 18)); // NOI18N + btnReset.setText("Reset"); + btnReset.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + btnResetActionPerformed(evt); + } + }); + + javax.swing.GroupLayout panelTimerLayout = new javax.swing.GroupLayout(panelTimer); + panelTimer.setLayout(panelTimerLayout); + panelTimerLayout.setHorizontalGroup( + panelTimerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(panelTimerLayout.createSequentialGroup() + .addGap(68, 68, 68) + .addGroup(panelTimerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(panelTimerLayout.createSequentialGroup() + .addComponent(checkSave) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addGroup(panelTimerLayout.createSequentialGroup() + .addComponent(lblTimer, javax.swing.GroupLayout.DEFAULT_SIZE, 461, Short.MAX_VALUE) + .addGap(66, 66, 66)) + .addGroup(panelTimerLayout.createSequentialGroup() + .addComponent(lblSet) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(txtTimer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(18, 18, 18) + .addComponent(btnSet) + .addGap(18, 18, 18) + .addComponent(btnReset) + .addGap(0, 0, Short.MAX_VALUE)))) + ); + panelTimerLayout.setVerticalGroup( + panelTimerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(panelTimerLayout.createSequentialGroup() + .addContainerGap() + .addComponent(lblTimer) + .addGap(18, 18, 18) + .addGroup(panelTimerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelTimerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(txtTimer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(btnSet) + .addComponent(btnReset)) + .addComponent(lblSet)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(checkSave) + .addContainerGap()) + ); + + panelTimerLayout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {btnSet, txtTimer}); + + tabbedPane.addTab("Timer", panelTimer); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(tabbedPane, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(tabbedPane, javax.swing.GroupLayout.DEFAULT_SIZE, 245, Short.MAX_VALUE) + ); + + pack(); + setLocationRelativeTo(null); + }// //GEN-END:initComponents + + private void btnStartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnStartActionPerformed + if(isRunning){ + lblIsRunning.setText("Il cronometro è già avviato!"); + Timer warning = new Timer(); + warning.schedule(new TimerTask() { + @Override + public void run() { + lblIsRunning.setText(" "); + } + }, 3000); + } + else { + lblCron.setText("00:00:00"); + isRunning = true; + cron.scheduleAtFixedRate(new TimerTask() { + @Override + public void run() { + time++; + long hours = time / 3600; + long minutes = (time % 3600) / 60; + long seconds = time % 60; + + String sTime = String.format("%02d:%02d:%02d", hours, minutes, seconds); + + lblCron.setText(sTime); + } + }, 1000, 1000); + } + }//GEN-LAST:event_btnStartActionPerformed + + private void btnPauseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPauseActionPerformed + cron.cancel(); + cron = new Timer(); + isRunning = false; + }//GEN-LAST:event_btnPauseActionPerformed + + private void btnStopActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnStopActionPerformed + cron.cancel(); + cron = new Timer(); + isRunning = false; + time = 0; + }//GEN-LAST:event_btnStopActionPerformed + + private void btnSetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSetActionPerformed + if(timer != null) + timer.cancel(); + + String sTimer = txtTimer.getText(); + int hours = Integer.parseInt(sTimer.substring(0, 2)); + int minutes = Integer.parseInt(sTimer.substring(3, 5)); + int seconds = Integer.parseInt(sTimer.substring(6)); + totalSecs = (hours * 3600) + (minutes * 60) + seconds; + String sTime = String.format("%02d:%02d:%02d", hours, minutes, seconds); + lblTimer.setText(sTime); + + timer = new Timer(); + timer.scheduleAtFixedRate(new TimerTask() { + @Override + public void run() { + if(totalSecs > 0) { + totalSecs--; + long hours = totalSecs / 3600; + long minutes = (totalSecs % 3600) / 60; + long seconds = totalSecs % 60; + + String sTime = String.format("%02d:%02d:%02d", hours, minutes, seconds); + + lblTimer.setText(sTime); + + if(checkSave.isSelected()){ + try { + fm.stringToFile(sTime, "timer.txt"); + } catch (IOException ex) { + timer.cancel(); + JOptionPane.showMessageDialog(panelTimer, "C'è stato un errore inaspettato nel salvataggio!\nSe esiste già un file chiamato 'timer.txt' nella cartella del programma provare ad eliminarlo.", "Errore col file :(", JOptionPane.ERROR_MESSAGE, null); + lblTimer.setText("00:00:00"); + txtTimer.setText("00:00:00"); + timer = null; + } + } + } + else { + timer.cancel(); + timer = null; + } + } + }, 1000, 1000); + }//GEN-LAST:event_btnSetActionPerformed + + private void btnResetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnResetActionPerformed + timer.cancel(); + timer = null; + txtTimer.setText("00:00:00"); + lblTimer.setText("00:00:00"); + try { + fm.stringToFile("00:00:00", "timer.txt"); + } catch (IOException ex) { + JOptionPane.showMessageDialog(panelTimer, "C'è stato un errore inaspettato nel salvataggio!\nSe esiste già un file chiamato 'timer.txt' nella cartella del programma provare ad eliminarlo.", "Errore col file :(", JOptionPane.ERROR_MESSAGE, null); + } + }//GEN-LAST:event_btnResetActionPerformed + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + /* Set the Nimbus look and feel */ + // + /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. + * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html + */ + try { + for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { + if ("Windows".equals(info.getName())) { + javax.swing.UIManager.setLookAndFeel(info.getClassName()); + break; + } + } + } catch (ClassNotFoundException ex) { + java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (InstantiationException ex) { + java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (javax.swing.UnsupportedLookAndFeelException ex) { + java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + // + + /* Create and display the form */ + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + new Main().setVisible(true); + } + }); + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton btnPause; + private javax.swing.JButton btnReset; + private javax.swing.JButton btnSet; + private javax.swing.JButton btnStart; + private javax.swing.JButton btnStop; + private javax.swing.JCheckBox checkSave; + private javax.swing.JLabel lblCron; + private javax.swing.JLabel lblIsRunning; + private javax.swing.JLabel lblSet; + private javax.swing.JLabel lblTimer; + private javax.swing.JPanel panelCron; + private javax.swing.JPanel panelTimer; + private javax.swing.JTabbedPane tabbedPane; + private javax.swing.JFormattedTextField txtTimer; + // End of variables declaration//GEN-END:variables +}