Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save BodyEmulsion/896e55f091aa96ed5050397c84280c76 to your computer and use it in GitHub Desktop.
Save BodyEmulsion/896e55f091aa96ed5050397c84280c76 to your computer and use it in GitHub Desktop.
#Sun Oct 13 17:52:53 MSK 2019
gradle.version=5.2.1
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleJvm" value="11" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
</set>
</option>
<option name="useQualifiedModuleNames" value="true" />
</GradleProjectSettings>
</option>
</component>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_13" project-jdk-name="13" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="eb175477-6c7f-4706-a948-5859aa99f05f" name="Default Changelist" comment="" />
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="ExternalProjectsData">
<projectState path="$PROJECT_DIR$">
<ProjectState />
</projectState>
</component>
<component name="ExternalProjectsManager">
<system id="GRADLE">
<state>
<projects_view>
<tree_state>
<expand />
<select />
</tree_state>
</projects_view>
</state>
</system>
</component>
<component name="Git.Settings">
<option name="ROOT_SYNC" value="DONT_SYNC" />
</component>
<component name="ProjectId" id="1S9aeZCANpU3VMEmuyrxkNIojHw" />
<component name="PropertiesComponent">
<property name="last_opened_file_path" value="$PROJECT_DIR$/../Git/bin/git.exe" />
<property name="project.structure.last.edited" value="Modules" />
<property name="project.structure.proportion" value="0.15" />
<property name="project.structure.side.proportion" value="0.2" />
<property name="settings.editor.selected.configurable" value="settings.github" />
</component>
<component name="RunDashboard">
<option name="ruleStates">
<list>
<RuleState>
<option name="name" value="ConfigurationTypeDashboardGroupingRule" />
</RuleState>
<RuleState>
<option name="name" value="StatusDashboardGroupingRule" />
</RuleState>
</list>
</option>
</component>
<component name="RunManager">
<configuration name="MainWindow" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="MainWindow" />
<module name="kyr.main" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<recent_temporary>
<list>
<item itemvalue="Application.MainWindow" />
</list>
</recent_temporary>
</component>
<component name="SvnConfiguration">
<configuration>C:\Users\Vlad\AppData\Roaming\Subversion</configuration>
</component>
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="eb175477-6c7f-4706-a948-5859aa99f05f" name="Default Changelist" comment="" />
<created>1570978360893</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1570978360893</updated>
</task>
<servers />
</component>
</project>
plugins {
id 'java'
}
group 'Kyr'
version '1.0-SNAPSHOT'
apply plugin: "application"
mainClassName = 'MainWindow'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
}
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
#!/usr/bin/env sh
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn () {
echo "$*"
}
die () {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=$(save "$@")
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi
exec "$JAVACMD" "$@"
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windows variants
if not "%OS%" == "Windows_NT" goto win9xME_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
��sr
ThreadList��2�)s�LmyThreadArrayListtLjava/util/ArrayList;xpsrjava.util.ArrayListx����a�IsizexpwsrmyThread���E�s�IcounterIincrementValueI timeSleepLnametLjava/lang/String;LstatustLStatus;LthreadControlWindowtLThreadControlWindow;xpPdtms~rStatusxrjava.lang.EnumxptSTOPsrThreadControlWindow���þ�>LlabeltLjavax/swing/JLabel;xrjavax.swing.JFrame�I��7�IdefaultCloseOperationZrootPaneCheckingEnabledLaccessibleContextt'Ljavax/accessibility/AccessibleContext;LrootPanetLjavax/swing/JRootPane;LtransferHandlertLjavax/swing/TransferHandler;xrjava.awt.Frame%�L�l IframeSerializedDataVersionZ mbManagementZ resizableIstateZ undecoratedLmaximizedBoundstLjava/awt/Rectangle;LmenuBartLjava/awt/MenuBar;L ownedWindowstLjava/util/Vector;Ltitleq~xrjava.awt.Window>k���n
Z alwaysOnTopZautoRequestFocusZfocusableWindowStateZlocationByPlatformFopacityIstateZsyncLWRequestsIwindowSerializedDataVersionLfocusMgrtLjava/awt/FocusManager;LmodalExclusionTypet$Ljava/awt/Dialog$ModalExclusionType;LshapetLjava/awt/Shape;LtypetLjava/awt/Window$Type;L
warningStringq~xrjava.awt.Container@�s� 'IcontainerSerializedDataVersionZfocusCycleRootZfocusTraversalPolicyProviderI ncomponents[ componentt[Ljava/awt/Component;L
dispatchert Ljava/awt/LightweightDispatcher;L layoutMgrtLjava/awt/LayoutManager;LmaxSizetLjava/awt/Dimension;xrjava.awt.Component��Y�<��$ZautoFocusTransferOnDisposalIboundsOpIcomponentSerializedDataVersionZenabledJ eventMaskZfocusTraversalKeysEnabledZ focusableIheightZ
ignoreRepaintIisFocusTraversableOverriddenZisPackedZ
maxSizeSetZ
minSizeSetZnameExplicitlySetZ
newEventsOnlyZ prefSizeSetZvalidZvisibleIwidthIxIyLaccessibleContextq~L
backgroundtLjava/awt/Color;L
changeSupportt"Ljava/beans/PropertyChangeSupport;LcursortLjava/awt/Cursor;L
dropTargettLjava/awt/dnd/DropTarget;[focusTraversalKeyst[Ljava/util/Set;LfonttLjava/awt/Font;L
foregroundq~$LlocaletLjava/util/Locale;LmaxSizeq~"LminSizeq~"Lnameq~LpeerFontq~)Lpopupsq~LprefSizeq~"xpHA�e�psr javax.swing.plaf.ColorUIResourcekS�����xrjava.awt.Color���3uFfalphaIvalueLcstLjava/awt/color/ColorSpace;[ frgbvaluet[F[fvalueq~/xp����ppppsrjava.awt.Cursorojw��ItypeLnameq~xptDefault Cursorppsr
java.awt.Fontš5���VsIfontSerializedDataVersionF pointSizeIsizeIstyleLfRequestedAttributestLjava/util/Hashtable;Lnameq~xpA@ ptDialogxsrjava.awt.SystemColor>~`t.���xq~- pppsrjava.util.Locale~�`�0��IhashcodeLcountryq~L
extensionsq~Llanguageq~Lscriptq~Lvariantq~xp����tRUttruq~=q~=xpppq~6pppsrjava.awt.ComponentOrientation��E��c�I orientationxpppxur[Ljava.awt.Component;�
�uxpsrjavax.swing.JRootPaneGM���ԛZuseTrueDoubleBufferingIwindowDecorationStyleL contentPanetLjava/awt/Container;L
defaultButtontLjavax/swing/JButton;L glassPanetLjava/awt/Component;L layeredPanetLjavax/swing/JLayeredPane;LmenuBartLjavax/swing/JMenuBar;xrjavax.swing.JComponent?����j�F
alignmentXF
alignmentYZ autoscrollsIflagsZisAlignmentXSetZisAlignmentYSetZverifyInputWhenFocusTargetL actionMaptLjavax/swing/ActionMap;LancestorInputMaptLjavax/swing/InputMap;LbordertLjavax/swing/border/Border;L
focusInputMapq~KL
inputVerifiertLjavax/swing/InputVerifier;L listenerListt%Ljavax/swing/event/EventListenerList;L popupMenutLjavax/swing/JPopupMenu;LvetoableChangeSupportt"Ljava/beans/VetoableChangeSupport;LwindowInputMaptLjavax/swing/ComponentInputMap;xq~�ppsr java.beans.PropertyChangeSupportX��dWH`�I*propertyChangeSupportSerializedDataVersionLchildrenq~5LsourcetLjava/lang/Object;xppq~Rpxpppppq~;pppq~6pppq~@ppxuq~Asrjavax.swing.JPanel[���z�Dxq~I�psq~,����pppppppsrjavax.swing.plaf.FontUIResourceBć�"�Gxq~4A0 ptTahomaxsq~,�pppq~;pptnull.glassPanesq~ZA0 ptTahomaxpppq~@ppxuq~Apsrjava.awt.FlowLayout�6K[�9IalignZalignOnBaselineIhgapInewAlignIserialVersionOnStreamIvgapxppppx@pppppsr#javax.swing.event.EventListenerList�H�-s��xppxpppwxxsrjavax.swing.JLayeredPane <9���mZoptimizedDrawingPossibleLcomponentToLayerq~5xq~I�ppppppppq~;pptnull.layeredPaneq~6pppq~@ppxuq~Asq~W�pq~Yppppq~[q~]q~;pppq~_pppq~@ppxuq~Asrjavax.swing.JLabel,����� ZdisabledIconSetIhorizontalAlignmentIhorizontalTextPositionI iconTextGapImnemonicI
mnemonicIndexIverticalAlignmentIverticalTextPositionL defaultIcontLjavax/swing/Icon;L disabledIconq~mLlabelForq~FLtextq~xq~I�pq~Ysq~Spq~npxpppq~[q~]q~;pppq~_pppq~@ppxq~apppppx�@pppppsq~dpxpppwx
����pppt79xpsrjava.awt.GridLayout�#��K��IcolsIhgapIrowsIvgapxppppx@ pppppsq~dpxpppwtlayeredContainerLayersrjava.lang.Integer⠤���8Ivaluexrjava.lang.Number��� ���xp����xxpppppx@pppppsq~dpxpppwxppsr javax.swing.JRootPane$RootLayout��{�>�UnLthis$0q~xpq~RpppxA�srjavax.swing.ActionMap����z���Lparentq~Jxppwxsrjavax.swing.InputMap��f!ٟLparentq~Kxpsr#javax.swing.plaf.InputMapUIResource�H�Mכ�xq~~pwsrjavax.swing.KeyStroke�Cŗuv >xrjava.awt.AWTKeyStroke��"8��|�CkeyCharIkeyCodeI modifiersZ onKeyReleasexp��yAt postPopupsq~���
q~�xwxpppsq~dpxppsrjavax.swing.ComponentInputMapos��$�L componenttLjavax/swing/JComponent;xq~~pwxq~Rwxq~jpq~Xq~gpsrjava.awt.LightweightDispatcherG�M���ЉJ eventMaskLfocusq~FLnativeContainerq~DL nativeCursorq~&xppq~+psrjava.awt.BorderLayout�ב_ps� IhgapIvgapLcenterq~FLeastq~FL firstItemq~FL firstLineq~FLlastItemq~FLlastLineq~FLnorthq~FLsouthq~FLwestq~Fxpq~Rppppppppppsr&javax.swing.LayoutFocusTraversalPolicy;��ș]��xpsrjavax.swing.LayoutComparatorrW�UO�jZ
horizontalZ leftToRightxpwxx?�srjava.awt.FocusManager"����DL
focusOwnerq~FL focusRootq~Dxpq~+q~+~r"java.awt.Dialog$ModalExclusionTypexq~ t
NO_EXCLUDEppppppxpppq~
pxpq~Rpq~nx
rootProject.name = 'kyr'
import javax.swing.*;
import javax.swing.text.NumberFormatter;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.text.NumberFormat;
@SuppressWarnings("ALL")
public class MainWindow extends JFrame {
private static ThreadList threadList;
static private JButton startButton;
static private JButton pauseButton;
static private JButton stopButton;
static private JButton newButton;
static private JButton changeButton;
static private JButton deleteButton;
static private JButton infoButton;
static private DefaultListModel<String> defaultListModel = new DefaultListModel<String>();
static private JList<String> list;
static private JPanel mainPanel;
static private JPanel buttonPanel;
static private JScrollPane scrollPane;
private MainWindow(){
super("Test GUI");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
initializeWindowListener();
initializeMainPanel();
initializeThreadList();
initializeListAndScrollPane();
initializeButtonPanel();
initializeButtons();
setSize(400, 300);
setVisible(true);
}
private void initializeWindowListener(){
addWindowListener(new WindowListener() {
public void windowActivated (WindowEvent event) {}
public void windowClosed (WindowEvent event) {}
public void windowDeactivated(WindowEvent event) {}
public void windowDeiconified(WindowEvent event) {}
public void windowIconified (WindowEvent event) {}
public void windowOpened (WindowEvent event) {}
public void windowClosing (WindowEvent event) {
threadList.close();
}
});
}
private void initializeMainPanel(){
mainPanel = new JPanel();
setContentPane(mainPanel);
mainPanel.setLayout(new BoxLayout(mainPanel,BoxLayout.X_AXIS));
}
private void initializeButtonPanel(){
buttonPanel = new JPanel();
buttonPanel.setLayout(new GridLayout(0,1,0,0));
buttonPanel.setMaximumSize(new Dimension(200,Short.MAX_VALUE));
buttonPanel.setPreferredSize(new Dimension(150,Short.MAX_VALUE));
mainPanel.add(buttonPanel);
}
private void initializeThreadList(){
try {
threadList = ThreadList.getThreadList();
}
catch (Exception e){
e.printStackTrace();
}
}
private void initializeListAndScrollPane(){
list = new JList<String>(defaultListModel);
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
for(String name : threadList.getList()){
defaultListModel.addElement(name);
}
scrollPane = new JScrollPane(list);
mainPanel.add(scrollPane);
}
private void initializeButtons(){
initialiseStartButton();
initialisePauseButton();
initialiseStopButton();
initialiseNewButton();
initialiseChangeButton();
initialiseDeleteButton();
initialiseInfoButton();
}
private void initialiseStartButton(){
startButton = new JButton();
startButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
threadList.startThread(list.getSelectedIndex());
defaultListModel.clear();
for(String name : ThreadList.getThreadList().getList()){
defaultListModel.addElement(name);
}
}
});
startButton.setName("Start");
startButton.setText("Start");
buttonPanel.add(startButton);
}
private void initialisePauseButton(){
pauseButton = new JButton();
pauseButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
threadList.pauseThread(list.getSelectedIndex());
defaultListModel.clear();
for(String name : ThreadList.getThreadList().getList()){
defaultListModel.addElement(name);
}
}
});
pauseButton.setText("Pause");
buttonPanel.add(pauseButton);
}
private void initialiseStopButton(){
stopButton = new JButton();
stopButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
threadList.stopThread(list.getSelectedIndex());
defaultListModel.clear();
for(String name : ThreadList.getThreadList().getList()){
defaultListModel.addElement(name);
}
}
});
stopButton.setText("Stop");
buttonPanel.add(stopButton);
}
private void initialiseNewButton(){
newButton = new JButton();
newButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
NumberFormat format = NumberFormat.getInstance();
NumberFormatter formatter = new NumberFormatter(format);
formatter.setValueClass(Integer.class);
formatter.setMinimum(0);
formatter.setMaximum(Integer.MAX_VALUE);
formatter.setAllowsInvalid(false);
formatter.setCommitsOnValidEdit(true);
JTextField nameThread = new JTextField();
JTextField increment = new JTextField();
JTextField time = new JTextField();
Object[] message = {
"Name: ", nameThread,
"Increment: ", increment,
"Time: ",time
};
int option;
do{
option = JOptionPane.showConfirmDialog(null, message, "New thread", JOptionPane.OK_CANCEL_OPTION);
}
while(option != JOptionPane.OK_OPTION);
threadList.newThread(new myThread(
nameThread.getText(),
Integer.parseInt(increment.getText()),
Integer.parseInt(time.getText())
));
defaultListModel.clear();
for(String name : ThreadList.getThreadList().getList()){
defaultListModel.addElement(name);
}
}
});
newButton.setText("New");
buttonPanel.add(newButton);
}
private void initialiseChangeButton(){
changeButton = new JButton();
changeButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
NumberFormat format = NumberFormat.getInstance();
NumberFormatter formatter = new NumberFormatter(format);
formatter.setValueClass(Integer.class);
formatter.setMinimum(0);
formatter.setMaximum(Integer.MAX_VALUE);
formatter.setAllowsInvalid(false);
formatter.setCommitsOnValidEdit(true);
JTextField nameThread = new JTextField();
JTextField increment = new JTextField();
JTextField time = new JTextField();
Object[] message = {
"Name: ", nameThread,
"Increment: ", increment,
"Time: ",time
};
int option;
do{
option = JOptionPane.showConfirmDialog(null, message, "Change thread", JOptionPane.OK_CANCEL_OPTION);
threadList.changeThread(
list.getSelectedIndex(),
nameThread.getText(),
Integer.parseInt(increment.getText()),
Integer.parseInt(time.getText())
);
}
while(option != JOptionPane.OK_OPTION);
for(String name : ThreadList.getThreadList().getList()){
defaultListModel.addElement(name);
}
}
});
changeButton.setText("Change");
buttonPanel.add(changeButton);
}
private void initialiseDeleteButton(){
deleteButton = new JButton();
deleteButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
threadList.deleteThread(list.getSelectedIndex());
defaultListModel.clear();
for(String name : ThreadList.getThreadList().getList()){
defaultListModel.addElement(name);
}
}
});
deleteButton.setText("Delete");
buttonPanel.add(deleteButton);
}
private void initialiseInfoButton(){
infoButton = new JButton();
infoButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
JOptionPane.showInternalMessageDialog(getContentPane(),"JUST DO SOMETHING");
}
});
infoButton.setText("Info");
buttonPanel.add(infoButton);
}
private static void setStyle(){
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
setStyle();
new MainWindow();
}
}
import java.io.Serializable;
public class myThread extends java.lang.Thread implements Serializable {
private String name;
private int counter = 0;
private int incrementValue = 1;
private int timeSleep = 1000;
private Status status = Status.STOP;
private ThreadControlWindow threadControlWindow;
myThread(String name,int incrementValue,int timeSleep){
this.name = name;
this.incrementValue = incrementValue;
this.timeSleep = timeSleep;
this.threadControlWindow = new ThreadControlWindow(counter,status,name);
}
public void run() {
while (true) {
ThreadLoop();
}
}
private void waitCommandTimeout(){
int statusCheckRate = 200;
try {
Thread.sleep(statusCheckRate);
} catch (Exception e) {
e.printStackTrace();
}
}
private void incrementTime(){
try {
Thread.sleep(timeSleep);
} catch (Exception e) {
e.printStackTrace();
}
}
private void ThreadLoop(){
while (status != Status.STOP) {
while (status == Status.WORK) {
threadControlWindow.refresh(counter);
counter += incrementValue;
incrementTime();
}
waitCommandTimeout();
}
waitCommandTimeout();
}
String getString(){
return name + " Status: " + status.getString();
}
void pauseThread(){
if(status!=Status.STOP)
status = Status.PAUSE;
}
void startThread(){
status = Status.WORK;
threadControlWindow.setVisible(true);
}
void stopThread(){
status = Status.STOP;
threadControlWindow.setVisible(false);
}
Status getStatus(){
return status;
}
void changeThread(String newName, int newIncrementValue, int newTimeSleep){
name = newName;
incrementValue = newIncrementValue;
timeSleep = newTimeSleep;
}
}
public enum Status {
WORK,
PAUSE,
STOP,
ERROR;
public String getString(){
switch (this){
case STOP:
return "Stop";
case WORK:
return "Working";
case PAUSE:
return "Pause";
default:
return "ERROR";
}
}
}
import javax.swing.*;
import java.awt.*;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
class ThreadControlWindow extends JFrame {
private JLabel label;
ThreadControlWindow(Integer counter, Status status,String name){
super(name);
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
//initializeWindowListener();
JPanel panel = new JPanel();
setContentPane(panel);
label = new JLabel();
panel.add(label);
panel.setLayout(new GridLayout());
setSize(200+(name.length()*10),65);
}
//НЕ РАБОТАЕТ ПОСЛЕ ЧИСТКИ ПРОЕКТА И/ИЛИ ИЗМЕНЕНИЯ ПОТОКОВ
// private void initializeWindowListener(){
// addWindowListener(new WindowListener() {
//
// public void windowActivated (WindowEvent event) {}
// public void windowClosed (WindowEvent event) {}
// public void windowDeactivated(WindowEvent event) {}
// public void windowDeiconified(WindowEvent event) {}
// public void windowIconified (WindowEvent event) {}
// public void windowOpened (WindowEvent event) {}
// public void windowClosing (WindowEvent event) {
// JOptionPane.showMessageDialog(label,"Please press the \"Stop\" button to close this window");
// }
// });
// }
void refresh(Integer counter){
label.setText(counter.toString());
}
}
import java.io.*;
import java.util.ArrayList;
class ThreadList implements Serializable {
private static ThreadList threadList;
private ArrayList<myThread> myThreadArrayList;
private static String address = "save.bat";
private ThreadList() throws Exception {
ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream(address));
this.myThreadArrayList = ((ThreadList) objectInputStream.readObject()).myThreadArrayList;
//myThreadArrayList = new ArrayList<myThread>();
//myThreadArrayList.add(new myThread("test",1,1000));
}
static synchronized ThreadList getThreadList(){
try {
if (threadList == null) {
threadList = new ThreadList();
}
}
catch (Exception e){
e.printStackTrace();
}
return threadList;
}
void close(){
try {
ThreadList threadList = new ThreadList();
threadList.myThreadArrayList = this.myThreadArrayList;
ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream(address));
objectOutputStream.writeObject(threadList);
objectOutputStream.close();
}
catch (Exception e){
e.printStackTrace();
}
}
ArrayList<String> getList(){
ArrayList<String> list = new ArrayList<String>();
for(myThread myThread : myThreadArrayList){
list.add(myThread.getString());
}
return list;
}
void startThread(int id){
if(!myThreadArrayList.get(id).isAlive())
myThreadArrayList.get(id).start();
myThreadArrayList.get(id).startThread();
}
void pauseThread(int id){
if(myThreadArrayList.get(id).getStatus() != Status.STOP) {
myThreadArrayList.get(id).pauseThread();
}
}
void stopThread(int id){
if(myThreadArrayList.get(id).getStatus() != Status.STOP) {
myThreadArrayList.get(id).stopThread();
}
}
void deleteThread(int id){
myThreadArrayList.remove(id);
}
void changeThread(int id, String newName, int incr,int time){
myThreadArrayList.get(id).changeThread(newName, incr,time);
}
void newThread(myThread myThread) {
myThreadArrayList.add(myThread);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment