Results 1 to 2 of 2
Thread: any one can help me....
- 12-24-2007, 03:26 PM #1
Member
- Join Date
- Nov 2007
- Posts
- 12
- Rep Power
- 0
any one can help me....
i have create menu for insert image in document...like in word procesor..i try insert the image in the document and save the document..then went i reopen that ducumnent, the picture automaticly disappear from the document...can any one help me to solve this problem in order to save the image in the document?
here the code for menu for insert image that i has create..
Java Code:IItemInsertImage.setText(imagemenu); ItemInsertImage.setToolTipText("Insert Image"); ItemInsertImage.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/thumbnail_tiny.png"))); ItemInsertImage.setComponentOrientation(java.awt.ComponentOrientation.RIGHT_TO_LEFT); ItemInsertImage.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { fc = new JFileChooser(); fc.addChoosableFileFilter(m_gifFilter); fc.addChoosableFileFilter(m_jpgFilter); fc.setDialogTitle("\u0645\u0627\u0633\u0648\u0642\u06A9\u0646\u0020\u0627\u064A\u0645\u064A\u062C"); fc.setComponentOrientation(java.awt.ComponentOrientation.RIGHT_TO_LEFT); fc.setFileFilter(m_gifFilter); fc.removeChoosableFileFilter(m_rtfFilter); Thread runner = new Thread() { public void run() { if (fc.showOpenDialog(OJMain.this) != JFileChooser.APPROVE_OPTION) return; OJMain.this.repaint(); File fChoosen = fc.getSelectedFile(); ImageIcon icon = new ImageIcon(fChoosen.getPath()); int w = icon.getIconWidth(); int h = icon.getIconHeight(); if (w<=0 || h<=0) { JOptionPane.showMessageDialog(OJMain.this,"\u0645\u0639\u0627\u0641,\u0020\u0641\u0627\u0674\u064A\u0644\u0020\u06AC\u0627\u0645\u0628\u0631\u0020\u06AC\u0627\u06AC\u0644\u0020\u062F\u0628\u0627\u0686.\n"+ fChoosen.getPath(), error , JOptionPane.WARNING_MESSAGE); return; } MutableAttributeSet attr = new SimpleAttributeSet(); StyleConstants.setIcon(attr, icon); int p = tpOpenJawi.getCaretPosition(); try { m_doc.insertString(p, " ", attr); } catch (BadLocationException ex) {} // Its ok to do this outside of the event-dispatching // thread because the chooser is not visible here. fc.addChoosableFileFilter(m_rtfFilter); fc.setFileFilter(m_rtfFilter); fc.removeChoosableFileFilter(m_gifFilter); fc.removeChoosableFileFilter(m_jpgFilter); } }; runner.start(); } }); MenuTools.add(ItemInsertImage);
below is for save document code....
Java Code:private void Save() { if(opened==true) { try { FileOutputStream out = new FileOutputStream(Opened_File); //FileWriter writer = new FileWriter(Opened_File); m_kit.write(out,tpOpenJawi.getStyledDocument(), 0, tpOpenJawi.getStyledDocument().getLength()); out.close(); //timedMessage.showIt(OJTimedMessage.FILE_SAVED); this.setTitle("\u0627\u0648\u06A4\u064A\u0646\u0020\u062C\u0627\u0648\u064A"); } catch(Exception ex) {} } else if(saved_once==true) { try { FileOutputStream out = new FileOutputStream(Saved_Once); // m_kit.write(out,tpOpenJawi.getStyledDocument(), 0, tpOpenJawi.getStyledDocument().getLength()); //FileWriter writer = new FileWriter(Saved_Once); m_kit.write(out,tpOpenJawi.getStyledDocument(), 0, tpOpenJawi.getStyledDocument().getLength()); out.close(); //timedMessage.showIt(OJTimedMessage.FILE_SAVED); this.setTitle("\u0627\u0648\u06A4\u064A\u0646\u0020\u062C\u0627\u0648\u064A"); } catch(Exception ex) {} } else SaveAs(); } private void SaveAs() { File fileToSave; JFileChooser fc = new JFileChooser(); fc.setDialogTitle (savemenu); fc.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); if(fc.showSaveDialog(OJMain.this)==0) { fileToSave = fc.getSelectedFile(); if(fileToSave.exists()) { existsDialog.showIt(); if (existsDialog.getDecision().equals("no")){ Save(); //System.out.println(fileToSave); }else { try { File fout = new File (fc.getSelectedFile().toString() + type); FileOutputStream out = new FileOutputStream(fout); //FileWriter writer = new FileWriter(fout); m_kit.write(out,tpOpenJawi.getStyledDocument(), 0, tpOpenJawi.getStyledDocument().getLength()); Saved_Once=fc.getSelectedFile(); saved_once=true; out.close(); //timedMessage.showIt(OJTimedMessage.FILE_SAVED); this.setTitle("\u0627\u0648\u06A4\u064A\u0646\u0020\u062C\u0627\u0648\u064A"); } catch (Exception ex) { ex.printStackTrace(); System.out.println("error"); } } }else{ try { File fout = new File (fc.getSelectedFile().toString() + type); FileOutputStream out = new FileOutputStream(fout); //m_kit.write(out,tpOpenJawi.getStyledDocument(), 0, tpOpenJawi.getStyledDocument().getLength()); //FileWriter writer = new FileWriter(fout); m_kit.write(out,tpOpenJawi.getStyledDocument(), 0, tpOpenJawi.getStyledDocument().getLength()); Saved_Once=fc.getSelectedFile(); saved_once=true; out.close(); //timedMessage.showIt(OJTimedMessage.FILE_SAVED); this.setTitle("\u0627\u0648\u06A4\u064A\u0646\u0020\u062C\u0627\u0648\u064A"); } catch (Exception ex) { ex.printStackTrace(); System.out.println("error"); } } fc.rescanCurrentDirectory(); } // SwingUtilities.updateComponentTreeUI(OJMain.this); }
- 12-24-2007, 08:39 PM #2
The abstract class Image does not implement the Serializable interface.
Options:
You could make up a class implementing Serializable that would deconstruct your image data, probably using a BufferedImage, and write it to file along with your object output.
Or you might find something useful in the Preferences api. Here's a couple of links for research:
Sir, What is Your Preference?
Using the Preferences API


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks