Skip to content
Snippets Groups Projects
Commit a2d3888a authored by Robert Goldmann's avatar Robert Goldmann
Browse files

initial commit

parents
No related branches found
No related tags found
No related merge requests found
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry combineaccessrules="false" kind="src" path="/_Tools"/>
<classpathentry kind="output" path="bin"/>
</classpath>
bin/
\ No newline at end of file
.project 0 → 100644
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>LoadingBar</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
package de.deadlocker8.loadingbar.main;
import java.util.Arrays;
import java.util.Locale;
import java.util.ResourceBundle;
import de.deadlocker8.loadingbar.ui.Controller;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.stage.Stage;
import logger.LogLevel;
import logger.Logger;
public class Main extends Application
{
public static ResourceBundle bundle = ResourceBundle.getBundle("de/deadlocker8/loadingbar/main/", Locale.GERMANY);
@Override
public void start(Stage stage)
{
try
{
FXMLLoader loader = new FXMLLoader(getClass().getClassLoader().getResource("de/deadlocker8/loadingbar/ui/GUI.fxml"));
Parent root = (Parent)loader.load();
Scene scene = new Scene(root, 600, 600);
((Controller)loader.getController()).init(stage);
stage.setResizable(true);
stage.getIcons().add(new Image("/de/deadlocker8/loadingbar/resources/icon.png"));
stage.setTitle(bundle.getString("app.name"));
stage.setScene(scene);
stage.show();
}
catch(Exception e)
{
Logger.log(LogLevel.ERROR, Logger.exceptionToString(e));
}
}
public static void main(String[] args)
{
if(Arrays.asList(args).contains("debug"))
{
Logger.setLevel(LogLevel.ALL);
Logger.log(LogLevel.INFO, "Running in Debug Mode");
}
else
{
Logger.setLevel(LogLevel.ERROR);
}
Logger.log(LogLevel.INFO, bundle.getString("app.name") + " - v" + bundle.getString("version.name") + " - (versioncode: " + bundle.getString("version.code") + ") from " + bundle.getString("version.date"));
launch(args);
}
}
\ No newline at end of file
app.name=LoadingBar
version.code=0
version.name=0.0.0
version.date=18.12.16
author=Robert Goldmann
\ No newline at end of file
src/de/deadlocker8/loadingbar/resources/icon.png

2.63 KiB

package de.deadlocker8.loadingbar.ui;
import java.util.Locale;
import java.util.Random;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.control.ProgressBar;
import javafx.scene.image.Image;
import javafx.stage.Stage;
import tools.AlertGenerator;
public class Controller
{
@FXML private Label label;
@FXML private ProgressBar progressBar;
private Stage stage;
private Image icon = new Image("de/deadlocker8/loadingbar/resources/icon.png");
private final ResourceBundle bundle = ResourceBundle.getBundle("de/deadlocker8/loadingbar/main/", Locale.GERMANY);
private CountdownTimer timer;
public void init(Stage stage)
{
this.stage = stage;
}
public void buttonStart()
{
Random random = new Random();
int targetPercentage = 10 + random.nextInt(90 - 10 + 1);
label.setText(String.valueOf(targetPercentage));
progressBar.setProgress(0.0);
timer = new CountdownTimer(4.0, this);
}
public void buttonStop()
{
stop(timer.stop());
}
public void updateProgress(double value)
{
progressBar.setProgress(value);
}
public void stop(double value)
{
int userPercentage = (int)(value * 100);
label.setText(label.getText() + " - " + userPercentage);
}
public Stage getStage()
{
return stage;
}
public void about()
{
AlertGenerator.showAboutAlert(bundle.getString("app.name"), bundle.getString("version.name"), bundle.getString("version.code"), bundle.getString("version.date"), bundle.getString("author"), icon, stage, null, false);
}
}
\ No newline at end of file
package de.deadlocker8.loadingbar.ui;
import java.util.Timer;
import java.util.TimerTask;
import javafx.application.Platform;
public class CountdownTimer
{
private double count;
private double time;
private Controller controller;
private Timer timer;
private TimerTask task;
public CountdownTimer(double seconds, Controller controller)
{
this.count = seconds;
this.controller = controller;
start();
}
public void start()
{
time = 0.0;
task = new TimerTask()
{
@Override
public void run()
{
Platform.runLater(()->{
try
{
controller.updateProgress(time/count);
}
catch(Exception e)
{
}
});
if(time < count)
{
time += 0.01;
}
if(Math.abs(time - count) <= 0.0001)
{
Platform.runLater(()->{
controller.stop(1.0);
});
timer.cancel();
}
}
};
timer = new Timer();
timer.schedule(task, 0, 10);
}
public double stop()
{
timer.cancel();
timer.purge();
return time / count;
}
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ProgressBar?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>
<AnchorPane prefHeight="400.0" prefWidth="400.0" xmlns="http://javafx.com/javafx/8.0.60" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.deadlocker8.loadingbar.ui.Controller">
<children>
<ProgressBar fx:id="progressBar" layoutX="25.0" layoutY="129.0" prefWidth="200.0" progress="0.0" AnchorPane.leftAnchor="25.0" AnchorPane.rightAnchor="25.0" />
<Button layoutX="174.0" layoutY="174.0" mnemonicParsing="false" onAction="#buttonStart" text="Start" />
<Label fx:id="label" layoutX="174.0" layoutY="89.0" prefHeight="27.0" prefWidth="147.0">
<font>
<Font name="System Bold" size="18.0" />
</font>
</Label>
<Button layoutX="240.0" layoutY="174.0" mnemonicParsing="false" onAction="#buttonStop" text="Stop" />
</children>
</AnchorPane>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment