Search
Search titles only
By:
Search titles only
By:
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Forums
New posts
All threads
Latest threads
New posts
Trending threads
Trending
Search forums
What's new
New posts
New ads
New profile posts
Latest activity
Free Ads
Latest reviews
Search ads
Members
Current visitors
New profile posts
Search profile posts
Contact us
Latest ads
Bodim.lk out now !
Manoj Suranga Bandara
Updated:
Sunday at 3:05 AM
Power Lifting Lever Belt
SkullVamp
Updated:
Jun 13, 2026
Ad icon
port.lk Domain for sale
Lankan-Tech
Updated:
Jun 13, 2026
Colombo
Kaduwela - Two Storey House for Sale
dilrasan
Updated:
Jun 11, 2026
Ad icon
Wechat qr verification
Pawan2005
Updated:
Jun 11, 2026
Electronics
Vehicles
Property
Search
Reply to thread
Forums
General
Education
ElaKiri Programmer's Club
Get the App
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
<blockquote data-quote="tery123" data-source="post: 20809697" data-attributes="member: 343391"><p>[PHP]import java.io.*;</p><p>import java.net.*;</p><p>import java.awt.*;</p><p>import java.awt.event.ActionEvent;</p><p>import java.awt.event.ActionListener;</p><p></p><p>import javax.swing.*;</p><p>import javax.xml.ws.handler.MessageContext;</p><p></p><p>public class client extends JFrame {</p><p> </p><p> private JTextField userText;</p><p> private JTextArea chatWindow;</p><p> private ObjectOutput output;</p><p> private ObjectInputStream input;</p><p> private String message= "";</p><p> private String serverIp;</p><p> private Socket connection;</p><p> </p><p> //constructor</p><p> </p><p> public client(String host){</p><p> </p><p> super("CLINENT MOFO !!!!");</p><p> serverIp = host;</p><p> userText.setEditable(false);</p><p> userText.addActionListener(</p><p> </p><p> new ActionListener() {</p><p> </p><p> @Override</p><p> public void actionPerformed(ActionEvent event) {</p><p> // TODO Auto-generated method stub</p><p> </p><p> sendMessage(event.getActionCommand());</p><p> userText.setText("");</p><p> </p><p> }</p><p> }</p><p> </p><p> );</p><p> </p><p> add(userText,BorderLayout.NORTH);</p><p> chatWindow = new JTextArea();</p><p> add(new JScrollPane(chatWindow),BorderLayout.CENTER);</p><p> setSize(300,150);</p><p> setVisible(true);</p><p> }</p><p> </p><p> //connect to server</p><p> public void startRunning(){</p><p> </p><p> try{</p><p> connectToServer();</p><p> setupStreams();</p><p> whileChatting();</p><p> </p><p> }catch(EOFException eofException){</p><p> showMessage("\n Client terminated connection");</p><p> </p><p> }catch(IOException ioException){</p><p> ioException.printStackTrace();</p><p> </p><p> }finally{</p><p> closeCrap();</p><p> }</p><p> }</p><p> </p><p> // connect to server</p><p> private void connectToServer() throws IOException{</p><p> showMessage("Attempting connection.....\n");</p><p> </p><p> connection = new Socket(InetAddress.getByName(serverIp),6789);</p><p> showMessage("Connected to : " + connection.getInetAddress().getHostName());</p><p> }</p><p> </p><p> //setting up streams to recive massages</p><p> </p><p> private void setupStreams() throws IOException{</p><p> output= new ObjectOutputStream(connection.getOutputStream());</p><p> output.flush();</p><p> input = new ObjectInputStream(connection.getInputStream());</p><p> showMessage("\n dude your streams are now good to go");</p><p> }</p><p> </p><p> //while chatting method</p><p> </p><p> private void whileChatting() throws IOException{</p><p> ableToType(true);</p><p> </p><p> do{</p><p> try{</p><p> </p><p> message=(String) input.readObject();</p><p> showMessage("\n" + message);</p><p> </p><p> }catch(ClassNotFoundException classNotFoundException){</p><p> showMessage("\n i dont know that object type");</p><p> }</p><p> </p><p> }while(!message.equals("SERVER - END"));</p><p> </p><p> }</p><p> </p><p> //close crap to close everything</p><p> </p><p> private void closeCrap(){</p><p> showMessage("\n closing crap down...");</p><p> ableToType(false);</p><p> </p><p> try{</p><p> output.close();</p><p> input.close();</p><p> connection.close();</p><p> </p><p> }catch(IOException ioException){</p><p> ioException.printStackTrace();</p><p> }</p><p> }</p><p> </p><p> //send massages to server</p><p> </p><p> private void sendMessage(String message){</p><p> try{</p><p> output.writeObject("CLIENT - " + message);</p><p> output.flush();</p><p> showMessage("\n CLIENT - " + message);</p><p> </p><p> }catch(IOException ioException){</p><p> </p><p> chatWindow.append("\n something messed up with sending massages");</p><p> }</p><p> }</p><p> </p><p> //show message to show all massage to window</p><p> private void showMessage(final String m){</p><p> SwingUtilities.invokeLater(</p><p> new Runnable() {</p><p> </p><p> @Override</p><p> public void run() {</p><p> // TODO Auto-generated method stub</p><p> chatWindow.append(m);</p><p> }</p><p> }</p><p> </p><p> );</p><p> }</p><p> </p><p> // give user permission to type </p><p> </p><p> private void ableToType(final boolean tof){</p><p> SwingUtilities.invokeLater(</p><p> new Runnable() {</p><p> </p><p> @Override</p><p> public void run() {</p><p> // TODO Auto-generated method stub</p><p> userText.setEditable(tof);</p><p> }</p><p> }</p><p> </p><p> );</p><p> }</p><p> </p><p>}</p><p>[/PHP]</p><p>[PHP]import javax.swing.JFrame;</p><p></p><p></p><p>public class clientTest {</p><p></p><p> public static void main(String[] args) {</p><p> // TODO Auto-generated method stub</p><p> </p><p> client mychat;</p><p> mychat= new client("127.0.0.1");</p><p> mychat.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);</p><p> mychat.startRunning();</p><p> </p><p></p><p> }</p><p></p><p>}</p><p>[/PHP]</p><p></p><p>meke mehema exception ekak enawane bun...mokakda case eka???</p><p></p><p><span style="color: Red">Exception in thread "main" java.lang.NullPointerException</span></p><p><span style="color: Red"> at client.<init>(client.java:27)</span></p><p><span style="color: Red"> at clientTest.main(clientTest.java:10)</span></p><p><span style="color: Red"></span></p><p></p><p><img src="/styles/default/xenforo/smilies/default/dull.gif" class="smilie" loading="lazy" alt=":dull:" title="Dull :dull:" data-shortname=":dull:" /><img src="/styles/default/xenforo/smilies/default/dull.gif" class="smilie" loading="lazy" alt=":dull:" title="Dull :dull:" data-shortname=":dull:" /><img src="/styles/default/xenforo/smilies/default/dull.gif" class="smilie" loading="lazy" alt=":dull:" title="Dull :dull:" data-shortname=":dull:" /><img src="/styles/default/xenforo/smilies/default/dull.gif" class="smilie" loading="lazy" alt=":dull:" title="Dull :dull:" data-shortname=":dull:" /><img src="/styles/default/xenforo/smilies/default/dull.gif" class="smilie" loading="lazy" alt=":dull:" title="Dull :dull:" data-shortname=":dull:" /></p></blockquote><p></p>
[QUOTE="tery123, post: 20809697, member: 343391"] [PHP]import java.io.*; import java.net.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; import javax.xml.ws.handler.MessageContext; public class client extends JFrame { private JTextField userText; private JTextArea chatWindow; private ObjectOutput output; private ObjectInputStream input; private String message= ""; private String serverIp; private Socket connection; //constructor public client(String host){ super("CLINENT MOFO !!!!"); serverIp = host; userText.setEditable(false); userText.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent event) { // TODO Auto-generated method stub sendMessage(event.getActionCommand()); userText.setText(""); } } ); add(userText,BorderLayout.NORTH); chatWindow = new JTextArea(); add(new JScrollPane(chatWindow),BorderLayout.CENTER); setSize(300,150); setVisible(true); } //connect to server public void startRunning(){ try{ connectToServer(); setupStreams(); whileChatting(); }catch(EOFException eofException){ showMessage("\n Client terminated connection"); }catch(IOException ioException){ ioException.printStackTrace(); }finally{ closeCrap(); } } // connect to server private void connectToServer() throws IOException{ showMessage("Attempting connection.....\n"); connection = new Socket(InetAddress.getByName(serverIp),6789); showMessage("Connected to : " + connection.getInetAddress().getHostName()); } //setting up streams to recive massages private void setupStreams() throws IOException{ output= new ObjectOutputStream(connection.getOutputStream()); output.flush(); input = new ObjectInputStream(connection.getInputStream()); showMessage("\n dude your streams are now good to go"); } //while chatting method private void whileChatting() throws IOException{ ableToType(true); do{ try{ message=(String) input.readObject(); showMessage("\n" + message); }catch(ClassNotFoundException classNotFoundException){ showMessage("\n i dont know that object type"); } }while(!message.equals("SERVER - END")); } //close crap to close everything private void closeCrap(){ showMessage("\n closing crap down..."); ableToType(false); try{ output.close(); input.close(); connection.close(); }catch(IOException ioException){ ioException.printStackTrace(); } } //send massages to server private void sendMessage(String message){ try{ output.writeObject("CLIENT - " + message); output.flush(); showMessage("\n CLIENT - " + message); }catch(IOException ioException){ chatWindow.append("\n something messed up with sending massages"); } } //show message to show all massage to window private void showMessage(final String m){ SwingUtilities.invokeLater( new Runnable() { @Override public void run() { // TODO Auto-generated method stub chatWindow.append(m); } } ); } // give user permission to type private void ableToType(final boolean tof){ SwingUtilities.invokeLater( new Runnable() { @Override public void run() { // TODO Auto-generated method stub userText.setEditable(tof); } } ); } } [/PHP] [PHP]import javax.swing.JFrame; public class clientTest { public static void main(String[] args) { // TODO Auto-generated method stub client mychat; mychat= new client("127.0.0.1"); mychat.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); mychat.startRunning(); } } [/PHP] meke mehema exception ekak enawane bun...mokakda case eka??? [COLOR="Red"]Exception in thread "main" java.lang.NullPointerException at client.<init>(client.java:27) at clientTest.main(clientTest.java:10) [/COLOR] :dull::dull::dull::dull::dull: [/QUOTE]
Insert quotes…
Verification
Dawasata paya keeyak thibeda?
Post reply
Top
Bottom