Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
J

Joshua Waring

@Joshua Waring
About
Posts
20
Topics
5
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Share Code With Others dissappeared
    J Joshua Waring

    Solved the issue, Adblocker was blocking the Share Code button which takes you to %project%/share I was already contacted via Email where we sorted things out ;D

    Site Bugs / Suggestions question

  • Share Code With Others dissappeared
    J Joshua Waring

    I can confirm that the link is visible under Firefox (just downloaded it to test)

    Site Bugs / Suggestions question

  • Share Code With Others dissappeared
    J Joshua Waring

    Am I the only one who's missing the Share Code With Others button? It should be visible at the top under the code tab, but its not and it's not visible under any other tabs Is this just me? It was there yesterday.

    Site Bugs / Suggestions question

  • LWJGL Texture error
    J Joshua Waring

    If it helps anyone, the problem was that the texture size wasn't a power of two, which caused them problem, support for textures which aren't n^2 in openGL 2.1 The used one was openGL 1.1

    Java help csharp

  • LWJGL Texture error
    J Joshua Waring

    Since gamedev doesn't have the fastest responces... here's a link :) please look http://www.gamedev.net/topic/630416-texture-loading-problem-using-lwjgl-and-slick-util-to-import/

    Java help csharp

  • Object parsing non-static
    J Joshua Waring

    From my understanding so far from the Java tutorials, but there was a question I wanted to clarify. When creation of a Object which isn't static, each decleration of the object with Object object = new Object() will create a new instance, if it was static wouldn't that mean instead of creating multiple instances, instead of only existing as one instance. As a non static would they then be independent of each other?

    public class One{
    Object object = new Object();

    public static void main(String\[\] args){
    One.start(object);
    }
    

    }
    public class Two{
    Object obj = new Object();
    public void start(Object obj){
    this.obj = obj;
    }
    }

    Java question java json

  • Swing
    J Joshua Waring

    I see no error but to call a implements Runnable I use the line,

    (new Thread(new accept(br))).start();

    if that helps

    Java help java sysadmin data-structures

  • Swing
    J Joshua Waring

    Hopefully you could help me with this one, I've found the problem (Thanks to the breakpoints) My main created a thread1 and then thread1 created thread 2, both of which contain a while(true) (Then just sit and wait for input and output) but when thread1 creates thread2 it doesn't go past the line which creates thread2 which Isn't what I thought would happen... I thought Thread1 would create thread2 then proceeds to the loop for user input.

    Java help java sysadmin data-structures

  • Swing
    J Joshua Waring

    Any special features and tricks to Eclipse Debugger, I've hit an error while fusing it to the client. the server gets the connection but all input is just added to the JTextArea without being sent to the server even though it's told to send. I'd prefer to fix this one so I don't have to spam these forums.

    Java help java sysadmin data-structures

  • Swing
    J Joshua Waring

    Meaning i should of put Stack incoming = new Stack();

    Java help java sysadmin data-structures

  • Swing
    J Joshua Waring

    the purpose of the stack was for when I implements it into my chat client I'll have something to send it by, without changing the code around too much. I personally don't see how it caused an error.

    Java help java sysadmin data-structures

  • Swing
    J Joshua Waring

    I have made the edit, yes I'm new, but learning fast, a lot faster than expected. though the edit has been made, there was no change to the error. What I don't understand is that the field isn't empty D:

    Java help java sysadmin data-structures

  • Swing
    J Joshua Waring

    First lets give some context, I've just created a client and server but they don't work without using console So I've decided to create a GUI on top they'll communicate though the Stack, but that's all for a later date, right now I get a error on the Even listener which says that the JTextField is empty upon .getText() even though it's not. I've looked though it, but since I'm quite new to the whole Swing field, it's a challenge for me to fix the problem. It really is a simple GUI.

    import java.awt.Button;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.Stack;

    import javax.swing.*;
    public class GUI extends JFrame implements ActionListener{
    Stack incoming = null;
    Stack outgoing = null;
    JTextField input;
    JTextArea output;
    Button button;
    public GUI(){

    	setTitle("Satire v1.0.1");
    	setSize(320,360);
    	setLocationRelativeTo(null);
    	setDefaultCloseOperation(EXIT\_ON\_CLOSE);
    	
    	JPanel panel = new JPanel();
    	panel.setLayout(null);
    	
    	output = new JTextArea();
    	output.setBounds(0, 0, 300, 300);
    	output.setEditable(false);
    	
    	input = new JTextField();
    	input.setBounds(0, 300, 260, 20);
    	
    	button = new Button("SEND");
    	button.setBounds(250, 300, 50, 20);
    	button.addActionListener(this);
    	
    	getContentPane().add(panel);
    	panel.add(button);
    	panel.add(input);
    	panel.add(output);
    }
    public void actionPerformed(ActionEvent e) { 
    	GUI gui = new GUI();
    	try{
    		String out = gui.input.getText();
    		gui.input.selectAll();
    		outgoing.add(out);
    	}catch(NullPointerException e3){}
    	gui.output.append(outgoing.pop());
    }
    
    public static void main(String\[\] args){
    	 SwingUtilities.invokeLater(new Runnable() {
    		 public void run(){
    			 GUI cGUI = new GUI();
    			 cGUI.setVisible(true);
    		 }
    	 });
    }
    

    }

    Java help java sysadmin data-structures

  • Chat Server Issue
    J Joshua Waring

    Parsing the Socket into the thread was my screw up, so It was replaced with parameters of the thread.

    Java help csharp java sysadmin lounge

  • Chat Server Issue
    J Joshua Waring

    I'm committed to learn it and since I'm self taught, I've decided to throw myself in and learn how it all works then learn in more depth.

    Java help csharp java sysadmin lounge

  • Chat Server Issue
    J Joshua Waring

    I really don't understand, this is currently beyond me at the moment.

    Java help csharp java sysadmin lounge

  • Chat Server Issue
    J Joshua Waring

    A null pointer is when it returns a Null, right? I don't see the problem because that part of the code is unchanged. so why return an error now

    Java help csharp java sysadmin lounge

  • Chat Server Issue
    J Joshua Waring

    OKAY so here comes the update, I've added it into threads but now a unknown error occurs. Thanks to a debugger I know where and when it occurs but I don't know why. I get a exceptionNullPointer at line 11 of Users.java br = new BufferedReader(new InputStreamReader(socket.getInputStream()));

    import java.net.*;
    import java.io.*;

    public class Room implements Runnable{
    public void run(){
    ServerSocket serversocket;
    Socket socket;
    Clients client = new Clients();
    try{
    // Created a socket in which clients can connect to.
    serversocket = new ServerSocket(7776);
    // Waits for a client to connect to the server //
    while(true){
    socket = serversocket.accept();
    System.out.println("Client connected" + socket);
    // Starts their thread
    client.newThread(socket);
    }
    }catch(IOException e){
    System.out.println(e);
    }
    }
    public static void main(String[] args){
    (new Thread(new Room())).start();
    }
    }

    import java.io.BufferedReader;
    import java.io.IOException;
    import java.net.Socket;

    public class Clients implements Runnable{
    Socket socket1;
    public void run(){
    Socket socket2 = socket1;
    Users userfunction = new Users();
    BufferedReader bf;
    bf = userfunction.addStream(socket2);
    while(true){
    // Receives a Message.
    try{
    String out = bf.readLine();
    System.out.println(out);
    if(out != null)
    userfunction.sendMessageALL(out);

    		}catch(IOException e){
    			System.out.println(e);
    		}
    		try{
    			Thread.sleep(10);
    		} catch (InterruptedException e) {}
    	}
    }
    public void newThread(Socket socket){
    	// Creates one thread for ever client, to parse the socket I sent it to socket1 which is then
    	// received in the thread which is taken to socket2..
    	socket1 = socket;
    	(new Thread(new Clients())).start();
    }
    

    }

    import java.net.*;
    import java.io.*;
    import java.util.ArrayList;

    public class Users {
    ArrayList recieveAL = new ArrayList();
    ArrayList sendAL = new ArrayList();
    // Creates the BufferedReader and PrintWriter then returns the Reader since the Writer it maintained in the class for the sendMessageAll method.
    public BufferedReader addStream(Socket socket){
    BufferedReader br;
    PrintWriter pw;
    try{
    br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
    pw = new PrintWriter(socket.getOutputStream(), true);
    recieveAL.add(br);
    sendAL.

    Java help csharp java sysadmin lounge

  • Chat Server Issue
    J Joshua Waring

    So a method of non-blocking would be, upon return of the .accept(), we create a thread with the socket of the new user. Another thread could be used to send the received message to all the users, which i would think makes sending the received messages to one thread to be sent, let's say though a stack, instead to all threads where we wouldn't know when to peek and/or pop so messages are sent to all without missing users. To summaries, one thread per user to receive messages and one thread for all users to distribute them.

    Java help csharp java sysadmin lounge

  • Chat Server Issue
    J Joshua Waring

    I previously posted this on another forum which didn't seem to have a response, probably due to a low amount of users. www.gamedev.net/topic/629181-java-chat-server-unknown-issue-beginner/ I've identified the problem as the loop getting stuck on the second run at the serversocket.accept() where the loop waits for a new client before dealing with other clients. I can't use serversocket.setTimeout() because then it will throw a exception which completely stops the server and if I place it in it's own try statement then the .accept will fallout of the scope and be pointless.

    Java help csharp java sysadmin lounge
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups