Witam wszystkich ! Mam do was gorącą prośbę :) jeżeli możecie i wiecie coś na temat błędu jaki popełniam to prosze napiszcie. Mianowicie chodzi o to że nie pojawia się ramka i inne komponenty(tutaj nie jest to istotne).
jeżeli usunę Serwer g=new Serwer(); z metody NewJFrame() ramka się pokaże jeżeli jednak to będzie to uruchomi ją ale nie pokaże ramki.
package GG;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class NewJFrame extends javax.swing.JFrame {
public NewJFrame() throws InterruptedException {
initComponents();
Serwer g=new Serwer();
}
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(0, 400, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(0, 300, Short.MAX_VALUE)
);
pack();
}// </editor-fold>
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
try {
new NewJFrame().setVisible(true);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
});
}
// Variables declaration - do not modify
// End of variables declaration
}
class Serwer
{
int w=1;
ArrayList klienci=new ArrayList();
int vb=-1;
public Serwer() throws InterruptedException {
try {
ServerSocket serwer=new ServerSocket(2007);
while(true)
{
Socket incoming=serwer.accept();
// System.out.println(w);
Runnable r=new customer(incoming,w);
// System.out.println(r);
Thread t=new Thread(r);
t.start();
w++;
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
private class customer implements Runnable
{
public customer(Socket i, int c)
{
incoming=i;
counter=c;
}
public void run()
{
try
{
try
{
InputStream inStream = incoming.getInputStream();
OutputStream outStream = incoming.getOutputStream();
Scanner in = new Scanner(inStream);
PrintWriter out = new PrintWriter(outStream,true);
String line = in.nextLine();
for(int i=0; i<klienci.size(); i++)
{
if(line.trim().equals((String)klienci.get(i)) && i!=vb)
{
line=JOptionPane.showInputDialog("Podaj imie");
i=vb;
i=-1;
}
}
if(klienci.size()<5)
{
klienci.add(line);
}
else
{
out.println("z");
incoming.close();
Thread.currentThread().interrupt();
}
out.println(line);
boolean done=true;
while(done)
{
// System.out.println("jestem wpetli");
line = in.nextLine();
System.out.println(line);
out.println(line);
if(line.equals("BYE"))
{
line = in.nextLine();
// System.out.println("tu powinno byc ostanie line -->"+line);
for(int i = 0; i<klienci.size();i++)
{
if(line.equals((String)klienci.get(i)))
{
System.out.println((String)klienci.get(i)+" Opóścił GG_2000");
klienci.remove(i);
}
}
for(int s=0;s<klienci.size();s++)
{
System.out.println((String)klienci.get(s));
}
w--;
// System.out.println(w);
done = false;
Thread.currentThread().interrupt();
}
}
}
finally
{
incoming.close();
System.out.println("Połączenie zamknięte");
}
}
catch(IOException e)
{}
}
private Socket incoming;
private int counter;
}
}