Results 1 to 2 of 2
  1. #1
    Jyzef is offline Member
    Join Date
    Jun 2010
    Posts
    4
    Rep Power
    0

    Angry JInternalFramePROBLEM

    Hi I have BIG problem with internalframe, I want load image to new InternalFrame and then I click on this new Frame and edit Image

    Java Code:
    private class OtwieranieP implements ActionListener
    {
    public void actionPerformed(ActionEvent zdarzenia)
    {
    
    wybor.setCurrentDirectory(new File("."));
    
    
    final FiltrR filtr = new FiltrR();
    
    filtr.addRoz("gif");
    filtr.addRoz("jpg");
    filtr.addRoz("png");
    
    wybor.setFileFilter(filtr);
    
    wybor.setAccessory(new PodgladO(wybor));
    
    wybor.setFileView(new Wyglad(filtr,new ImageIcon("palette.gif")));
    
    int wynik = wybor.showOpenDialog(Szramka.this);
    
    
    
    if(wynik == wybor.APPROVE_OPTION)
    {
    String nazwa =
    wybor.getSelectedFile().getPath();
    try
    {
    
    img[x] = ImageIO.read(wybor.getSelectedFile());
    image = new BufferedImage(img[x].getWidth(null), img[x].getHeight(null),
    BufferedImage.TYPE_INT_RGB);
    
    
    }
    catch (IOException e)
    {
    JOptionPane.showMessageDialog(wybor, e);
    }
    createInternalFrame(image,nazwa);
    }
    
    
    }
    }
    
    public void createInternalFrame(final BufferedImage im, String t)
    {
    iframe[x] = new JInternalFrame(t,
    true,//zm rozm
    true,//moz zamk
    true,//max
    true);//zw do ikony
    
    image.getGraphics().drawImage(img[x], 0, 0, null);
    
    JPanel panel = new
    JPanel()
    {
    public void paintComponent(Graphics g)
    {
    if (image != null)
    g.drawImage(image, 0, 0, null);
    
    }
    
    };
    iframe[x].add(panel,BorderLayout.CENTER);
    desktop.add(iframe[x]);
    
    
    
    iframe[x].addVetoableChangeListener(new VetoableChangeListener()
    {
    public void vetoableChange(PropertyChangeEvent zdarzenie) throws PropertyVetoException
    {
    String name = zdarzenie.getPropertyName();
    Object value = zdarzenie.getNewValue();
    
    
    if(name.equals("closed")&&value.equals(true))
    {
    
    int result = JOptionPane.showInternalConfirmDialog(
    iframe[x],"Ok to close?","Select an Option",JOptionPane.YES_NO_OPTION);
    
    
    if(result != JOptionPane.YES_OPTION)
    {iframe[x].setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    --x;
    }
    
    }
    
    }
    });
    
    int width = desktop.getWidth()/2;
    int height = desktop.getHeight()/2;
    iframe[x].reshape(nextFrameX, nextFrameY, width, height);
    
    iframe[x].show();
    
    try
    {
    iframe[x].setSelected(true);
    }
    catch (PropertyVetoException e)
    {}
    
    frameDistance = iframe[x].getHeight() - iframe[x].getContentPane().getHeight();
    
    
    nextFrameX += frameDistance;
    nextFrameY += frameDistance;
    if (nextFrameX + width > desktop.getWidth()) nextFrameX = 0;
    if (nextFrameY + height > desktop.getHeight()) nextFrameY = 0;
    
    
    }
    private void filter(BufferedImageOp op)
    {
    image.getGraphics().drawImage(img[x], 0, 0, null);
    if (image == null) return;
    image = op.filter(image, null);
    repaint();
    }
    
    
    private int y = 0;
    private int x = 0;
    private JInternalFrame[] iframe = new JInternalFrame[10];
    private Image[] img = new Image[10];
    private BufferedImage image;
    private BufferedImage im;
    private JFileChooser wybor;
    private int nextFrameX;
    private int nextFrameY;
    private int frameDistance; 
    }
    Last edited by Jyzef; 06-01-2010 at 04:17 AM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Your post seems a bit incomplete as it appears you didn't finish your last sentence, and I'm not sure what you were trying to state. You may wish to clarify this a bit if you still need help.

    Also, when posting code here, please use code tags so that your code will retain its formatting and thus will be readable -- after all, your goal is to get as many people to read your post and understand your code as possible, right?

    To do this, highlight your pasted code (please be sure that it is already formatted when you paste it into the forum; the code tags don't magically format unformatted code) and then press the code button, and your code will have tags.

    Another way to do this is to manually place the tags into your code by placing the tag [code] above your pasted code and the tag [/code] below your pasted code like so:

    Java Code:
    [code]
      // your code goes here
      // notice how the top and bottom tags are different
    [/code]
    Good luck and again welcome!

Posting Permissions

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