Results 1 to 9 of 9
Like Tree1Likes
  • 1 Post By JosAH

Thread: Converting console into gui

  1. #1
    Join Date
    Dec 2011
    Posts
    4
    Rep Power
    0

    Default Converting console into gui

    Hey everybody out there i ve written a code for Image STEGANOGRAPHY its in console kindly help me in converting it to a GUI........... FIND THE CODEs BELOW

    TEXT ENCODING LOGIC:
    Java Code:
    import java.awt.Frame;
    import java.awt.Toolkit;
    import java.awt.Canvas;
    import java.awt.MediaTracker;
    import java.awt.Image;
    import java.awt.AWTEvent;
    import java.awt.event.WindowEvent;
    import java.awt.image.*;
    import java.awt.*;
    import javax.swing.*;
    import java.io.*;
    import javax.imageio.ImageIO;
    import java.awt.image.BufferedImage;
    import java.io.File;
    
    public class ImageApp extends Frame {
    
        
        public static void main(String[] args) throws IOException {
          
            new ImageApp();//a constructor to create an object
    
            
        }
        ImageApp() throws IOException
        {               
    	System.out.println("Enter the image name");
    	DataInputStream cin = new DataInputStream(System.in);
    	String imname;
    	imname=cin.readLine();//read image name
            Image image = Toolkit.getDefaultToolkit().getImage(imname);//create class image and get the object image
            MediaTracker mt = new MediaTracker(this);//this class is used to see the status of the image being transferred from disk to ram
            mt.addImage(image,1);//add the image to media tracker
            try {
                mt.waitForAll();//wait till the image is transferred
            } catch(Exception e) {
                System.err.println(e);
                System.exit(1);
            }
             BufferedImage buffImage =
          new BufferedImage(
              image.getWidth(this),
              image.getHeight(this),
              BufferedImage.TYPE_INT_ARGB);  // this class is used to have an image whose rgb values can be altered
            Graphics g = buffImage.getGraphics();//this and the next statement creates an image in the object buffImage 
            g.drawImage(image, 0, 0, null);
            int rg=0,ht=0,wd=0,txlen=1;
            int i=0,j=0,len=0;
            boolean flag=false;
            //Integer tx=new Integer;
            String stx;
    	System.out.println("Enter the data you need to encrypt\n");
            
            stx=cin.readLine();//get the data
    	
    	stx=stx+"~";//append a delimiter
    	
            int a=0 ;
            int b=0x80;//make MSB of the byte 1 and rest to 0
            int c;
            //char ch;
           // int count=0;
            a=stx.charAt(0);//a contains the first letter of the given data
            for(i=0;i<image.getWidth(null);i++)//loop to control each row
    	   {
    		for(j=0;j<image.getHeight(null);j++)//loop to control each coloumn
                        {
                           
                            rg= buffImage.getRGB(i,j);//get the rgb value at i,j
                            if(rg!=-1&&len<8)//if one compelete character has not been formed or the rgb vale is not negetive
    
                                    {
                                            
                            
                                   
                                    len++;//inmcrement the length
                                   
                                   
                                    c=a&b;//AND operation done on the letter and variable b to get MSB and result put in c
                                    c=c>>7;//right shift c 7 times to get the bit 
                                    a=a<<1;//left shift a 1 time to make the next bit as MSB
                                    if(c==0)//if the bit is 0
                                       {
                                             
                                            rg=rg&0xfffffffe;//make the last bit of RGB zero
                                            buffImage.setRGB(i,j,rg);//set the new RGB value
                                       }
                                    else //if the bit is 1
                                       {
                         
                                                    rg=rg|0x01;//make the RGB value 1
                                                    buffImage.setRGB(i,j,rg);//set the new RGB value
                                       }
                                    
                                    
    
                                     }
                                else if(len==8&&stx.length()!=1)//if one character is completely read or there is no data to encrypt
                                  {
                                             
                                             
                                    if(txlen==stx.length())//if whole data is encrypted
                                     {
    					flag=true;//set flag
    						break;
                                           
                                           
    					
                                     }
    				
    				a=stx.charAt(txlen);//get next character
                                             len=0;//reset len to 0
    				 txlen++;//incriment the txlen by 1
    				
    
                                  }
                       }//row
                       if(flag==true)//break if the process is complete
                            break;
    
            }//column
    
          System.out.println("encryption done\n\n\nEnter the file name where you want to save the image (no extensions)");
    
    	
    	imname=cin.readLine();//read the image name of the output file
    	imname=imname+".png";//append the extension
    	ImageIO.write( buffImage, "PNG" , new File( imname)  );//write image onto the disk
    	System.out.println("Your code is hidden in image "+imname);
            
            System.exit(0);//exit
        
        }
    }
     
    
    
    
    
    
    TEXT DECODING LOGIC:
    
    
    
    import java.awt.Frame;
    import java.awt.Toolkit;
    import java.awt.Canvas;
    import java.awt.MediaTracker;
    import java.awt.Image;
    import java.awt.AWTEvent;
    import java.awt.event.WindowEvent;
    import java.awt.image.*;
    import java.awt.*;
    import javax.swing.*;
    import java.io.*;
    import javax.imageio.ImageIO;
    import java.awt.image.BufferedImage;
    import java.io.File;
    public class Decode extends Frame {
    public static void main(String[] args) throws IOException
    {
    new Decode();
    }
    Decode () throws IOException
    {
    	System.out.println("Enter the image name (without extensions)");
    	DataInputStream cin = new DataInputStream(System.in);
    	String imname;
    	imname=cin.readLine();
    	imname=imname+".png";
            Image image = Toolkit.getDefaultToolkit().getImage(imname);
            MediaTracker mt = new MediaTracker(this);
            mt.addImage(image,1);
            try {
                mt.waitForAll();
            } catch(Exception e) {
                System.err.println(e);
                System.exit(1);
            }
             BufferedImage buffImage =
            new BufferedImage(
              image.getWidth(this),
              image.getHeight(this),
              BufferedImage.TYPE_INT_ARGB);  
            Graphics g = buffImage.getGraphics();
            g.drawImage(image, 0, 0, null);
    	int rg=0,ht=0,wd=0,txlen=0;
            int i=0,j=0,len=0,temp=0;
            boolean flag=false;
            //Integer tx=new Integer;
            String stx="\0";
            int a=0x00 ;
    	
            int b=0x80;
            int c;
            
            for(i=0;i<image.getWidth(null);i++)
    	{
    		for(j=0;j<image.getHeight(null);j++)
                        {
                           
                            rg= buffImage.getRGB(i,j);
                            if(rg!=-1&&len<8)
    
                                    {
    				
                                     temp=0x00;
    				 temp=rg&0x00000001;  
         				 temp=temp<<(7-len);
    				 
    				 a=temp|a;
    				 
                            	
    				 len++;
    
                                    }
                                else if(len==8)
                                  {
    				
    				if((char)a=='~')
                                     {
    					stx=stx+"\0";
                                            flag=true;
                                            break;
                                     }
    					 //System.out.println(stx);
    					
    					 stx=stx+(char)a;
                                             a=0x00;
                                             len=0;
                                              
                                    
    
                                  }
                       }
                       if(flag==true)
    		{
                            break;
    			
    			//stx.charAt(txlen)='\0';
    		}
    
            }
    	System.out.println("Your hidden text\n"+stx);
    
        }
    }








    thank yu in advance........
    Last edited by Norm; 12-16-2011 at 01:38 PM. Reason: added code tags

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,318
    Rep Power
    25

    Default Re: Converting console into gui

    First thing you need to do is design what you want the GUI to look like.
    Take a piece of paper and layout the components you want and their locations on the GUI.
    Have you read the Java Tutorial on Swing GUI?
    Trail: Creating a GUI With JFC/Swing (The Java™ Tutorials)

  3. #3
    Join Date
    Dec 2011
    Posts
    4
    Rep Power
    0

    Default Re: Converting console into gui

    well to be honest im new to java n i took a help of my senior in writing this prog. n the thing is that i need the gui version of this console to be done before monday.... :(
    Last edited by Norm; 12-17-2011 at 12:32 PM.

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,318
    Rep Power
    25

    Default Re: Converting console into gui

    If you want help, post your questions and describe your problems.

  5. #5
    Join Date
    Dec 2011
    Posts
    4
    Rep Power
    0

    Default Re: Converting console into gui

    well yu bet i do need help n very badly in need of it.. .
    Well i ll just tell yu d needs which the .jar app shud have.. .firstly it shud have 2 options 1.ENCODE 2.DECODE.. .
    next it shud chose an image file n ask the user to enter the data to be encrypted within the image.. .then after encryption is done, it shud save d new image in some place.. .
    Then in d decoding part it shud again ask for the image which is to be decrypted ie the image from which the hidden data needs to be decrypted.. .that's it .. .help of ny kind ll be appreciated.. .thank you :)

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,318
    Rep Power
    25

    Default Re: Converting console into gui

    Your last post looks like it was about how the internals of the app should work.
    What about the conversion to GUI? Do you have a design for how you want the GUI to look?
    Do you have any problems or questions about the code you are writing?

  7. #7
    Join Date
    Dec 2011
    Posts
    4
    Rep Power
    0

    Default Re: Converting console into gui

    well a simple gui would do no fancy designs as such.. .regarding the doubts related to the code .. .well actually i donno how to write a code for d interfacing, i'm just a beginner.. .i know it's too much asking for d code for gui but dat's d only option i'm left with :(

  8. #8
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,318
    Rep Power
    25

    Default Re: Converting console into gui

    i donno how to write a code for d interfacing, i'm just a beginner
    Here is a good place to start learning how to write GUIs:
    Trail: Creating a GUI With JFC/Swing (The Java™ Tutorials)

  9. #9
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,447
    Blog Entries
    7
    Rep Power
    20

    Default Re: Converting console into gui

    There is a fundamental difference between console input/output and gui applications; for the console your application 'pulls' its input, i.e. it actively waits for input to become available. Not so with a gui based application, i.e. the gui itself 'pushes' its input into your application, while your application was doing other things, possibly nothing. This is modeled by listeners, pieces of code in your application that are called when some input is available (text from a field or a button press or whatever). Converting from a console based application to a gui based application turns your entire application 'inside out'. It is just as easy to rebuild the entire application from scratch.

    kind regards,

    Jos
    Fubarable likes this.
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Help with Console
    By thiagohe in forum Advanced Java
    Replies: 7
    Last Post: 08-01-2011, 01:30 PM
  2. Move from console to GUI
    By MaxMonic in forum Advanced Java
    Replies: 2
    Last Post: 01-01-2011, 06:34 AM
  3. No errors but, nothing in console ..?
    By fresh83 in forum New To Java
    Replies: 2
    Last Post: 07-04-2010, 11:58 PM
  4. implementing a console
    By bilbodeb in forum Threads and Synchronization
    Replies: 2
    Last Post: 03-26-2009, 07:09 AM
  5. Console Progress Bar
    By new_2_java in forum New To Java
    Replies: 1
    Last Post: 02-16-2008, 02:18 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •