Skip to content

Commit

Permalink
Prepared source for version 0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Tech-FZ authored Apr 13, 2022
1 parent 0d14a0b commit 8abd9e3
Show file tree
Hide file tree
Showing 17 changed files with 298 additions and 4 deletions.
Binary file modified bin/randopackage/RandochooseMain$1.class
Binary file not shown.
Binary file modified bin/randopackage/RandochooseMain$2.class
Binary file not shown.
Binary file modified bin/randopackage/RandochooseMain$3.class
Binary file not shown.
Binary file modified bin/randopackage/RandochooseMain$4.class
Binary file not shown.
Binary file modified bin/randopackage/RandochooseMain$5.class
Binary file not shown.
Binary file added bin/randopackage/RandochooseMain$6.class
Binary file not shown.
Binary file modified bin/randopackage/RandochooseMain.class
Binary file not shown.
Binary file added bin/randopackage/RandochooseUpdate$1.class
Binary file not shown.
Binary file added bin/randopackage/RandochooseUpdate.class
Binary file not shown.
Binary file not shown.
Binary file added bin/randopackage/RandochooseUpdateStageTwo$2.class
Binary file not shown.
Binary file added bin/randopackage/RandochooseUpdateStageTwo$3.class
Binary file not shown.
Binary file added bin/randopackage/RandochooseUpdateStageTwo.class
Binary file not shown.
5 changes: 5 additions & 0 deletions doc/Changelog English.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Randochoose 0.2.0 Alpha
- Completion: 13th April, 2022
- The Java VM processing bug has been fixed. If you close this program, you REALLY close it now! :)
- You want to profit from features and bugfixes like this, don't you? The Randochoose Update Management will be the feature which can serve you in this case.

Randochoose 0.1.0 Alpha
- Completion: 11th April, 2022
- Software is completely legalised.
Expand Down
28 changes: 24 additions & 4 deletions src/randopackage/RandochooseMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,24 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.File;
import java.util.concurrent.*;

public class RandochooseMain {

public static int majorVer = 0;
public static int minorVer1 = 1;
public static int minorVer1 = 2;
public static int minorVer2 = 0;

public static void main(String[] args) {
public static void main(String[] args) {
String link = "https://raw.githubusercontent.com/Tech-FZ/randochoose/main/vercheck.rdc";
File out = new File("vercheck.rdc");
new Thread(new RandochooseUpdate(link, out)).start();
RandochooseUpdateStageTwo.checkStage(majorVer, minorVer1, minorVer2, false);

JFrame mainFrame = new JFrame();
mainFrame.setTitle("Randochoose");
mainFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mainFrame.setSize(500, 300);
mainFrame.setLocationRelativeTo(null);

Expand All @@ -41,7 +47,7 @@ public static void main(String[] args) {

mainPanel.add(textPanel);

JPanel btnPanel = new JPanel(new GridLayout(1, 2, 10, 10));
JPanel btnPanel = new JPanel(new GridLayout(1, 3, 10, 10));

JButton chooseCandidateBtn = new JButton("Choose!");
chooseCandidateBtn.setFont(new Font("Arial", 0, 14));
Expand All @@ -54,6 +60,20 @@ public void actionPerformed(ActionEvent arg0) {

btnPanel.add(chooseCandidateBtn);

JButton updateBtn = new JButton("Check for updates");
updateBtn.setFont(new Font("Arial", 0, 14));

updateBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String link = "https://raw.githubusercontent.com/Tech-FZ/randochoose/main/vercheck.rdc";
File out = new File("vercheck.rdc");
new Thread(new RandochooseUpdate(link, out)).start();
RandochooseUpdateStageTwo.checkStage(majorVer, minorVer1, minorVer2, true);
}
});

btnPanel.add(updateBtn);

JButton aboutBtn = new JButton("About");
aboutBtn.setFont(new Font("Arial", 0, 14));

Expand Down
102 changes: 102 additions & 0 deletions src/randopackage/RandochooseUpdate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package randopackage;

import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;
import java.net.*;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class RandochooseUpdate implements Runnable {
String link;
File out;

public RandochooseUpdate(String link, File out) {
this.link = link;
this.out = out;
}

@Override
public void run() {
try {
URL url = new URL(link);
HttpURLConnection http = (HttpURLConnection)url.openConnection();
BufferedInputStream in = new BufferedInputStream(http.getInputStream());
FileOutputStream fos = new FileOutputStream(out);
BufferedOutputStream bout = new BufferedOutputStream(fos, 1024);
byte[] buffer = new byte[1024];
int read = 0;

while((read = in.read(buffer, 0, 1024)) >= 0) {
bout.write(buffer, 0, read);
}

bout.close();
in.close();
}

catch (Exception e) {
noInternet();
}

}

public static void noInternet() {
JDialog noEntryDialog = new JDialog();
noEntryDialog.setTitle("Randochoose Update Management");

JPanel noEntryPanel = new JPanel(new GridLayout(0, 1, 10, 10));

JLabel noticeLabel = new JLabel("Sorry, but Randochoose failed to connect to its GitHub repository!");
noticeLabel.setFont(new Font("Arial", 0, 16));
noEntryPanel.add(noticeLabel);

JLabel noticeLabel2 = new JLabel("This might have one of the following reasons:");
noticeLabel2.setFont(new Font("Arial", 0, 16));
noEntryPanel.add(noticeLabel2);

JLabel causeLbl1 = new JLabel("- You're most likely not connected to the internet. Please check your");
causeLbl1.setFont(new Font("Arial", 0, 14));
noEntryPanel.add(causeLbl1);

JLabel causeLbl2 = new JLabel(" internet connection and try again.");
causeLbl2.setFont(new Font("Arial", 0, 14));
noEntryPanel.add(causeLbl2);

JLabel causeLbl3 = new JLabel("- If it still fails, your administrator might have blocked access to GitHub.");
causeLbl3.setFont(new Font("Arial", 0, 14));
noEntryPanel.add(causeLbl3);

JLabel causeLbl4 = new JLabel(" Contact him or her for further information.");
causeLbl4.setFont(new Font("Arial", 0, 14));
noEntryPanel.add(causeLbl4);

JLabel causeLbl5 = new JLabel("- If these are all not the case, GitHub servers might be down at the moment.");
causeLbl5.setFont(new Font("Arial", 0, 14));
noEntryPanel.add(causeLbl5);

JLabel causeLbl6 = new JLabel(" In this case, try again when GitHub is online again.");
causeLbl6.setFont(new Font("Arial", 0, 14));
noEntryPanel.add(causeLbl6);

JButton okBtn = new JButton("OK!");
okBtn.setFont(new Font("Arial", 0, 14));

okBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
noEntryDialog.setVisible(false);
}
});

noEntryPanel.add(okBtn);

noEntryDialog.add(noEntryPanel);
noEntryDialog.pack();
noEntryDialog.setVisible(true);
}
}
167 changes: 167 additions & 0 deletions src/randopackage/RandochooseUpdateStageTwo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
package randopackage;

import java.io.*;
import java.net.URI;
import java.net.URISyntaxException;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class RandochooseUpdateStageTwo {
static String[] newestVer = new String[3];
static int[] newestVerInt = new int[3];

public static void checkStage(int majorVer, int minorVer1, int minorVer2, boolean manual) {
File file = new File("vercheck.rdc");

if (!file.canRead() || !file.isFile()) {
@SuppressWarnings("unused")
BufferedReader in = null;
}

try {
BufferedReader in = new BufferedReader(new FileReader("vercheck.rdc"));
String line = null;

int i = 0;

while ((line = in.readLine()) != null) {
newestVer[i] = line;
i++;
}

if (in != null) {
try {
in.close();
}

catch (Exception e) {

}
}
}

catch (Exception e) {

}

int i = 0;

while (i < newestVer.length) {
int verPart = Integer.parseInt(newestVer[i]);
newestVerInt[i] = verPart;
i++;
}

if (minorVer2 < newestVerInt[2] || minorVer1 < newestVerInt[1] || majorVer < newestVerInt[0]) {
int[] currentVer = {majorVer, minorVer1, minorVer2};
newVerAvailable(currentVer, newestVerInt);
}

else {
if (manual) {
isLatest();
}
}
}

public static void newVerAvailable(int[] currVer, int[] latestVer) {
JDialog noEntryDialog = new JDialog();
noEntryDialog.setTitle("Randochoose Update Management");

JPanel noEntryPanel = new JPanel(new GridLayout(0, 1, 10, 10));

JLabel noticeLabel = new JLabel("An update has been released.");
noticeLabel.setFont(new Font("Arial", 0, 16));
noEntryPanel.add(noticeLabel);

JLabel noticeLabel2 = new JLabel("You're currently running version " + currVer[0] + "." + currVer[1] + "." + currVer[2]);
noticeLabel2.setFont(new Font("Arial", 0, 16));
noEntryPanel.add(noticeLabel2);

JLabel noticeLabel3 = new JLabel("The latest version is " + latestVer[0] + "." + latestVer[1] + "." + latestVer[2]);
noticeLabel3.setFont(new Font("Arial", 0, 16));
noEntryPanel.add(noticeLabel3);

JLabel questionLbl = new JLabel("Do you want to be redirected to the GitHub repository of");
questionLbl.setFont(new Font("Arial", 0, 16));
noEntryPanel.add(questionLbl);

JLabel questionLbl2 = new JLabel("Randochoose to download the latest version?");
questionLbl2.setFont(new Font("Arial", 0, 16));
noEntryPanel.add(questionLbl2);

JPanel btnPanel = new JPanel(new GridLayout(1, 2, 10, 10));

JButton yesBtn = new JButton("Yes");
yesBtn.setFont(new Font("Arial", 0, 14));

yesBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
Desktop desk = Desktop.getDesktop();

try {
desk.browse(new URI("https://github.com/Tech-FZ/randochoose/releases"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

noEntryDialog.setVisible(false);
}
});

btnPanel.add(yesBtn);

JButton noBtn = new JButton("No");
noBtn.setFont(new Font("Arial", 0, 14));

noBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
noEntryDialog.setVisible(false);
}
});

btnPanel.add(noBtn);

noEntryPanel.add(btnPanel);

noEntryDialog.add(noEntryPanel);
noEntryDialog.pack();
noEntryDialog.setVisible(true);
}

public static void isLatest() {
JDialog noEntryDialog = new JDialog();
noEntryDialog.setTitle("Randochoose Update Management");

JPanel noEntryPanel = new JPanel(new GridLayout(3, 1, 10, 10));

JLabel noticeLabel = new JLabel("Don't know if you see this as good or bad, but...");
noticeLabel.setFont(new Font("Arial", 0, 16));
noEntryPanel.add(noticeLabel);

JLabel noticeLabel2 = new JLabel("...you're already running the latest version.");
noticeLabel2.setFont(new Font("Arial", 0, 16));
noEntryPanel.add(noticeLabel2);

JButton okBtn = new JButton("OK!");
okBtn.setFont(new Font("Arial", 0, 14));

okBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
noEntryDialog.setVisible(false);
}
});

noEntryPanel.add(okBtn);

noEntryDialog.add(noEntryPanel);
noEntryDialog.pack();
noEntryDialog.setVisible(true);
}
}

0 comments on commit 8abd9e3

Please sign in to comment.