Simple text encyption - why BadPaddingException?

Hi
I'm trying out how to encrypt and descrypt a text. The key must be the same since I decrypt in another program. With the program below, I get this exception:
javax.crypto.BadPaddingException: Given final block not properly padded
     at com.sun.crypto.provider.DESedeCipher.engineDoFinal(DashoA6275)
     at com.sun.crypto.provider.DESedeCipher.engineDoFinal(DashoA6275)
     at javax.crypto.Cipher.doFinal(DashoA6275)
     at endecryptor.main(endecryptor.java:49)
What's the problem here?
import java.security.*;
import javax.crypto.*;
import java.io.*;
public class endecryptor {
public static void main(String[] args) throws Exception {
String text = "test eins";
System.out.println("Generating a DESede (TripleDES) key ... ");
//add the provider
Provider sunJce = new com.sun.crypto.provider.SunJCE();
Security.addProvider(sunJce);
//create a triple DES key
KeyGenerator keyGenerator = KeyGenerator.getInstance("DESede");
keyGenerator.init(168); //initialize with the keysize
Key key = keyGenerator.generateKey();
System.out.println("Key Algorithm :" + key.getAlgorithm());
System.out.println("Key Algorithm :" + key);
System.out.println("Done generating the key.");
//create a cipher using a key to initialize it
Cipher cipher = Cipher.getInstance("DESede/ECB/PKCS5Padding");//DES/ECB/PKCS5Padding
cipher.init(Cipher.ENCRYPT_MODE, key); ;
byte[] plaintext = text.getBytes("UTF8");
byte[] ciphertext = cipher.doFinal(plaintext);
System.out.println("Decrypting the string ...");
sunJce = new com.sun.crypto.provider.SunJCE();
Security.addProvider(sunJce);
//create a triple DES key
keyGenerator = KeyGenerator.getInstance("DESede");
keyGenerator.init(168); //initialize with the keysize
key = keyGenerator.generateKey();
System.out.println("Key Algorithm :" + key.getAlgorithm());
System.out.println("Key Algorithm :" + key);
System.out.println("Done generating the key.");
//create a cipher using a key to initialize it
cipher = Cipher.getInstance("DESede/ECB/PKCS5Padding");
cipher.init(Cipher.DECRYPT_MODE, key);
--> exception is thrown here -->byte[] decryptedText = cipher.doFinal(ciphertext);
String output = new String(decryptedText, "UTF8");
System.out.println("\n\nDecrypted Text:" + output);
}

Your problem is that you use one key to encrypt, and then create a completely different key to decrypt.
Ciphers are just functions that take in a bitstream, operate on it using a sequence of bytes we call a key, and spit out another bitstream. There's no way for the cipher to know that you're using the wrong key. It's often the case that a cipher will be perfectly happy decrypting with an incorrect key, handing you back utter gibberish.
Padding, however, is something that a cipher can recognize, and know when it isn't seeing what it expects at the end of the plaintext. So it is not uncommon, when using an incorrect key to decipher, to get a BadPaddingException, since the key-problem causes gibberish in the pad-bytes.
But the net is, you need to share one generated key - not generate two different ones.
Good luck,
Grant

Similar Messages

  • Simple Text Changes Won't Upload to Server?

    I have created a simple HTML e-mail signature in Photoshop, slicing and inputed all information in the "Slice Option" dialogue box, including the URL link for each social media platform button. I imported it into Dreamweaver, uploaded the files to my server and it works perfectly! Here is the issue I am having: I needed to make a simple link change to one of the buttons. I tried changing the link in Dreamweaver. Did not work! I tried changing the link in Photoshop, making the edit in the slice and re-saving the file and uploading to the server via Dreamweaver. Did not work. I eventually had to redo all the slices, renaming them something different; input to Dreamweaver under a different file name, do what i had to do, and then upload to my server. Everything worked perfect! Why? Why can't I just make a simple text change in Dreamweaver, uploaded it, and it works?! I feel like it is a cache issue, but i have no idea.
    Anybody have a solution?
    Frustrated Creative Cloud Subscriber
    Michael Salewych

    Open browser and hit Ctrl+R to refresh.  Or clear your browser's cache from the Tools menu.  In Firefox, Tools > Options > Advanced.
    Nancy O.

  • I get this message when trying to past simple text into an e-mail document. The Web-Based Email plugin has crashed. I have run out of options...please help.

    The Web-Based Email plugin has crashed. I get this message when trying to paste simple text into an email document. I have updated plugins and have run out of options. If I use another browser I have no problem. Please advise.

    UPDATE
    Compiling from command line I found out that the class definition for oracle.oats.scripting.modules.basic.api.IteratingVUserScript is missing. Do you know what .jar file contains this class?
    Thanks.
    Fede.

  • Since upgrading to iOS 6 I can no longer send pictures as attachments to text messages, why?

    I upgraded to iOS6 and can no longer attach photos to text messages, why would that be?  Also since upgrading I find that the Personal Hotspot on my iPhone 4s is now grayed out.  Is this something to to with the upgrade or what?  I am really frustrated by the glitches with this new iOS.  It is very un-Apple like.

    I recommend taking it into the store.  Sounds to me like you have downloaded an app that has allowed itself to become the "primary" when sending and recieving images....  Apple is seriously dropping the ball!!  Just the other day, I downloaded an app called v-downloader...  Its an app that allows you to download videos through a 3rd party browser.  Well what it did, was automatically place restrictions on my phone...  I couldnt send pics, and it removed access to safari, facetime, messages, etc... so maybe try removing any recent app purchases.  Also, I would reccomend that you restore your phone.  it will redo the update off your computer and come through with less glitches 
    But I agree, iOS6 has been nothing but problems... I plan on removing the update when I get home

  • Cannot print a simple Text File

    Hello All,
    I wrote the following program
    import java.io.*;
    import java.awt.print.*;
    import javax.print.*;
    import javax.print.attribute.*;
    import javax.print.attribute.standard.*;
    public class TestPrint
         public static void main(String[] args) throws Exception
              FileInputStream fis = new FileInputStream(new File("pds.txt"));
              byte[] fileByte = new byte[34];
              int read = 0;
              int counter = 0;
              while((read = fis.read()) != -1)
                   fileByte[counter++] = (byte)read;
              PrintService services[] = PrinterJob.lookupPrintServices();
              DocFlavor flavor = DocFlavor.INPUT_STREAM.TEXT_PLAIN_US_ASCII;
              PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
              aset.add(MediaSizeName.ISO_A4);
              aset.add(new Copies(1));
              Doc doc = new SimpleDoc(fileByte, flavor, null);
              DocPrintJob pj = services[0].createPrintJob();
              pj.print(doc, aset);
    }The file I am trying to print is a simple text file. My requirement is to convert it to an array of bytes and then print it.
    However I get the exception
    Exception in thread "main" java.lang.IllegalArgumentException: data is not of de
    clared type
    at javax.print.SimpleDoc.<init>(Unknown Source)
    at TestPrint.main(TestPrint.java:25)
    Please help me. I would appriciate any help in this matter.
    regards,
    Abhishek.
    PS: The contents of the file (pds.txt) which I am trying to print is
    PDS
    pds
    pds
    pds
    pds

    Hi,
    you get a java.lang.IllegalArgumentException in line 25:
    So we take the Java API for SimpleDoc:
    IllegalArgumentException - if flavor or printData is null, or the printData does not correspond to the specified doc flavor--for example, the data is not of the type specified as the representation in the DocFlavor.
    Since fileByte seems not the be null, the type must be wrong!
    In line 21 we see:
    DocFlavor flavor = DocFlavor.INPUT_STREAM.TEXT_PLAIN_US_ASCII;
    so fileByte must be type java.io.InputStream, which it isn�t. This causes your IllegalArgumentException.
    So try in line 21:
    DocFlavor flavor = DocFlavor.BYTE_ARRAY.TEXT_PLAIN_US_ASCII;
    Let me know if that was the reason!
    Best regards
    Martin

  • Efficient data structure to implement simple text editor?

    I was given this problem in an interview:
    What data structure would you use to implement a simple text editor that does these 4 functions:
    a) goto(line number)
    b) insert(char input,location)
    c) delete(location)
    d) printAll() //print entire file
    Given that i'm such a newb, i was stumped. I came up with making a 2d array that would allow for o(1) time for goto, but o(n) for everything else (shifting everything in the array). there were other downfalls too dealing with space issues and such, but he wanted me to optimize this data structure. I then came up with a linked list of arrays, but that had similar problems.
    But thinking about it further is driving me a little crazy so I'm wondering if you guys have any suggestions on how to answer this question...
    one thing that came to mind after is to implement the data structure as a binary tree, where each node contains
    class Node
    char theChar
    int position; // ie 0 = first character in the file, and 81 could be the first character in the 2nd line
    node left,right,parent;
    }so how it works is the cursor would know where the location was so i would know where to delete and insert within the tree.
    insert {
         //search for location to insert after (log n)
           //create new character node and append to current node
         //increment position for all subsequent children
    delete(x) {
         search for x position
         if found, remove node and decrement position value for all children
    goto(line #) {
         return line # * 80 (or whatever max length for a single line)
    }the major problem i see here is balancing the tree after every insert/delete
    Thanks in advance.

    One of many great things emacs has given us is the gap buffer:
    http://en.wikipedia.org/wiki/Gap_buffer
    To see a Java implementation of this you can look in the Java SDK source. The document model (I forget exactly what its called), used in Swing uses a gap buffer.

  • Sandy - a simple text editor

    sandy - a simple text editor
    Sandy is a X11 text editor with an easy-to-read, hackable C source. It uses GTK+ and GtkSourceView for convenience and is akin to surf, only it is a text editor, not a web browser. Sandy tries to maximize screen estate, minimize the SLOC used and not get in your way too much. It can somehow be controlled via XProperties and all preferences and keybindings are to be chosen at compile time. Two example configs are provided with the source.
    Features
    - Basic editing, saving, etc.
    - One document per instance
    - Embeddable (e.g. can use http://tools.suckless.org/tabbed for tabs)
    - Regex search, go to line functionalities
    - Pipe selection through arbitrary command
    - Pipe selection through predefined command(s)
    - Syntax highlighting
    - Line numbers, current line highlightnig
    - Simple autoindenting
    - Multi-level undo
    - Configurable at compile-time
    Dependencies
    - GtkSourceView2
    - Gtk+2
    - (probably) xorg-utils to get xprop to set XProperties
    - one method to grab user input: either zenity or dmenu in the pre-defined config files
    Screenshot
    http://sandyeditor.sf.net/sandy_editor.jpeg
    Homepage
    http://sandyeditor.sf.net/
    Download
    http://sourceforge.net/projects/sandyed … z/download
    AUR
    http://aur.archlinux.org/packages.php?ID=36084
    Comments, bug reports and patches welcome.
    Last edited by rafunchi (2010-04-13 23:24:26)

    Procyon wrote:
    It would be nice to be able to do something like this:
    1 abc
    2 dec
    3 abd
    4 edc
    5 {CURSOR}ad
    ^R, sed command: 1,3s/^/%%%/
    1 %%%abc
    2 %%%dec
    3 %%%abd
    4 edc
    5 {CURSOR}ad
    So you can edit and continue where you left off.
    The problem with implementing this behavior is 'sed' is an external command here. The full text is filtered through sed and put back in the buffer, not just lines 1 to 3. You can't just preserve the insert position as the text coming from the pipe might be completely different from your original. Same for searching the current line.
    You *could* remember your line+char position and move the cursor back there, but this would be highly unreliable and move the cursor to a third position in the buffer if your 's' command changes the number of lines (e.g. try s/:/\n/g in a password file)
    Also, a couple of tests with vim prove that it does not behave consistently in this regard, despite :s being an internal command there.
    if you really want to add '%%%' at the beginning of the line quite often, I suggest you define a binding or action for:
    t_editable, t_pipelines, { .v = (char *)"sed \'s/^/%%%/\'" }
    Then select the lines you want to target lousily (you don't need to select full lines) and launche the binding/action. It does move the cursor, but seems fairly quick.
    Procyon wrote:Maybe you can check for "/^s/" in the command to make it work on this current line, just like vim's :s///
    I made a wee change in the hg tip code. Now sandy "listens" to three properties regarding pipes:
    - _SANDY_PIPE: Pipes the selected text, or nothing by default as per f_pipe. This is used by the ^I binding in the default config.
    - _SANDY_PIPEALL: Pipes the selected text, or the full file if nothing is selected as per f_pipeall. This is used by the ^P binding in the default config.
    - _SANDY_PIPELINES: Pipes the selected text, extending the selection to full lines and matching the current line if there is no selection as per f_pipelines. This is used by the ^R binding in the default config. This means now sed is applied to full lines if there is a selection and to the current line if there is not.
    Thanks for your feedback. I hope this helps.

  • FM with code to send a simple text mail to external ID

    Hi All,
    I need a FM with code if possible to send a simple text mail to an external e-mail id or distribution list. I tried using the FM SO_NEW_DOCUMENT_ATT_SEND_API1 and was successfull in sending mail. But it requires attachment.
    I need help to send mail without attachment with code.
    All configurations done at my end.
    Thanks
    Anirban Bhattacharjee

    Hi Anirban,
    Please check this sample code.
    * Email ITAB structure
    DATA: BEGIN OF EMAIL_ITAB OCCURS 10.
            INCLUDE STRUCTURE SOLI.
    DATA: END OF EMAIL_ITAB.
    DATA: T_EMAIL LIKE SOOS1-RECEXTNAM.  "EMail distribution list
    CONSTANTS: C_EMAIL_DISTRIBUTION LIKE SOOS1-RECEXTNAM VALUE
               ‘[email protected],[email protected]’.
    * Initialization
    REFRESH EMAIL_ITAB.
    * Populate data
    EMAIL_ITAB-LINE = ‘Email body text 1’.
    APPEND EMAIL_ITAB.
    EMAIL_ITAB-LINE = ‘Email body text 2’.
    APPEND EMAIL_ITAB.
    T_EMAIL = C_EMAIL_DISTRIBUTION.
    * --- EMAIL FUNCTION ---------------------------------------------------
    * REQUIRMENTS:
    * 1) The user running the program needs a valid email address in their
    *    address portion of tx SU01 under external comms -> SMTP -> internet
    *    address.
    * 2) A job called SAP_EMAIL is running with the following parameters:
    *    Program: RSCONN01  Variant: INT   User: XXX
    *    This program moves mail from the outbox to the mail server using
    *    RFC destination: SAP_INTERNET_GATEWAY_SERVER
    * INTERFACE:
    * 1) APPLICATION: Anything
    * 2) EMAILTITLE:  EMail subject
    * 3) RECEXTNAM:   EMail distribution lists separated by commas
    * 4) TEXTTAB:     Internal table for lines of the email message
    * EXCEPTIONS:
    * Send OK = 0 otherwise there was a problem with the send.
        CALL FUNCTION 'Z_SEND_EMAIL_ITAB'
             EXPORTING
                  APPLICATION = 'EMAIL'
                  EMAILTITLE  = 'Email Subject'
                  RECEXTNAM   = T_EMAIL
             TABLES
                  TEXTTAB     = EMAIL_ITAB
             EXCEPTIONS
                  OTHERS      = 1.
    Function Z_SEND_EMAIL_ITAB
    *"*"Local interface:
    *"       IMPORTING
    *"             VALUE(APPLICATION) LIKE  SOOD1-OBJNAM
    *"             VALUE(EMAILTITLE) LIKE  SOOD1-OBJDES
    *"             VALUE(RECEXTNAM) LIKE  SOOS1-RECEXTNAM
    *"       TABLES
    *"              TEXTTAB STRUCTURE  SOLI
    *- local data declaration
      DATA: OHD    LIKE SOOD1,
            OID    LIKE SOODK,
            TO_ALL LIKE SONV-FLAG,
            OKEY   LIKE SWOTOBJID-OBJKEY.
      DATA: BEGIN OF RECEIVERS OCCURS 0.
              INCLUDE STRUCTURE SOOS1.
      DATA: END OF RECEIVERS.
    *- fill odh
      CLEAR OHD.
      OHD-OBJLA    = SY-LANGU.
      OHD-OBJNAM   = APPLICATION.
      OHD-OBJDES   = EMAILTITLE.
      OHD-OBJPRI   = 3.
      OHD-OBJSNS   = 'F'.
      OHD-OWNNAM   = SY-UNAME.
    *- send Email
      CONDENSE RECEXTNAM NO-GAPS.
      CHECK RECEXTNAM <> SPACE AND RECEXTNAM CS '@'.
    *- for every individual recipient send an Email
    * (see OSS message 0120050409/0000362105/1999)
      WHILE RECEXTNAM CS ','.
        PERFORM INIT_REC TABLES RECEIVERS.
        READ TABLE RECEIVERS INDEX 1.
        RECEIVERS-RECEXTNAM = RECEXTNAM+0(SY-FDPOS).
        ADD 1 TO SY-FDPOS.
        SHIFT RECEXTNAM LEFT BY SY-FDPOS PLACES.
        MODIFY RECEIVERS INDEX 1.
        PERFORM SO_OBJECT_SEND_REC
         TABLES TEXTTAB RECEIVERS
          USING OHD.
      ENDWHILE.
    *- check last recipient in recipient list
      IF RECEXTNAM <> SPACE.
        PERFORM INIT_REC TABLES RECEIVERS.
        READ TABLE RECEIVERS INDEX 1.
        RECEIVERS-RECEXTNAM = RECEXTNAM.
        MODIFY RECEIVERS INDEX 1.
        PERFORM SO_OBJECT_SEND_REC
         TABLES TEXTTAB RECEIVERS
          USING OHD.
      ENDIF.
    ENDFUNCTION.
    *       FORM SO_OBJECT_SEND_REC                                       *
    FORM  SO_OBJECT_SEND_REC
    TABLES  OBJCONT      STRUCTURE SOLI
            RECEIVERS    STRUCTURE SOOS1
    USING   OBJECT_HD    STRUCTURE SOOD1.
      DATA:   OID     LIKE SOODK,
              TO_ALL  LIKE SONV-FLAG,
              OKEY    LIKE SWOTOBJID-OBJKEY.
      CALL FUNCTION 'SO_OBJECT_SEND'
           EXPORTING
                EXTERN_ADDRESS             = 'X'
                OBJECT_HD_CHANGE           = OBJECT_HD
                OBJECT_TYPE                = 'RAW'
                OUTBOX_FLAG                = 'X'
                SENDER                     = SY-UNAME
           IMPORTING
                OBJECT_ID_NEW              = OID
                SENT_TO_ALL                = TO_ALL
                OFFICE_OBJECT_KEY          = OKEY
           TABLES
                OBJCONT                    = OBJCONT
                RECEIVERS                  = RECEIVERS
           EXCEPTIONS
                ACTIVE_USER_NOT_EXIST      = 1
                COMMUNICATION_FAILURE      = 2
                COMPONENT_NOT_AVAILABLE    = 3
                FOLDER_NOT_EXIST           = 4
                FOLDER_NO_AUTHORIZATION    = 5
                FORWARDER_NOT_EXIST        = 6
                NOTE_NOT_EXIST             = 7
                OBJECT_NOT_EXIST           = 8
                OBJECT_NOT_SENT            = 9
                OBJECT_NO_AUTHORIZATION    = 10
                OBJECT_TYPE_NOT_EXIST      = 11
                OPERATION_NO_AUTHORIZATION = 12
                OWNER_NOT_EXIST            = 13
                PARAMETER_ERROR            = 14
                SUBSTITUTE_NOT_ACTIVE      = 15
                SUBSTITUTE_NOT_DEFINED     = 16
                SYSTEM_FAILURE             = 17
                TOO_MUCH_RECEIVERS         = 18
                USER_NOT_EXIST             = 19
                X_ERROR                    = 20
                OTHERS                     = 21.
      IF SY-SUBRC <> 0.
        RAISE OTHERS.
      ENDIF.
    ENDFORM.
    *       FORM INIT_REC                                                 *
    FORM INIT_REC TABLES RECEIVERS STRUCTURE SOOS1.
      CLEAR RECEIVERS.
      REFRESH RECEIVERS.
      MOVE SY-DATUM  TO RECEIVERS-RCDAT .
      MOVE SY-UZEIT  TO RECEIVERS-RCTIM.
      MOVE '1'       TO RECEIVERS-SNDPRI.
      MOVE 'X'       TO RECEIVERS-SNDEX.
      MOVE 'U-'      TO RECEIVERS-RECNAM.
      MOVE 'U'       TO RECEIVERS-RECESC.
      MOVE 'INT'     TO RECEIVERS-SNDART.
      MOVE '5'       TO RECEIVERS-SORTCLASS.
      APPEND RECEIVERS.
    ENDFORM.
    Hope this will help.
    Regards,
    Ferry Lianto

  • The Find function (Ctrl+F), mis-finds the desired simple text in Acrobat Standard, but works fine in Reader

    Adobe Acrobat X 10.1.13, Win 7 64bit, 
    The Find function (Ctrl+F), mis-finds the desired simple text. 
    This is not a scanned document.  When I search for some word that DOES exist in the document, Acrobat will highlight text that does not match at all and which does NOT contain the word.  If I select the actual word, copy and past the text, I get the selected text accurately, but when I paste the same selected text into the Find box to search for it, Acrobat still mis-finds. 
    HOWEVER, I can open the very same .PDF file in Acrobat Reader X and do not have the same problem - Find works correctly in Reader with the same .PDF. 
    What is going on?!  Both Acrobat standard, and Reader report that they are up to date.   Please help.

    Can you try rasterizing (converting the document to tiff/bmp) and then importing those image files (tiff/bmp) back in Acrobat.
    This would allow document to be re-OCRed and you will be able to search text in it. You can use lossless export/import settings to preserve the quality of ducment.
    For exporting the file:
    1: Go to File > Save As Other > Image > Tiff.
    2: Click on Settings button in the Save As Dialog and set the file settings as ZIP for Monochrome, Grayscale and Color.
    Now for importing the files back:
    1: Press Ctrl + K
    2: In the Preferences dialog, select Convert To PDF option in Categories.
    3: Choose tiff or bmp (as per the format used while exporting) and un-check Scan Optimization and OCR.
    4: Set Color and Grayscale to Zip and Monochrome to CCITT G4.
    5: Save the settings.
    6: Now import all the pages in Acrobat.
    7: You can use Combine Files feature to merge all the image files.

  • Save a numbers spreadsheet as a simple text document?

    How do you save a numbers spreadsheet as a simple text document? I can't seem to find this option anywhere. Simply renaming the extension also seems to maintain rich text.

    An extension name is just a reminder helping us and the operating system to recognize which kind is the contents of a given file.
    Changing a trousers against a dress will not change Mr. Obama in Mrs. Clinton;-)
    Same thing for the files.
    At this time, Numbers doesn't offer the ability to export as a text file.
    Happily, our machines are delivered with TextEdit.
    Copy the block of cells of your choice to the clipboard
    Paste in an empty TextEdit document
    Format > Convert as text
    Save
    That's all folks.
    Of course, you may
    _Go to "Provide Numbers Feedback" in the "Numbers" menu_, describe what you wish.
    Then, cross your fingers, and wait _at least_ for iWork'09
    Yvan KOENIG (from FRANCE mardi 5 août 2008 18:07:34)

  • How can I add highlighting to my simple text editor?

    Hi ...I wrote a simple text editor ..but I want to add Sysntax highlihting to my editor ...ilke I will enter some words in sourse code (new..import.. ext ) and when I write in text those words I want to see whit a different collor ..how can I do this? here is source codes for my text editor..and I want your help
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.text.*;
    import javax.swing.plaf.ComponentUI;
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.io.File;
    import java.io.FileReader;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.util.*;
    import java.util.regex.*;
    public class JText extends JFrame{
         private JTextArea textarea ;
         private JFileChooser fileChooser = new JFileChooser();
    private Action open =new OpenAction() ;
    private Action save = new SaveAction();
    private Action exit = new ExitAction();
    public static void main(String args[])
              JText pencere= new JText();
              pencere.setBackground(Color.lightGray);
              pencere.setSize(400,300);
              pencere.setVisible(true);
         //Text Area
         public JText(){
         textarea = new JTextArea(15,90) ;
         JScrollPane scroll = new JScrollPane(textarea);
         JPanel content = new JPanel();
    content.setLayout(new BorderLayout());
    content.add(scroll, BorderLayout.CENTER);
         //Menu Bar
    JMenuBar menu=new JMenuBar();
    JMenu file=menu.add(new JMenu("FILE"));
    file.setMnemonic('F');
    file.add(open);
    file.add(save);
    file.addSeparator();
    file.add(exit);
    setContentPane(content);
    setJMenuBar(menu);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setTitle("Project");
    pack();
    setLocationRelativeTo(null);
    setVisible(true);
         class OpenAction extends AbstractAction {
         //============================================= constructor
         public OpenAction() {
         super("Open...");
         putValue(MNEMONIC_KEY, new Integer('O'));
         //========================================= actionPerformed
         public void actionPerformed(ActionEvent e) {
         int retval = fileChooser.showOpenDialog(JText.this);
         if (retval == JFileChooser.APPROVE_OPTION) {
         File f = fileChooser.getSelectedFile();
         try {
         FileReader reader = new FileReader(f);
         textarea.read(reader, ""); // Use TextComponent read
         } catch (IOException ioex) {
         System.out.println(e);
         System.exit(1);
              class SaveAction extends AbstractAction {
              //============================================= constructor
              SaveAction() {
              super("Save...");
              putValue(MNEMONIC_KEY, new Integer('S'));
              //========================================= actionPerformed
              public void actionPerformed(ActionEvent e) {
              int retval = fileChooser.showSaveDialog(JText.this);
              if (retval == JFileChooser.APPROVE_OPTION) {
              File f = fileChooser.getSelectedFile();
              try {
              FileWriter writer = new FileWriter(f);
              textarea.write(writer); // Use TextComponent write
              } catch (IOException ioex) {
              JOptionPane.showMessageDialog(JText.this, ioex);
              System.exit(1);
                   class ExitAction extends AbstractAction {
                   //============================================= constructor
                   public ExitAction() {
                   super("Exit");
                   putValue(MNEMONIC_KEY, new Integer('X'));
                   //========================================= actionPerformed
                   public void actionPerformed(ActionEvent e) {
                   System.exit(0);
    }

    i looked it ...it is the one which i want to do ..But i want to use my window which i gave above ..But i cant mix them ..:( this codes for highlighting.... is any body can add this codes and my codes which i gave above connect together? pleaseeeee... :))
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.text.*;
    import java.util.*;
    import java.awt.*;
    import java.awt.event.*;
    public class SyntaxTest extends DefaultStyledDocument
    Element rootElement;
    String wordSeparators = ",:;.()[]{}+-/*%=!&|~^@? ";
    Vector keywords = new Vector();;
    SimpleAttributeSet keyword;
    public SyntaxTest()
    rootElement= this.getDefaultRootElement();
    keyword = new SimpleAttributeSet();
    StyleConstants.setForeground(keyword, Color.blue);
    keywords.add( "abstract" );
    keywords.add( "boolean" );
    keywords.add( "break" );
    keywords.add( "byte" );
    keywords.add( "case" );
    keywords.add( "catch" );
    keywords.add( "char" );
    keywords.add( "class" );
    keywords.add( "continue" );
    keywords.add( "default" );
    keywords.add( "do" );
    keywords.add( "double" );
    keywords.add( "else" );
    keywords.add( "extends" );
    keywords.add( "false" );
    keywords.add( "final" );
    keywords.add( "finally" );
    keywords.add( "float" );
    keywords.add( "for" );
    keywords.add( "if" );
    keywords.add( "implements" );
    keywords.add( "import" );
    keywords.add( "instanceof" );
    keywords.add( "int" );
    keywords.add( "interface" );
    keywords.add( "long" );
    keywords.add( "native" );
    keywords.add( "new" );
    keywords.add( "null" );
    keywords.add( "package" );
    keywords.add( "private" );
    keywords.add( "protected" );
    keywords.add( "public" );
    keywords.add( "return" );
    keywords.add( "short" );
    keywords.add( "static" );
    keywords.add( "super" );
    keywords.add( "switch" );
    keywords.add( "synchronized" );
    keywords.add( "this" );
    keywords.add( "throw" );
    keywords.add( "throws" );
    keywords.add( "true" );
    keywords.add( "try" );
    keywords.add( "void" );
    keywords.add( "volatile" );
    keywords.add( "while" );
    public void insertString(int offset, String str, AttributeSet a) throws BadLocationException
    super.insertString(offset, str, a);
    int startOfLine = rootElement.getElement(rootElement.getElementIndex(offset)).getStartOffset();
    int endOfLine = rootElement.getElement(rootElement.getElementIndex(offset+str.length())).getEndOffset() -1;
    //highlight the changed line
    highlightKeyword(this.getText(0,this.getLength()), startOfLine, endOfLine);
    public void remove(int offset, int length) throws BadLocationException
    super.remove(offset, length);
    int startOfLine = rootElement.getElement(rootElement.getElementIndex(offset)).getStartOffset();
    int endOfLine = rootElement.getElement(rootElement.getElementIndex(offset+length)).getEndOffset() -1;
    //highlight the changed line
    highlightKeyword(this.getText(0,this.getLength()), startOfLine, endOfLine);
    public void highlightKeyword(String content,int startOffset, int endOffset)
    char character;
    int tokenEnd;
    while (startOffset < endOffset)
    tokenEnd = startOffset;
    //find next wordSeparator
    while(tokenEnd < endOffset)
    character = content.charAt(tokenEnd);
    if(wordSeparators.indexOf(character) > -1)
    break;
    else
    tokenEnd++;
    //check for keyword
    String token = content.substring(startOffset,tokenEnd).trim();
    if(keywords.contains(token))
    this.setCharacterAttributes(startOffset, token.length(), keyword, true);
    startOffset = tokenEnd+1;
    public static void main(String[] args)
    JFrame f = new JFrame();
    JTextPane pane = new JTextPane(new SyntaxTest());
    JScrollPane scrollPane = new JScrollPane(pane);
    f.setContentPane(scrollPane);
    f.setSize(600,400);
    f.setVisible(true);
    }

  • I want to publish a simple text animation transparent but keep getting a black background?

    I want to publish a simple text animation transparent but keep getting a black background?

    trouble is, it's not always that straight forward if the initial animation has not been set to a transparent background, as you cant simply change/update the poster.png
    What I mean is, if the poster has been saved as non transparent once, the only wayto update it,  is to physically open the file and make it transparent, even then it doesnt always work especially working with OAM's
    hope that also helps
    Alistair

  • How to sending simple text in the mail body

    Hi friends,
                 How to send simple text in the mail body through ABAP code
       plz send me the related code and setting for that mail.
      Thanks&Regards,
      Srinivas

    try this...
    FORM send_file_as_email_attachment .
      DATA: objtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE.
      DATA: objpack LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE.
      DATA: objhead LIKE solisti1 OCCURS 1 WITH HEADER LINE.
      DATA: reclist LIKE somlreci1 OCCURS 5 WITH HEADER LINE.
      DATA: objbin LIKE solisti1 OCCURS 10 WITH HEADER LINE.
      DATA : i_body TYPE soli_tab WITH HEADER LINE.
    DATA: it_attach LIKE it_display1 OCCURS 0 WITH HEADER LINE.
      DATA: doc_chng LIKE sodocchgi1.
      DATA: tab_lines LIKE sy-tabix.
      DATA: att_lines TYPE i.
    DATA: lv_lines TYPE i.
      DATA: file TYPE string.
      data: g_datum like sy-datum.
      data: g_datum1(10) type c.
      DATA: len TYPE n.
      LOOP AT it_email.
        CLEAR : objpack,
                objhead,
                objbin,
                objtxt,
                reclist.
        REFRESH: objpack,
                 objhead,
                 objbin,
                 objtxt,
                 reclist.
        g_datum =     sy-datum - 1.
        concatenate g_datum6(2) '.' g_datum4(2) '.' g_datum+0(4) into
        g_datum1.
    doc_chng-obj_descr = 'Aged Stock more than 45 Days'.
        CONCATENATE 'Aged Stock more than 45 Days' '-' it_email-vkbur INTO
        doc_chng-obj_descr.
        CONCATENATE 'Please find enclosed Aged Stock Details ( >45days ) report as on'
        g_datum1
        INTO objtxt-line SEPARATED BY space.
        APPEND objtxt.
        objtxt-line = ' '.
        APPEND objtxt.
        objtxt-line = 'Regards'.
        APPEND objtxt.
        objtxt-line = 'LIS SAP Projects'.
        APPEND objtxt.
        objtxt-line =
        'PS: Pls send feedback for futher improvements to SAP office.'.
        APPEND objtxt.
        DESCRIBE TABLE objtxt LINES tab_lines.
        READ TABLE objtxt INDEX tab_lines.
        doc_chng-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objtxt ).
       CLEAR objpack-transf_bin.
        objpack-head_start = 1.
        objpack-head_num = 1.
        objpack-body_start = 1.
        objpack-body_num = tab_lines.
        objpack-doc_type = 'TXT'.
       objpack-obj_name = 'Run_prog'.
       objpack-obj_descr = 'Agestock.txt'.
       lv_lines = tab_lines.
        APPEND objpack.
    *CONCATENATE 'Plant'   'Material Number' 'Qty(More than 45days)'
    *'Amount' INTO
           it_display SEPARATED BY space.
           append objbin.
           clear: objbin.
        CLEAR:it_display2.
        REFRESH it_display2.
        it_display2-werks = 'Plant|'.
        it_display2-matnr = 'Material Number'.
        it_display2-qty = '|Qty > 45 days'.
        it_display2-amount = '      |Amount'.
        APPEND it_display2.
        it_display2-werks = ''.
        it_display2-matnr = ''.
        it_display2-qty = ''.
        it_display2-amount = ''.
        APPEND it_display2.
        CLEAR : it_display2.
        sort it_display1 by amount descending.
        LOOP AT it_display1 WHERE werks = it_email-vkbur.
         AT FIRST.
    *CONCATENATE 'Plant    '   'Material Number' 'Qty(More than 45days)'
    *'Amount' INTO
           objbin-line SEPARATED BY space.
           append objbin.
           clear: objbin.
         ENDAT.
          CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
            EXPORTING
              input  = it_display1-matnr
            IMPORTING
              output = it_display1-matnr.
          it_display1-qty = TRUNC( it_display1-qty ).
          MOVE-CORRESPONDING it_display1 TO it_display2.
          APPEND it_display2.
          CLEAR:it_display1,it_display2,objbin.
          CLEAR:it_display1.
        ENDLOOP.
        objbin[] = it_display2[].
        DESCRIBE TABLE objbin LINES tab_lines.
        objhead = 'Suug'.
        APPEND objhead.
        objpack-transf_bin = 'X'.
        objpack-head_start = 3.
        objpack-head_num = 1.
        objpack-body_start = 1.
        objpack-body_num = tab_lines.
        objpack-doc_type = 'RAW'.
        objpack-obj_name = 'Run_prog'.
        objpack-obj_descr = 'Agestock.txt'.
        APPEND objpack.
        reclist-receiver = '[email protected]'.
        reclist-rec_type = 'U'.
        APPEND reclist.
    =====================================================================
        CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
          EXPORTING
            document_data              = doc_chng
            commit_work                = 'X'
          TABLES
            packing_list               = objpack
            object_header              = objhead
            contents_bin               = objbin
            contents_txt               = objtxt
            receivers                  = reclist
          EXCEPTIONS
            too_many_receivers         = 1
            document_not_sent          = 2
            operation_no_authorization = 4
            OTHERS                     = 99.
        CLEAR : it_email.
      ENDLOOP.
    ENDFORM.                    "send_mail
    Message was edited by:
            Sugumar Ganesan

  • (Enter the text shown) why this showing in firefox persona sign in, there is no text???

    Enter the text shown why this showing in Firefox persona sign in

    That is a CAPTCHA from https://api-secure.recaptcha.net
    Make sure that you do not block that image.
    You can check if you can see that image in Tools > Page Info > Media
    See also:
    [[Images or animations do not show]]
    [[Websites look wrong]]

  • E-mail is in simple text. how can it be changed to html?

    all e-mail is in simple text. i want to change it to html. when an e-mail shows Click Here for better images, the Click Here is not highlighted so I cannot get the html version.

    Clear the cache and the cookies from sites that cause problems.
    "Clear the Cache":
    * Firefox > Preferences > Advanced > Network > Offline Storage (Cache): "Clear Now"
    "Remove Cookies" from sites causing problems:
    * Firefox > Preferences > Privacy > Cookies: "Show Cookies"
    Start Firefox in <u>[[Safe Mode]]</u> to check if one of the extensions or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox (Tools) > Add-ons > Appearance/Themes).
    *Don't make any changes on the Safe mode start window.
    *https://support.mozilla.com/kb/Safe+Mode

Maybe you are looking for

  • Header line item mapping issue in LSMW

    Hello experts, I am trying to map my data in LSMW with header and line items.My structure looks like this. 1header col1 col2 col3 (2item) col1 col2 1header col1 col2 col3 (2item) col1 col2 In the line item col1 changes its posting key. Header is reap

  • Is there a way to distribute new versions of iOS to all Enterprise iphone users?

    I see that with Mobile Device Management (MDM) we can configure iphones with various policies and restrictions, and also deploy applications to the users.  But is there a way to centrally distribute new versions of the iOS to the phones, so that they

  • Problems with SQL Developer 2.3.0 on Ubuntu

    I installed on my 'Acer Aspire one' Ubuntu 9.04 and OracleXE and SQLDeveloper 2.3.0. The connection to the database functions. (I've been connected as HR) But when I use the 'Database Navigator' and select 'Schemas -> HR (default) -> Tables' than hap

  • ISE & EAP-TLS Wired document

    All, Is there a document out there that explicitly shows wired authentication via EAP-TLS and explains the steps? I have a good handle on what's needed, but I had trouble finding relevant documentation.

  • Magic Wand won't select CS5.5 OSX

    Was working on a file that is very intricate, going back and forth with shortcuts from the wand (W) to the eyedropper (I) and I must of hit something because now my magic wand won't select any of the fine details in my file, when I click it selects t