Results 1 to 2 of 2
  1. #1
    zerocool1822 is offline Member
    Join Date
    Nov 2012
    Posts
    9
    Rep Power
    0

    Default java gui menu , saveing

    hello , im trying to get my save function on my menu bar to work right. when i hit save on the menu bar , it creates the file and everything. but the picture is blank. i cant seem to find what i did wrong.


    heres my save method, it supposed to save an image of my GUI canvas , but like i said i comes up blank.
    Java Code:
    public void SaveToDisk(String file) {
    		file = "save.png";
    		// need a buffered image to save the image
    		BufferedImage bufferedImage = 
    			new BufferedImage(150, 
    					150, 
    					BufferedImage.TYPE_INT_ARGB); 
    		
    		
    		Graphics g = bufferedImage.createGraphics();
    
    		this.paint(g);
    		
    		
    		g.dispose();
    		
    		
    		System.out.println("Saving file to disk:" + file); 
    		try {
    			ImageIO.write(bufferedImage, "png", new File(file));
    		} catch (Exception e) {
    			System.out.println("[e] cannot save");
    		}		
    	}
    
    	public void loadImage() {
    	      try {                
    	    	  image = ImageIO.read(new File("save.png"));
    	       } catch (IOException ex) {
    	    	   System.out.println("[e] cannot load");
    	       }
    	}
    just incase here the action listener for my save button , which im pretty sure is right

    Java Code:
    save.addActionListener(new ActionListener() {
    
    			@Override
    			public void actionPerformed(ActionEvent e) {
    				System.out.println(e.getActionCommand());
    				canvas.SaveToDisk("");
    			}
    
    		});

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

    Default Re: java gui menu , saveing

    What do you mean by "but the picture is blank"? Please provide any details that can help us help you.

    Also this looks quite suspicious:

    Java Code:
    this.paint(g);
    It appears as if you're trying to call paint(...) directly on a Swing component, something that you'll almost never want to do.

Similar Threads

  1. Java Script context menu into JAVA Context Menu...
    By cnu.nandhikonda@gmail.com in forum AWT / Swing
    Replies: 1
    Last Post: 08-22-2012, 09:14 AM
  2. Java Menu Help
    By 73challenger in forum New To Java
    Replies: 2
    Last Post: 12-10-2009, 05:19 AM
  3. Fill a menu dynamically when menu is shown
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-07-2008, 04:47 PM
  4. React to menu action and checkbox menu
    By Java Tip in forum javax.swing
    Replies: 0
    Last Post: 06-27-2008, 07:50 PM
  5. Replies: 7
    Last Post: 05-09-2008, 07:54 AM

Posting Permissions

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