diff --git a/src/client/Client.java b/src/client/Client.java index 5fafbcc..09abe68 100644 --- a/src/client/Client.java +++ b/src/client/Client.java @@ -1,6 +1,39 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ package client; +import gui.Hub; +import gui.Login; +import javax.swing.SwingUtilities; + +/** + * + * @author Kyrre + */ public class Client { - + + public static Login login = new Login(); + public static Hub hub = new Hub(); + public static SocketClient sockCli; + + public static void main(String[] args) { + + sockCli = new SocketClient("localhost", 6667); + sockCli.run(); + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + login.setVisible(true); + + } + }); + + //sockCli.close(); + + } } + diff --git a/src/client/Constants.java b/src/client/Constants.java deleted file mode 100644 index dd91915..0000000 --- a/src/client/Constants.java +++ /dev/null @@ -1,12 +0,0 @@ - -package client; - -/** - * - * @author Kyrre - */ -public class Constants { - - public static final String SUPER_USERNAME = "scott"; - public static final String SUPER_PASSWORD = "tiger"; -} diff --git a/src/client/DbDownload.java b/src/client/DbDownload.java index 1136ac7..8c6235f 100644 --- a/src/client/DbDownload.java +++ b/src/client/DbDownload.java @@ -1,6 +1,5 @@ package client; -import gui.GUI; import helpclasses.CommEnum; import helpclasses.CommMessage; import helpclasses.Owner; @@ -11,6 +10,6 @@ public class DbDownload { public static void loadFarms(){ ArrayList metadata = new ArrayList(); metadata.add(ServerData.owner); - GUI.sockCli.sendMessage(new CommMessage(CommEnum.GETFARMS, metadata)); + Client.sockCli.sendMessage(new CommMessage(CommEnum.GETFARMS, metadata)); } } diff --git a/src/gui/GUI.java b/src/gui/GUI.java deleted file mode 100644 index 42c022c..0000000 --- a/src/gui/GUI.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package gui; - -import javax.swing.SwingUtilities; -import client.SocketClient; - -/** - * - * @author Kyrre - */ -public class GUI { - - static Login login = new Login(); - static Hub hub = new Hub(); - public static SocketClient sockCli; - - public static void main(String[] args) { - - sockCli = new SocketClient("localhost", 6667); - sockCli.run(); - SwingUtilities.invokeLater(new Runnable() { - - @Override - public void run() { - login.setVisible(true); - - } - }); - - //sockCli.close(); - - } -} - diff --git a/src/gui/Hub.java b/src/gui/Hub.java index 8fe2e42..2875c31 100644 --- a/src/gui/Hub.java +++ b/src/gui/Hub.java @@ -6,6 +6,7 @@ import java.util.ArrayList; +import client.Client; import client.DbDownload; import client.ServerData; import helpclasses.CommEnum; @@ -393,7 +394,7 @@ private void addFarmAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FI addFarmName.setText(null); ArrayList metadata = new ArrayList(); metadata.add(new Farm(-1, farmName, ServerData.owner.getOwnerId())); - GUI.sockCli.sendMessage(new CommMessage(CommEnum.ADDFARM,metadata)); + Client.sockCli.sendMessage(new CommMessage(CommEnum.ADDFARM,metadata)); DbDownload.loadFarms(); initRemoveFarm(); }else{ @@ -407,7 +408,7 @@ private void removeFarmAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN System.out.print(farmToRemove); ArrayList metadata = new ArrayList(); metadata.add(ServerData.getFarmByNameAndRemove(farmToRemove)); - GUI.sockCli.sendMessage(new CommMessage(CommEnum.REMOVEFARM, metadata)); + Client.sockCli.sendMessage(new CommMessage(CommEnum.REMOVEFARM, metadata)); initRemoveFarm(); }//GEN-LAST:event_removeFarmAddActionPerformed @@ -418,7 +419,7 @@ private void addSheepAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-F addSheepName.setText(null); ArrayList sheep = new ArrayList(); sheep.add(new Sheep(-1, name, birthYear, ServerData.getFarmByName(farmName).getFarmId(), ServerData.owner.getOwnerId())); - GUI.sockCli.sendMessage(new CommMessage(CommEnum.ADDSHEEP, sheep)); + Client.sockCli.sendMessage(new CommMessage(CommEnum.ADDSHEEP, sheep)); }//GEN-LAST:event_addSheepAddActionPerformed private void removeSheepRemoveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeSheepRemoveActionPerformed @@ -426,7 +427,7 @@ private void removeSheepRemoveActionPerformed(java.awt.event.ActionEvent evt) {/ removeSheepID.setText(null); ArrayList sheep = new ArrayList(); sheep.add(new Sheep(id, "", -1, -1, -1)); - GUI.sockCli.sendMessage(new CommMessage(CommEnum.REMOVESHEEP, sheep)); + Client.sockCli.sendMessage(new CommMessage(CommEnum.REMOVESHEEP, sheep)); }//GEN-LAST:event_removeSheepRemoveActionPerformed diff --git a/src/gui/Login.java b/src/gui/Login.java index dafd58f..58eea8b 100644 --- a/src/gui/Login.java +++ b/src/gui/Login.java @@ -15,6 +15,7 @@ import javax.swing.JOptionPane; +import client.Client; import client.DbDownload; import client.ServerData; @@ -123,8 +124,8 @@ private void loginActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:e if(isUsernameAndPassword(username, password)){ this.setVisible(false); DbDownload.loadFarms(); - GUI.hub.setVisible(true); - GUI.hub.initComp(); + Client.hub.setVisible(true); + Client.hub.initComp(); System.out.println(ServerData.owner); System.out.println(ServerData.farms.get(0).getName()); System.out.println(ServerData.farms.get(1).getName()); @@ -165,7 +166,7 @@ private boolean isUsernameAndPassword(String username, String password) { ArrayList al = new ArrayList(); al.add(username); al.add(password); - GUI.sockCli.sendMessage(new CommMessage(CommEnum.LOGIN, al)); + Client.sockCli.sendMessage(new CommMessage(CommEnum.LOGIN, al)); return client.ServerData.isLoggedIn; } }