Skip to main content

JInternalFramePROBLEM

2 replies [Last post]
jyzef
Offline
Joined: 2010-05-31

Hi, I have BIG problem with JInternalframe. I want to open Image in new InternalFrame and edit this Image, at present I have open Image, filters but Image open in all show InteralFrames and all is filters....
Please HELP

<br />
private class Open implements ActionListener<br />
{<br />
       public void actionPerformed(ActionEvent zdarzenia)<br />
    {</p>
<p>           wybor.setCurrentDirectory(new File("."));</p>
<p>           final FiltrR filtr = new FiltrR();</p>
<p>           filtr.addRoz("gif");<br />
           filtr.addRoz("jpg");<br />
           filtr.addRoz("png");</p>
<p>           wybor.setFileFilter(filtr);</p>
<p>           wybor.setAccessory(new PodgladO(wybor));</p>
<p>           wybor.setFileView(new Wyglad(filtr,new ImageIcon("palette.gif")));</p>
<p>           int wynik = wybor.showOpenDialog(Szramka.this);</p>
<p>           if(wynik == wybor.APPROVE_OPTION)<br />
           {<br />
               String nazwa =<br />
                       wybor.getSelectedFile().getPath();<br />
                 try<br />
      {</p>
<p>         img[x] = ImageIO.read(wybor.getSelectedFile());<br />
         image = new BufferedImage(img[x].getWidth(null), img[x].getHeight(null),<br />
               BufferedImage.TYPE_INT_RGB);</p>
<p>      }<br />
      catch (IOException e)<br />
      {<br />
         JOptionPane.showMessageDialog(wybor, e);<br />
      }<br />
               createInternalFrame(image,nazwa);<br />
           }</p>
<p>    }<br />
}<br />
 /**<br />
    * Creates an internal frame on the desktop.<br />
    * @param c the component to display in the internal frame<br />
    * @param t the title of the internal frame.<br />
    */<br />
public void createInternalFrame(final BufferedImage im, String t)<br />
{<br />
     iframe[x] = new JInternalFrame(t,<br />
            true,//zm rozm<br />
            true,//moz zamk<br />
            true,//max<br />
            true);//zw do ikony</p>
<p>          image.getGraphics().drawImage(img[x], 0, 0, null);</p>
<p>          JPanel panel = new<br />
                  JPanel()<br />
          {<br />
              public void paintComponent(Graphics g)<br />
              {<br />
                  if (image != null)<br />
                      g.drawImage(image, 0, 0, null);</p>
<p>              }</p>
<p>          };<br />
       iframe[x].add(panel,BorderLayout.CENTER);<br />
       desktop.add(iframe[x]);</p>
<p>     iframe[x].addVetoableChangeListener(new VetoableChangeListener()<br />
         {<br />
            public void vetoableChange(PropertyChangeEvent zdarzenie) throws PropertyVetoException<br />
            {<br />
            String name = zdarzenie.getPropertyName();<br />
            Object value = zdarzenie.getNewValue();</p>
<p>            if(name.equals("closed")&&value.equals(true))<br />
            {</p>
<p>                int result = JOptionPane.showInternalConfirmDialog(<br />
                        iframe[x],"Ok to close?","Select an Option",JOptionPane.YES_NO_OPTION);</p>
<p>                if(result != JOptionPane.YES_OPTION)<br />
                {iframe[x].setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);<br />
                 --x;<br />
                }</p>
<p>            }</p>
<p>        }<br />
    });</p>
<p>    int width = desktop.getWidth()/2;<br />
    int height = desktop.getHeight()/2;<br />
    iframe[x].reshape(nextFrameX, nextFrameY, width, height);</p>
<p>     iframe[x].show();</p>
<p>     try<br />
      {<br />
         iframe[x].setSelected(true);<br />
      }<br />
      catch (PropertyVetoException e)<br />
      {}</p>
<p>      frameDistance = iframe[x].getHeight() - iframe[x].getContentPane().getHeight();</p>
<p>      //oblicza dystans pomieddzy ramkami<br />
      nextFrameX += frameDistance;<br />
      nextFrameY += frameDistance;<br />
      if (nextFrameX + width > desktop.getWidth()) nextFrameX = 0;<br />
      if (nextFrameY + height > desktop.getHeight()) nextFrameY = 0;</p>
<p>}<br />
    private void filter(BufferedImageOp op)<br />
   {<br />
      image.getGraphics().drawImage(img[x], 0, 0, null);<br />
      if (image == null) return;<br />
      image = op.filter(image, null);<br />
      repaint();<br />
   }</p>
<p>private int y = 0;<br />
private int x = 0;<br />
private  JInternalFrame[] iframe = new JInternalFrame[10];<br />
private Image[] img = new Image[10];<br />
private BufferedImage image;<br />
private BufferedImage im;<br />
private JFileChooser wybor;<br />
private int nextFrameX;<br />
private int nextFrameY;<br />
private int frameDistance;</p>
<p>}<br />

Message was edited by: jyzef

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
walterln
Offline
Joined: 2007-04-17

The variable 'x' is the same for all internal frames so they all paint image x.

jyzef
Offline
Joined: 2010-05-31

maybe complete code help?