/*
* Main.java
*
* Created on 11 février 2007, 19:38
*/
package javaapplication11;
import javax.swing.*;
/**
*
* @author André
*/
public class Main {
/** Creates a new instance of Main */
public Main() {
NewJFrame frame = new NewJFrame();
frame.getEinLabel().setText("Hallo");
frame.setVisible(true);
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
new Main();
}
}
/*
* NewJFrame.java
*
* Created on 11 février 2007, 19:39
*/
package javaapplication11;
import javax.swing.*;
/**
*
* @author André
*/
public class NewJFrame extends javax.swing.JFrame {
/** Creates new form NewJFrame */
public NewJFrame() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setText("jLabel1");
getContentPane().add(jLabel1, java.awt.BorderLayout.NORTH);
java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
setBounds((screenSize.width-400)/2, (screenSize.height-300)/2, 400, 300);
}// </editor-fold>
public JLabel getEinLabel(){
return jLabel1;
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JLabel jLabel1;
// End of variables declaration
}
package socket_test_server;
import java.net.*;
import java.io.*;
import java.util.*;
public class Main {
/** Creates a new instance of Main */
public static void main(String[] args) {
NewJFrame frame = new NewJFrame();
frame.setVisible(true);
try{
ServerSocket server = new ServerSocket(124);
Socket s;
while(true) {
// Auf verbindung warten
s = server.accept();
// kommunikation an einen nebenläufigen Thread abgeben
ServerThread t = new ServerThread(s);
t.start();
// und wieder auf neue Verbindungen warten
}
}catch(Exception e){
System.out.println(e);
System.exit(1);
}
}
}
/*
* NewJFrame.java
*
* Created on 11. Februar 2007, 11:17
*/
package socket_test_server;
import javax.swing.*;
/**
*
* @author Lazybone
*/
public class NewJFrame extends javax.swing.JFrame {
/** Creates new form NewJFrame */
public NewJFrame() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
private void initComponents() {
jButton1 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jButton1.setText("Exit");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jLabel1.setText("jLabel1");
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 119, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jButton1))
.addContainerGap(24, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(jButton1)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jLabel1)
.addContainerGap(37, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(3);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame().setVisible(true);
}
});
}
public JLabel getEinLabel() {
return jLabel1;
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
// End of variables declaration
}
package socket_test_server;
import java.net.*;
import java.io.*;
import java.util.*;
public class ServerThread extends Thread {
private Socket s;
public ServerThread(Socket s) {
this.s = s;
}
public void run() {
try{
// lesen
BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
String text = in.readLine();
// schreiben
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
String eingabe = text.toUpperCase();
NewJFrame frame = new NewJFrame();
frame.getEinLabel().setText("Hallo");
System.out.println("Test");
//frame.repaint();
if(eingabe.compareTo("1") == 0) {
out.write("1");
}else{
out.write("2");
}
out.newLine();
out.flush();
// aufräumen
out.close();
in.close();
}catch(Exception e){
System.exit(0);
}
}
}