• Post Reply Bookmark Topic Watch Topic
  • New Topic

Some begginers questions.  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey, everybody, im was learning Java by Head First Java book, and i decided to really make their Simple Chat in something worthwhile. I already done a lot of work(user lists, server logging, private messages), but im there is few thing i still dont know how to really implement and, of course my current program is far from beign decent, so i decided to start asking questions(so far i was just experimenting just using knowledge from book and some info found on Java API). There will be a lot of them, so please specify which one you're answering. So:

1. How can i make JTextField to scroll down each time new message recieved and log is already full? i mean visible part of it, so you don't need to scroll it yourself...

2. Why sequencer doesn't play MIDI if it is launched not by main thread?

3. What is good way to do user list with avatars? atm, i'm using regular JList and listening to selected values to open dialogs.

4. What is a good ways to implement sounds in application, other than MIDI? i know that i should just google it, but anyway.

You can check my source code for it by link. Chat client: http://pastebin.com/P923zJJt , Chat Server: http://pastebin.com/zfGiZLLq , User Class: http://pastebin.com/CBDHMKfU

I appreciate any tips on upgrading and optimizing.

P.S.: Sorry for my broken English, i'm Ukrainian.
 
Ranch Hand
Posts: 789
C++ Linux Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
4. midi is the last thing you should use for sound, unless the program is for the purpose of playing midi.
Generally play a wav file, which is just uncompressed recorded sound. Background music, rail gun blast, just make it a wav. Even if you have something in midi you like, record it and use it as a wav. Playing it can be trivial or complicated depending on the requirements. Mp3 can be used and is smaller. If it's for a browser make sure the browser supports it. Been awhile since I did this...
 
Marshal
Posts: 56600
172
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

As for scrolling, start here in the Java® Tutorials.
 
Ilya Puzanov
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Welcome to the Ranch

As for scrolling, start here in the Java® Tutorials.


I have read it, and there is mostly pictures viewport or lists/tables related stuff, can't find anything about scrolling TextArea...

And also, how many threads is ok to use for chat client/server? My server already have 3 threads and i still need more for login information checking at least.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ilya Puzanov wrote:

And also, how many threads is ok to use for chat client/server? My server already have 3 threads and i still need more for login information checking at least.


For client/server chat one user thread is required per client, so that while the server is waiting(blocked) for the incoming client requests the already connected clients can be serviced concurrently by the individual threads.

We can make use of Thread pool instead of creating a new thread for each new client, this saves time giving better performance as threads can be re-used.
 
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Siddhant Sood wrote:
For client/server chat one user thread is required per client, so that while the server is waiting(blocked) for the incoming client requests the already connected clients can be serviced concurrently by the individual threads.


Well, technically, this is not a "requirement". You can use the NIO library to have a single thread check/select from many channels simultaneously.

Henry
 
Siddhant Sood
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:

Well, technically, this is not a "requirement". You can use the NIO library to have a single thread check/select from many channels simultaneously.

Henry



I am new to Java and not much aware of NIO library.

Thanks for your inputs and correcting me
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!