Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Laget GUI, men ikke koblet til resten atm. #1

  • Loading branch information...
commit 20204fa940dd0b0cf81e4effaff4a6acfaa3b00f 1 parent 96f75b4
@maads authored
View
57 src/gui/SntGUI.java
@@ -0,0 +1,57 @@
+package gui;
+
+import java.awt.GridLayout;
+
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JOptionPane;
+import javax.swing.JTextField;
+
+public class SntGUI extends JFrame {
+
+ private static JButton startBtn;
+ private static JTextField intervalField;
+ private static JLabel infoLabel;
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ new SntGUI();
+ }
+
+ public SntGUI() {
+ this.setLayout(new GridLayout(0, 1));
+ infoLabel = new JLabel("Hvor ofte vil du se etter endringer (sekund)?");
+ intervalField = new JTextField("30");
+ startBtn = new JButton("Start");
+ add(infoLabel);
+ add(intervalField);
+ add(startBtn);
+ startBtn.addActionListener(new TaskAL());
+ setSize(350, 80);
+ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ setVisible(true);
+
+ }
+
+ public static long getInterval() {
+ long interval;
+ try {
+ interval = Long.parseLong(intervalField.getText()) * 1000; // millisec
+ } catch (Exception e) {
+ interval = 30000;
+ JOptionPane.showMessageDialog(null, "Ikke et tall, prøv igjen.");
+ return -1;
+ }
+ return interval;
+ }
+
+ protected static void updateGUIafterLaunch() {
+ infoLabel.setText("Sjekker VG.no hvert " + intervalField.getText() + " sekund.");
+ startBtn.setVisible(false);
+ intervalField.setVisible(false);
+ }
+
+}
View
24 src/gui/TaskAL.java
@@ -0,0 +1,24 @@
+package gui;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import snt.Snt;
+
+public class TaskAL implements ActionListener {
+
+ private static long intervall;
+
+ public TaskAL() {
+ }
+
+ @Override
+ public void actionPerformed(ActionEvent arg0) {
+ intervall = SntGUI.getInterval();
+ if(intervall > 0) {
+ SntGUI.updateGUIafterLaunch();
+// new Snt(intervall);
+ }
+ }
+
+}
View
11 src/snt/Snt.java
@@ -9,8 +9,8 @@
public class Snt {
public static String latestHash;
-
- public static void main(String[] args) {
+
+ public Snt(long intervall) {
Document doc = null;
try {
@@ -26,12 +26,17 @@ public static void main(String[] args) {
latestHash = "md5hash" ; //MD5(artikler);
Timer t = new Timer();
- t.scheduleAtFixedRate(new SntTask(), 0, 15000);
+ t.scheduleAtFixedRate(new SntTask(), 0, intervall);
}
catch (Exception e) {
e.printStackTrace();
}
+
+ }
+
+ public static void main(String[] args) {
+ new Snt(15000);
}
public static String MD5(Object obj)
throws java.security.NoSuchAlgorithmException {
View
2  src/snt/SntTask.java
@@ -42,8 +42,6 @@
private static String newHash;
private static Elements articleURLs;
- // TODO GUI
-
public SntTask() {
Document doc = null;
try {
Please sign in to comment.
Something went wrong with that request. Please try again.