Friday, 25 November 2016

How to control arduino connected Servo motor from an android app Over Bluetooth connection ?

You can get your connection and device assembling from another stuffs.Here I place My code which i developed. which may useful for You. 

For Any Query comment below ..

//Arduino code..


       
#include <Servo.h>
int pos=0;
int servoPin=9;
int servoDelay=25;
Servo myPointer;

char data = 0;                //Variable for storing received data
void setup() 
{
  Serial.begin(9600);         //Sets the data rate in bits per second (baud) for serial data transmission
  //pinMode(13, OUTPUT);        //Sets digital pin 13 as output pin
  myPointer.attach(servoPin);
}
void loop()
{
  if(Serial.available() > 0)  // Send data only when you receive data:
  {
    while(Serial.available()==0){}
    pos=Serial.parseInt();
    myPointer.write(pos);
  }
}

 

//code FOR android application

AndroidManifest.xml file
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="com.example.kiit1.audrinoblutooth">
    <uses-sdk        android:minSdkVersion="8"        android:targetSdkVersion="17" />
    <uses-permission android:name="android.permission.BLUETOOTH"/>
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>

    <application        android:allowBackup="true"        android:icon="@mipmap/ic_launcher"        android:label="@string/app_name"        android:supportsRtl="true"        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

activity_main.xml File
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:id="@+id/activity_main"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:paddingBottom="@dimen/activity_vertical_margin"    android:paddingLeft="@dimen/activity_horizontal_margin"    android:paddingRight="@dimen/activity_horizontal_margin"    android:paddingTop="@dimen/activity_vertical_margin"    tools:context="com.example.kiit1.audrinoblutooth.MainActivity">

    <EditText android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:inputType="number"
              android:ems="10"  
              android:layout_alignParentTop="true"  
              android:layout_centerHorizontal="true" 
              android:layout_marginTop="184dp"  
              android:id="@+id/editText" />

    <Button   android:text="Move"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"  
              android:layout_alignParentBottom="true"
              android:layout_alignStart="@+id/button"
              android:layout_marginBottom="82dp"
              android:id="@+id/button2" />

    <Button   android:text="Button" 
              android:layout_width="wrap_content" 
              android:layout_height="wrap_content"
              android:layout_marginTop="45dp" 
              android:id="@+id/button"
              android:layout_alignParentTop="true" 
              android:layout_centerHorizontal="true" />
</RelativeLayout>
for mainActivity 
package com.example.kiit1.audrinoblutooth;

import android.app.AlertDialog;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;
import android.os.ParcelUuid;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Set;

public class MainActivity extends AppCompatActivity {
    private OutputStream outputStream;
    private InputStream inStream;

    @Override    protected void onCreate(Bundle savedInstanceState) {
        int position=0;
        try {
            BluetoothAdapter blueAdapter = BluetoothAdapter.getDefaultAdapter();
            if (blueAdapter != null) {

                if (blueAdapter.isEnabled()) {
                    Set<BluetoothDevice> bondedDevices = blueAdapter.getBondedDevices();

                    if (bondedDevices.size() > 0) {
                        Object[] devices = (Object[]) bondedDevices.toArray();
                        Toast.makeText(getBaseContext(), devices.length+"", Toast.LENGTH_LONG).show();
                        BluetoothDevice device = (BluetoothDevice) devices[position];
                        ParcelUuid[] uuids = device.getUuids();
                        BluetoothSocket socket = device.createRfcommSocketToServiceRecord(uuids[0].getUuid());
                        socket.connect();
                        outputStream = socket.getOutputStream();
                        inStream = socket.getInputStream();
                    }

                    Log.e("error", "No appropriate paired devices.");
                } else {
                    Log.e("error", "Bluetooth is disabled.");
                }
            }
        }catch(Exception e){
            e.printStackTrace();
            Toast.makeText(getBaseContext(), "SETUP Failure", Toast.LENGTH_LONG).show();
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            //Creating dialog box            AlertDialog alert = builder.create();
            //Setting the title manually            alert.setTitle("Error");
            String sErr=e.toString();
            alert.setMessage(sErr);
            alert.show();

        }


        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button button2=(Button)findViewById(R.id.button2);
        final EditText editText=(EditText)findViewById(R.id.editText);
        button2.setOnClickListener(new View.OnClickListener() {
            @Override            public void onClick(View v) {
             String str= editText.getText().toString();
                try {
                    write(str);
                }catch(Exception e){
                    Toast.makeText(getBaseContext(), "Connection Failure", Toast.LENGTH_LONG).show();
                }
            }
        });
    }

    public void write(String s) throws IOException {
        outputStream.write(s.getBytes());
    }
}


OUT PUT




It rotate degree you Send form your app..

Wednesday, 23 November 2016

How to convert pptx file to Image and pdf in Java ?

       
//Here I Use APACHE POI and ITEXT JAVA API
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;

import org.apache.poi.xslf.usermodel.*;

import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.pdf.PdfWriter;

public class MakePPTtoPDF {
 public static void main(String args[]) throws IOException{
       
       //creating an empty presentation
       File file=new File("D:/Exam2016Kiit/HTTP Over WebSocket Proxy System.pptx");
       XMLSlideShow ppt = new XMLSlideShow(new FileInputStream(file));
       
       
       //getting the dimensions and size of the slide
       
       Dimension pgsize = ppt.getPageSize();
       List<XSLFSlide> slide = ppt.getSlides();
       BufferedImage img=null;
       Document doc=new Document();
         try {
    PdfWriter.getInstance(doc, new  FileOutputStream("C:/Users/kiit1/Desktop/aca/PPTImages.pdf"));
   
         doc.open();

       for (int i = 0; i < slide.size(); i++) {
          img = new BufferedImage(pgsize.width, pgsize.height,BufferedImage.TYPE_INT_RGB);
          Graphics2D graphics = img.createGraphics();

          //clear the drawing area
          graphics.setPaint(Color.white);
          graphics.fill(new Rectangle2D.Float(0, 0, pgsize.width, pgsize.height));

          //render
          slide.get(i).draw(graphics);
          FileOutputStream out = new FileOutputStream("C:/Users/kiit1/Desktop/aca/"+i+".png");
        javax.imageio.ImageIO.write(img, "png", out);
        ppt.write(out);
        com.itextpdf.text.Image image =com.itextpdf.text.Image.getInstance("C:/Users/kiit1/Desktop/aca/"+i+".png");
             doc.setPageSize(new com.itextpdf.text.Rectangle(image.getScaledWidth(), image.getScaledHeight()));
             doc.newPage();
             image.setAbsolutePosition(0, 0);
             doc.add(image);

        System.out.println("Image successfully created");
        out.close();
       }
       doc.close();
         } catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }
       
        
    }

 
}

 


OUTPUT

AND MY OUT PUT FILE IS HERE

Friday, 18 November 2016

Detect your face using opencv in java

     // first SetUp Your OpenCV lib with Eclips IDE
  
package opencvtest;

import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.MatOfRect;
import org.opencv.core.Point;
import org.opencv.core.Rect;
import org.opencv.core.Scalar;
import org.opencv.highgui.Highgui;
import org.opencv.objdetect.CascadeClassifier;

//
// Detects faces in an image, draws boxes around them, and writes the results
// to "faceDetection.png".
//
class DetectFaceDemo {
  public void run() {
    System.out.println("\nRunning DetectFaceDemo");

    // Create a face detector from the cascade file in the resources
    // directory.
   // CascadeClassifier faceDetector = new CascadeClassifier(getClass().getResource("lbpcascade_frontalface.xml").getPath());
   CascadeClassifier faceDetector = new CascadeClassifier("D:/javaTech/OpenCV/opencv/sources/data/lbpcascades/lbpcascade_frontalface.xml");
//    Mat image = Highgui.imread("C:/Users/kiit1/Desktop/IMG_2096.JPG");
    Mat image = Highgui.imread("C:/Users/kiit1/Desktop/b.JPG");

    // Detect faces in the image.
    // MatOfRect is a special container class for Rect.
    MatOfRect faceDetections = new MatOfRect();
    faceDetector.detectMultiScale(image, faceDetections);

    System.out.println(String.format("Detected %s faces", faceDetections.toArray().length));

    // Draw a bounding box around each face.
    for (Rect rect : faceDetections.toArray()) {
        Core.rectangle(image, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height), new Scalar(0, 255, 0));
    }

    // Save the visualized detection.
    String filename = "C:/Users/kiit1/Desktop/lenafaceDetection.png";
    System.out.println(String.format("Writing %s", filename));
    Highgui.imwrite(filename, image);
  }
}

//Main.java (Execute this)
package opencvtest;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferByte;

import java.io.File;
import javax.imageio.ImageIO;

import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.imgproc.Imgproc;

public class Main {
   public static void main( String[] args ) { 
   
      try {
         System.loadLibrary( Core.NATIVE_LIBRARY_NAME );
         File input = new File("C:/Users/kiit1/Desktop/lena.png");
         BufferedImage image = ImageIO.read(input); 

         byte[] data = ((DataBufferByte) image.getRaster().getDataBuffer()).getData();
         Mat mat = new Mat(image.getHeight(), image.getWidth(), CvType.CV_8UC3);
         mat.put(0, 0, data);

         Mat mat1 = new Mat(image.getHeight(),image.getWidth(),CvType.CV_8UC1);
         Imgproc.cvtColor(mat, mat1, Imgproc.COLOR_RGB2GRAY);

         byte[] data1 = new byte[mat1.rows() * mat1.cols() * (int)(mat1.elemSize())];
         mat1.get(0, 0, data1);
         BufferedImage image1 = new BufferedImage(mat1.cols(),mat1.rows(), BufferedImage.TYPE_BYTE_GRAY);
         image1.getRaster().setDataElements(0, 0, mat1.cols(), mat1.rows(), data1);

         File ouptut = new File("C:/Users/kiit1/Desktop/grayscale.jpg");
         ImageIO.write(image1, "jpg", ouptut);
         
      } catch (Exception e) {
         System.out.println("Error: " + e.getMessage());
      }
   }
}
 

OutPut

Wednesday, 2 November 2016

Create a Hotsport in java(Useing OS primitives) !!!!

       
/*
 * Jyotiprakash
*/
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Hotsport {

 public static void main(String[] args) {        
     try {

         System.out.println("-- Setting up WLAN --");
         String netshCommand = "netsh wlan set hostednetwork mode=allow ssid=\"YourSSID\" key=\"YourPassword\" & exit";
         String[] elevateCommand = new String[]{"./Release/elevate.exe", "-wait", "-k", "prog", netshCommand};
         ProcessBuilder pb1 = new ProcessBuilder(elevateCommand);
         Process p1 = pb1.start();
         p1.waitFor();

         System.out.println("-- Starting WLAN --");
         netshCommand = "netsh wlan start hostednetwork & exit";
         elevateCommand = new String[]{"./Release/elevate.exe", "-wait", "-k", "prog", netshCommand};
         ProcessBuilder pb2 = new ProcessBuilder(elevateCommand);
         Process p2 = pb2.start();
         p2.waitFor();

         System.out.println("-- Setting up IPv4 interface --");
         netshCommand = "netsh interface ipv4 set address \"Conexión de red inalámbrica\" static 192.168.0.102 255.255.255.0 192.168.0.254 & exit";
         elevateCommand = new String[]{"./Release/elevate.exe", "-wait", "-k", "prog", netshCommand};
         ProcessBuilder pb3 = new ProcessBuilder(elevateCommand);
         Process p3 = pb3.start();
         p3.waitFor();

         System.out.println("-- Getting IPv4 interface dump --");
         netshCommand = "netsh interface ipv4 dump";
         ProcessBuilder pb4 = new ProcessBuilder("cmd.exe", "/c", netshCommand);
         Process p4 = pb4.start();

         System.out.println("-- Printing IPv4 interface dump --");
         BufferedReader bfr = new BufferedReader(new InputStreamReader(p4.getInputStream(),"ISO-8859-1"));
         String output;
         while((output = bfr.readLine()) != null){
             System.out.println(output);
         }

     } catch (Exception ex) {
         ex.printStackTrace();
     }

 }
}

 

IMAGE Stenography in java

 public class Image_Filter extends javax.swing.filechooser.FileFilter
{
 /*
  *Determines if the extension is of the defined types
  *@param ext Extension of a file
  *@return Returns true if the extension is 'jpg' or 'png'
  */
 protected boolean isImageFile(String ext)
 {
  return (ext.equals("jpg")||ext.equals("png"));
 }
 
 /*
  *Determines if the file is a directory or accepted extension
  *@param f The File to run the directory/proper extension check on
  *@return Returns true if the File is a directory or accepted extension
  */
 public boolean accept(File f)
 {
     if (f.isDirectory())
     {
   return true;
     }

     String extension = getExtension(f);
  if (extension.equals("jpg")||extension.equals("png"))
  {
   return true;
  }
  return false;
 }
 
 /*
  *Supplies File type description
  *@return Returns the String description
  */
 public String getDescription()
 {
  return "Supported Image Files";
 }
 
 /*
  *Determines the Extension
  *@param f File to return the extension of
  *@return Returns the String representing the extension
  */
 protected static String getExtension(File f)
 {
  String s = f.getName();
  int i = s.lastIndexOf('.');
  if (i > 0 &&  i < s.length() - 1) 
    return s.substring(i+1).toLowerCase();
  return "";
 } 
}
// Steganography_Controller.java     


import java.io.File;

import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.image.BufferedImage;
import java.awt.event.ActionListener;

import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.ImageIcon;
import javax.swing.JMenuItem;
import javax.swing.JTextArea;
import javax.imageio.ImageIO;
import javax.swing.JOptionPane;
import javax.swing.JFileChooser;

/*
 *Steganography_Controller Class
 */
public class Steganography_Controller
{
 //Program Variables
 private Steganography_View view;
 private Steganography  model;
 
 //Panel Displays
 private JPanel  decode_panel;
 private JPanel  encode_panel;
 //Panel Variables
 private JTextArea  input;
 private JButton  encodeButton,decodeButton;
 private JLabel  image_input;
 //Menu Variables
 private JMenuItem  encode;
 private JMenuItem  decode;
 private JMenuItem  exit;
 
 //action event classes
 private Encode   enc;
 private Decode   dec;
 private EncodeButton encButton;
 private DecodeButton decButton;
 
 //decode variable
 private String   stat_path = "";
 private String   stat_name = "";
 
 /*
  *Constructor to initialize view, model and environment variables
  *@param aView  A GUI class, to be saved as view
  *@param aModel A model class, to be saved as model
  */
 public Steganography_Controller(Steganography_View aView, Steganography aModel)
 {
  //program variables
  view  = aView;
  model = aModel;
  
  //assign View Variables
  //2 views
  encode_panel = view.getTextPanel();
  decode_panel = view.getImagePanel();
  //2 data options
  input   = view.getText();
  image_input  = view.getImageInput();
  //2 buttons
  encodeButton = view.getEButton();
  decodeButton = view.getDButton();
  //menu
  encode   = view.getEncode();
  decode   = view.getDecode();
  exit   = view.getExit();
  
  //assign action events
  enc = new Encode();
  encode.addActionListener(enc);
  dec = new Decode();
  decode.addActionListener(dec);
  exit.addActionListener(new Exit());
  encButton = new EncodeButton();
  encodeButton.addActionListener(encButton);
  decButton = new DecodeButton();
  decodeButton.addActionListener(decButton);
  
  //encode view as default
  encode_view();
 }
 
 /*
  *Updates the single panel to display the Encode View.
  */
 private void encode_view()
 {
  update();
  view.setContentPane(encode_panel);
  view.setVisible(true);
 }
 
 /*
  *Updates the single panel to display the Decode View.
  */
 private void decode_view()
 {
  update();
  view.setContentPane(decode_panel);
  view.setVisible(true);
 }
 
 /*
  *Encode Class - handles the Encode menu item
  */
 private class Encode implements ActionListener
 {
  /*
   *handles the click event
   *@param e The ActionEvent Object
   */
  public void actionPerformed(ActionEvent e)
  {
   encode_view(); //show the encode view
  }
 }
 
 /*
  *Decode Class - handles the Decode menu item
  */
 private class Decode implements ActionListener
 {
  /*
   *handles the click event
   *@param e The ActionEvent Object
   */
  public void actionPerformed(ActionEvent e)
  {
   decode_view(); //show the decode view
   
   //start path of displayed File Chooser
   JFileChooser chooser = new JFileChooser("./");
   chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
   chooser.setFileFilter(new Image_Filter());
   int returnVal = chooser.showOpenDialog(view);
   if (returnVal == JFileChooser.APPROVE_OPTION){
    File directory = chooser.getSelectedFile();
    try{
     String image = directory.getPath();
     stat_name = directory.getName();
     stat_path = directory.getPath();
     stat_path = stat_path.substring(0,stat_path.length()-stat_name.length()-1);
     stat_name = stat_name.substring(0, stat_name.length()-4);
     image_input.setIcon(new ImageIcon(ImageIO.read(new File(image))));
    }
    catch(Exception except) {
    //msg if opening fails
    JOptionPane.showMessageDialog(view, "The File cannot be opened!", 
     "Error!", JOptionPane.INFORMATION_MESSAGE);
    }
   }
  }
 }
 
 /*
  *Exit Class - handles the Exit menu item
  */
 private class Exit implements ActionListener
 {
  /*
   *handles the click event
   *@param e The ActionEvent Object
   */
  public void actionPerformed(ActionEvent e)
  {
   System.exit(0); //exit the program
  }
 }
 
 /*
  *Encode Button Class - handles the Encode Button item
  */
 private class EncodeButton implements ActionListener
 {
  /*
   *handles the click event
   *@param e The ActionEvent Object
   */
  public void actionPerformed(ActionEvent e)
  {
   //start path of displayed File Chooser
   JFileChooser chooser = new JFileChooser("./");
   chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
   chooser.setFileFilter(new Image_Filter());
   int returnVal = chooser.showOpenDialog(view);
   if (returnVal == JFileChooser.APPROVE_OPTION){
    File directory = chooser.getSelectedFile();
    try{
     String text = input.getText();
     String ext  = Image_Filter.getExtension(directory);
     String name = directory.getName();
     String path = directory.getPath();
     path = path.substring(0,path.length()-name.length()-1);
     name = name.substring(0, name.length()-4);
     
     String stegan = JOptionPane.showInputDialog(view,
         "Enter output file name:", "File name",
         JOptionPane.PLAIN_MESSAGE);
     
     if(model.encode(path,name,ext,stegan,text))
     {
      JOptionPane.showMessageDialog(view, "The Image was encoded Successfully!", 
       "Success!", JOptionPane.INFORMATION_MESSAGE);
     }
     else
     {
      JOptionPane.showMessageDialog(view, "The Image could not be encoded!", 
       "Error!", JOptionPane.INFORMATION_MESSAGE);
     }
     //display the new image
     decode_view();
     image_input.setIcon(new ImageIcon(ImageIO.read(new File(path + "/" + stegan + ".png"))));
    }
    catch(Exception except) {
    //msg if opening fails
    JOptionPane.showMessageDialog(view, "The File cannot be opened!", 
     "Error!", JOptionPane.INFORMATION_MESSAGE);
    }
   }
  }
  
 }
 
 /*
  *Decode Button Class - handles the Decode Button item
  */
 private class DecodeButton implements ActionListener
 {
  /*
   *handles the click event
   *@param e The ActionEvent Object
   */
  public void actionPerformed(ActionEvent e)
  {
   String message = model.decode(stat_path, stat_name);
   System.out.println(stat_path + ", " + stat_name);
   if(message != "")
   {
    encode_view();
    JOptionPane.showMessageDialog(view, "The Image was decoded Successfully!", 
       "Success!", JOptionPane.INFORMATION_MESSAGE);
    input.setText(message);
   }
   else
   {
    JOptionPane.showMessageDialog(view, "The Image could not be decoded!", 
       "Error!", JOptionPane.INFORMATION_MESSAGE);
   }
  }
 }
 
 /*
  *Updates the variables to an initial state
  */
 public void update()
 {
  input.setText("");   //clear textarea
  image_input.setIcon(null); //clear image
  stat_path = "";    //clear path
  stat_name = "";    //clear name
 }
 
 /*
  *Main Method for testing
  */
 public static void main(String args[])
 {
  new Steganography_Controller(
         new Steganography_View("Steganography"),
         new Steganography()
         );
 }
}
//Steganography_View.java


import java.awt.Color;
import java.awt.Insets;
import java.awt.Container;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;

import javax.swing.JMenu;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JTextArea;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.BorderFactory;

/*
 *Class Steganography_View
 */
public class Steganography_View extends JFrame
{
 //sie variables for window
 private static int WIDTH  = 500;
 private static int HEIGHT = 400;
 
 //elements for JPanel
 private JTextArea  input;
 private JScrollBar  scroll,scroll2;
 private JButton  encodeButton,decodeButton;
 private JLabel  image_input;
 
 //elements for Menu
 private JMenu   file;
 private JMenuItem  encode;
 private JMenuItem  decode;
 private JMenuItem  exit;
 
 /*
  *Constructor for Steganography_View class
  *@param name Used to set the title on the JFrame
  */
 public Steganography_View(String name)
 {
  //set the title of the JFrame
  super(name);
  
  //Menubar
  JMenuBar menu = new JMenuBar();
  
  JMenu file = new JMenu("File"); file.setMnemonic('F');
  encode = new JMenuItem("Encode"); encode.setMnemonic('E'); file.add(encode);
  decode = new JMenuItem("Decode"); decode.setMnemonic('D'); file.add(decode);
  file.addSeparator();
  exit = new JMenuItem("Exit"); exit.setMnemonic('x'); file.add(exit);
  
  menu.add(file);
  setJMenuBar(menu);
  
  // display rules
  setResizable(true);      //allow window to be resized: true?false
  setBackground(Color.lightGray);   //background color of window: Color(int,int,int) or Color.name
  setLocation(100,100);     //location on the screen to display window
        setDefaultCloseOperation(EXIT_ON_CLOSE);//what to do on close operation: exit, do_nothing, etc
        setSize(WIDTH,HEIGHT);     //set the size of the window
        setVisible(true);      //show the window: true?false
 }
 
 /*
  *@return The menu item 'Encode'
  */
 public JMenuItem getEncode()  { return encode;   }
 /*
  *@return The menu item 'Decode'
  */
 public JMenuItem getDecode()  { return decode;   }
 /*
  *@return The menu item 'Exit'
  */
 public JMenuItem getExit()  { return exit;    }
 /*
  *@return The TextArea containing the text to encode
  */
 public JTextArea getText()  { return input;    }
 /*
  *@return The JLabel containing the image to decode text from
  */
 public JLabel  getImageInput() { return image_input;  }
 /*
  *@return The JPanel displaying the Encode View
  */
 public JPanel  getTextPanel() { return new Text_Panel(); }
 /*
  *@return The JPanel displaying the Decode View
  */
 public JPanel  getImagePanel() { return new Image_Panel(); }
 /*
  *@return The Encode button
  */
 public JButton  getEButton() { return encodeButton;  }
 /*
  *@return The Decode button
  */
 public JButton  getDButton() { return decodeButton;  }
 
 /*
  *Class Text_Panel
  */
 private class Text_Panel extends JPanel
 {
  /*
   *Constructor to enter text to be encoded
   */
  public Text_Panel()
  {
   //setup GridBagLayout
   GridBagLayout layout = new GridBagLayout(); 
   GridBagConstraints layoutConstraints = new GridBagConstraints(); 
   setLayout(layout);
   
   input = new JTextArea();
   layoutConstraints.gridx  = 0; layoutConstraints.gridy = 0; 
   layoutConstraints.gridwidth = 1; layoutConstraints.gridheight = 1; 
   layoutConstraints.fill   = GridBagConstraints.BOTH; 
   layoutConstraints.insets  = new Insets(0,0,0,0); 
   layoutConstraints.anchor  = GridBagConstraints.CENTER; 
   layoutConstraints.weightx  = 1.0; layoutConstraints.weighty = 50.0;
   JScrollPane scroll = new JScrollPane(input,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
   JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); 
   layout.setConstraints(scroll,layoutConstraints);
   scroll.setBorder(BorderFactory.createLineBorder(Color.BLACK,1));
      add(scroll);
      
      encodeButton = new JButton("Encode Now");
      layoutConstraints.gridx  = 0; layoutConstraints.gridy = 1; 
   layoutConstraints.gridwidth = 1; layoutConstraints.gridheight = 1; 
   layoutConstraints.fill   = GridBagConstraints.BOTH; 
   layoutConstraints.insets  = new Insets(0,-5,-5,-5); 
   layoutConstraints.anchor  = GridBagConstraints.CENTER; 
   layoutConstraints.weightx  = 1.0; layoutConstraints.weighty = 1.0;
   layout.setConstraints(encodeButton,layoutConstraints);
      add(encodeButton);
      
      //set basic display
   setBackground(Color.lightGray);
   setBorder(BorderFactory.createLineBorder(Color.BLACK,1));
  }
 }
 
 /*
  *Class Image_Panel
  */
 private class Image_Panel extends JPanel
 {
  /*
   *Constructor for displaying an image to be decoded
   */
  public Image_Panel()
  {
   //setup GridBagLayout
   GridBagLayout layout = new GridBagLayout(); 
   GridBagConstraints layoutConstraints = new GridBagConstraints(); 
   setLayout(layout);
   
   image_input = new JLabel();
   layoutConstraints.gridx  = 0; layoutConstraints.gridy = 0; 
   layoutConstraints.gridwidth = 1; layoutConstraints.gridheight = 1; 
   layoutConstraints.fill   = GridBagConstraints.BOTH; 
   layoutConstraints.insets  = new Insets(0,0,0,0); 
   layoutConstraints.anchor  = GridBagConstraints.CENTER; 
   layoutConstraints.weightx  = 1.0; layoutConstraints.weighty = 50.0;
   JScrollPane scroll2 = new JScrollPane(image_input,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
   JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); 
   layout.setConstraints(scroll2,layoutConstraints);
   scroll2.setBorder(BorderFactory.createLineBorder(Color.BLACK,1));
   image_input.setHorizontalAlignment(JLabel.CENTER);
      add(scroll2);
      
      decodeButton = new JButton("Decode Now");
      layoutConstraints.gridx  = 0; layoutConstraints.gridy = 1; 
   layoutConstraints.gridwidth = 1; layoutConstraints.gridheight = 1; 
   layoutConstraints.fill   = GridBagConstraints.BOTH; 
   layoutConstraints.insets  = new Insets(0,-5,-5,-5); 
   layoutConstraints.anchor  = GridBagConstraints.CENTER; 
   layoutConstraints.weightx  = 1.0; layoutConstraints.weighty = 1.0;
   layout.setConstraints(decodeButton,layoutConstraints);
      add(decodeButton);
      
      //set basic display
   setBackground(Color.lightGray);
   setBorder(BorderFactory.createLineBorder(Color.BLACK,1));
     }
  }
 
 /*
  *Main Method for testing
  */
 public static void main(String args[])
 {
  new Steganography_View("Steganography");
 }
}