Posts

Showing posts from 2015

Why using Threads is better in Socket Programming

Image
Socket programming is a topic which has a wide area of knowledge to discuss,But I'm going to demonstrate only about the advantage of using Threads in the socket programming I'm going to use the Java as my programming language in this demonstration,To ease the work I'm going to run a Port scanning program with and with out using Threads.But keep in mind if you using a public place like a Computer Laboratory, port scanning may not be allowed.But if you guys use a private place and work through a localhost then things will be easy. A Thread and a process have some slight differences,if I go through quickly, a thread is a sub category of a process and which needs a low amount of resources to run and let the computer to create more easily because they are lightweight. Java Socket Scanning program which search available(open) ports in the server. public class MainPrograme {       private static String host;       public static void main(St...

adding font styles to JOP in Java SE using basic html

Image
This is Not Big Deal,Only need few simple HTML knowledge, Sit back & watch 1)Normal message dialog with default font and color. the Code: JOptionPane.showConfirmDialog(rootPane,  "Do You want to Exit from Invoice? ", "Message", JOptionPane.YES_NO_OPTION); You see,message consists of just plain text(Boring...) 2) Changing the Text properties as I wish * first take the Sentence to show into a String Variable String txt=  "Do You want to Exit from Invoice? "; *Put HTML tags String txt=  "<html>Do You want to Exit from Invoice? </html>"; *Change the Properties (I want the "Invoice" word to be bolt,underlined,colored and set the whole sentence's font size to 4) String txt=  "<html><font size=4>Do You want to Exit from <font color= A7239C><b><u>Invoice</u></b></font> ? </font></html>"; the final Code: JOptionPane....

How to Use KeyEventDispatcher() with Multiple JFrames Easily

Image
I have  to tell that this is the easiest trick I found so far to dealing with multiple JFrames with Keyboard inputs.(Eg:- Closing a JFrame using ESC button ) Scenario: closing the JFrame "Invoice" by pressing ESC and go to another JFrame "Main_menue". 1) First of all you have to import few things as follows import java.awt.KeyEventDispatcher; import java.awt.KeyboardFocusManager; import java.awt.event.KeyEvent;  2) Then Implement your JFrame class to KeyEventDispatcher(used class name is "Invoice") public class Invoice extends javax.swing.JFrame implements KeyEventDispatcher { 3) (Step  3 & 4 make sure to do in JFrame class u want to close)  Then you have to Override the method "public boolean dispatchKeyEvent(KeyEvent e) "  of   KeyEventDispatcher, as follows.         @Override         public boolean dispatchKeyEvent(KeyEvent e) {             ...