if(entscheidung==1) view.setTitle("Client"); | if(entscheidung==1) view.setTitle("Client"); | ||||
Transmitter model = new Transmitter(entscheidung); | 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 sendcontroller = new SendController(view,model); | ||||
sendcontroller.registerEvents(); | sendcontroller.registerEvents(); |
package controller; | 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 model.Transmitter; | ||||
import view.ChatView; | import view.ChatView; | ||||
* | * | ||||
* @author Apollo | * @author Apollo | ||||
*/ | */ | ||||
public class ConnectController | |||||
public class ConnectController implements ActionListener | |||||
{ | { | ||||
ChatView view; | ChatView view; | ||||
Transmitter model; | Transmitter model; | ||||
public ConnectController(ChatView view,Transmitter model) | |||||
public ConnectController(ChatView view,Transmitter model,int modus) | |||||
{ | { | ||||
this.view = view; | this.view = view; | ||||
this.model = model; | 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(); | |||||
} | } | ||||
} | } |
{ | { | ||||
private static final Logger lg = OhmLogger.getLogger(); | private static final Logger lg = OhmLogger.getLogger(); | ||||
private static final int PORT = 35000; | 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; | int modus; | ||||
private String nachricht; | private String nachricht; | ||||
return nachricht; | return nachricht; | ||||
} | } | ||||
/** | |||||
* @param IP_ADRESSE the IP_ADRESSE to set | |||||
*/ | |||||
public void setIP_ADRESSE(String IP_ADRESSE) | |||||
{ | |||||
this.IP_ADRESSE = IP_ADRESSE; | |||||
} | |||||
} | } |
</Constraint> | </Constraint> | ||||
</Constraints> | </Constraints> | ||||
</Component> | </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> | </SubComponents> | ||||
</Container> | </Container> | ||||
</SubComponents> | </SubComponents> |
*/ | */ | ||||
public class ChatView extends javax.swing.JFrame | 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 | * @param chatanzeige the chatanzeige to set | ||||
*/ | */ | ||||
jScrollPane3 = new javax.swing.JScrollPane(); | jScrollPane3 = new javax.swing.JScrollPane(); | ||||
chatanzeige = new javax.swing.JTextArea(); | chatanzeige = new javax.swing.JTextArea(); | ||||
inputField = new javax.swing.JTextField(); | 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(); | jMenuBar1 = new javax.swing.JMenuBar(); | ||||
jMenu1 = new javax.swing.JMenu(); | jMenu1 = new javax.swing.JMenu(); | ||||
jMenu2 = new javax.swing.JMenu(); | jMenu2 = new javax.swing.JMenu(); | ||||
jPanel1.add(jScrollPane3, java.awt.BorderLayout.CENTER); | jPanel1.add(jScrollPane3, java.awt.BorderLayout.CENTER); | ||||
jPanel1.add(inputField, java.awt.BorderLayout.PAGE_END); | 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); | getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER); | ||||
jMenu1.setText("File"); | jMenu1.setText("File"); | ||||
} | } | ||||
// Variables declaration - do not modify//GEN-BEGIN:variables | // Variables declaration - do not modify//GEN-BEGIN:variables | ||||
private javax.swing.JButton btnverbinden; | |||||
private javax.swing.JTextArea chatanzeige; | private javax.swing.JTextArea chatanzeige; | ||||
private javax.swing.JTextField inputField; | private javax.swing.JTextField inputField; | ||||
private javax.swing.JMenu jMenu1; | private javax.swing.JMenu jMenu1; | ||||
private javax.swing.JMenu jMenu2; | private javax.swing.JMenu jMenu2; | ||||
private javax.swing.JMenuBar jMenuBar1; | private javax.swing.JMenuBar jMenuBar1; | ||||
private javax.swing.JPanel jPanel1; | private javax.swing.JPanel jPanel1; | ||||
private javax.swing.JPanel jPanel2; | |||||
private javax.swing.JScrollPane jScrollPane3; | private javax.swing.JScrollPane jScrollPane3; | ||||
private javax.swing.JTextField txteigeneIP; | |||||
private javax.swing.JTextField txtzielIP; | |||||
// End of variables declaration//GEN-END:variables | // End of variables declaration//GEN-END:variables | ||||
} | } |