@@ -38,10 +38,8 @@ public class Start | |||
if(entscheidung==1) view.setTitle("Client"); | |||
Transmitter model = new Transmitter(entscheidung); | |||
ConnectController conncontroller = new ConnectController(view,model); | |||
Thread chatter = new Thread(model); | |||
chatter.start(); | |||
ConnectController conncontroller = new ConnectController(view,model,entscheidung); | |||
conncontroller.registerEvents(); | |||
SendController sendcontroller = new SendController(view,model); | |||
sendcontroller.registerEvents(); |
@@ -6,6 +6,12 @@ | |||
package controller; | |||
import java.awt.event.ActionEvent; | |||
import java.awt.event.ActionListener; | |||
import java.net.InetAddress; | |||
import java.net.UnknownHostException; | |||
import java.util.logging.Level; | |||
import java.util.logging.Logger; | |||
import model.Transmitter; | |||
import view.ChatView; | |||
@@ -13,14 +19,41 @@ import view.ChatView; | |||
* | |||
* @author Apollo | |||
*/ | |||
public class ConnectController | |||
public class ConnectController implements ActionListener | |||
{ | |||
ChatView view; | |||
Transmitter model; | |||
public ConnectController(ChatView view,Transmitter model) | |||
public ConnectController(ChatView view,Transmitter model,int modus) | |||
{ | |||
this.view = view; | |||
this.model = model; | |||
if(modus==0) | |||
{ | |||
Thread chatter = new Thread(model); | |||
chatter.start(); | |||
} | |||
try | |||
{ | |||
String t; | |||
t = InetAddress.getLocalHost().getHostAddress(); | |||
view.getTxteigeneIP().setText(t); | |||
} | |||
catch (UnknownHostException ex) | |||
{ | |||
Logger.getLogger(ConnectController.class.getName()).log(Level.SEVERE, null, ex); | |||
} | |||
} | |||
public void registerEvents() | |||
{ | |||
view.getBtnverbinden().addActionListener(this); | |||
} | |||
@Override | |||
public void actionPerformed(ActionEvent arg0) | |||
{ | |||
model.setIP_ADRESSE(view.getTxtzielIP().getText()); | |||
Thread chatter = new Thread(model); | |||
chatter.start(); | |||
} | |||
} |
@@ -27,7 +27,7 @@ public class Transmitter extends Observable implements Runnable | |||
{ | |||
private static final Logger lg = OhmLogger.getLogger(); | |||
private static final int PORT = 35000; | |||
private static final String IP_ADRESSE = "127.0.0.1"; | |||
private String IP_ADRESSE = "127.0.0.1"; | |||
int modus; | |||
private String nachricht; | |||
@@ -151,4 +151,12 @@ public class Transmitter extends Observable implements Runnable | |||
return nachricht; | |||
} | |||
/** | |||
* @param IP_ADRESSE the IP_ADRESSE to set | |||
*/ | |||
public void setIP_ADRESSE(String IP_ADRESSE) | |||
{ | |||
this.IP_ADRESSE = IP_ADRESSE; | |||
} | |||
} |
@@ -77,6 +77,40 @@ | |||
</Constraint> | |||
</Constraints> | |||
</Component> | |||
<Container class="javax.swing.JPanel" name="jPanel2"> | |||
<Properties> | |||
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor"> | |||
<Dimension value="[0, 0]"/> | |||
</Property> | |||
</Properties> | |||
<Constraints> | |||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription"> | |||
<BorderConstraints direction="First"/> | |||
</Constraint> | |||
</Constraints> | |||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignFlowLayout"/> | |||
<SubComponents> | |||
<Component class="javax.swing.JTextField" name="txteigeneIP"> | |||
<Properties> | |||
<Property name="editable" type="boolean" value="false"/> | |||
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor"> | |||
<Dimension value="[200, 26]"/> | |||
</Property> | |||
</Properties> | |||
</Component> | |||
<Component class="javax.swing.JTextField" name="txtzielIP"> | |||
<Properties> | |||
<Property name="text" type="java.lang.String" value="192.168.0.1"/> | |||
</Properties> | |||
</Component> | |||
<Component class="javax.swing.JButton" name="btnverbinden"> | |||
<Properties> | |||
<Property name="text" type="java.lang.String" value="Verbinden"/> | |||
</Properties> | |||
</Component> | |||
</SubComponents> | |||
</Container> | |||
</SubComponents> | |||
</Container> | |||
</SubComponents> |
@@ -11,6 +11,28 @@ package view; | |||
*/ | |||
public class ChatView extends javax.swing.JFrame | |||
{ | |||
/** | |||
* @return the btnverbinden | |||
*/ | |||
public javax.swing.JButton getBtnverbinden() | |||
{ | |||
return btnverbinden; | |||
} | |||
/** | |||
* @return the txteigeneIP | |||
*/ | |||
public javax.swing.JTextField getTxteigeneIP() | |||
{ | |||
return txteigeneIP; | |||
} | |||
/** | |||
* @return the txtzielIP | |||
*/ | |||
public javax.swing.JTextField getTxtzielIP() | |||
{ | |||
return txtzielIP; | |||
} | |||
/** | |||
* @param chatanzeige the chatanzeige to set | |||
*/ | |||
@@ -56,6 +78,10 @@ public class ChatView extends javax.swing.JFrame | |||
jScrollPane3 = new javax.swing.JScrollPane(); | |||
chatanzeige = new javax.swing.JTextArea(); | |||
inputField = new javax.swing.JTextField(); | |||
jPanel2 = new javax.swing.JPanel(); | |||
txteigeneIP = new javax.swing.JTextField(); | |||
txtzielIP = new javax.swing.JTextField(); | |||
btnverbinden = new javax.swing.JButton(); | |||
jMenuBar1 = new javax.swing.JMenuBar(); | |||
jMenu1 = new javax.swing.JMenu(); | |||
jMenu2 = new javax.swing.JMenu(); | |||
@@ -72,6 +98,20 @@ public class ChatView extends javax.swing.JFrame | |||
jPanel1.add(jScrollPane3, java.awt.BorderLayout.CENTER); | |||
jPanel1.add(inputField, java.awt.BorderLayout.PAGE_END); | |||
jPanel2.setMinimumSize(new java.awt.Dimension(0, 0)); | |||
txteigeneIP.setEditable(false); | |||
txteigeneIP.setMinimumSize(new java.awt.Dimension(200, 26)); | |||
jPanel2.add(txteigeneIP); | |||
txtzielIP.setText("192.168.0.1"); | |||
jPanel2.add(txtzielIP); | |||
btnverbinden.setText("Verbinden"); | |||
jPanel2.add(btnverbinden); | |||
jPanel1.add(jPanel2, java.awt.BorderLayout.PAGE_START); | |||
getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER); | |||
jMenu1.setText("File"); | |||
@@ -138,12 +178,16 @@ public class ChatView extends javax.swing.JFrame | |||
} | |||
// Variables declaration - do not modify//GEN-BEGIN:variables | |||
private javax.swing.JButton btnverbinden; | |||
private javax.swing.JTextArea chatanzeige; | |||
private javax.swing.JTextField inputField; | |||
private javax.swing.JMenu jMenu1; | |||
private javax.swing.JMenu jMenu2; | |||
private javax.swing.JMenuBar jMenuBar1; | |||
private javax.swing.JPanel jPanel1; | |||
private javax.swing.JPanel jPanel2; | |||
private javax.swing.JScrollPane jScrollPane3; | |||
private javax.swing.JTextField txteigeneIP; | |||
private javax.swing.JTextField txtzielIP; | |||
// End of variables declaration//GEN-END:variables | |||
} |