Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: java gui menu , saveing

  1. #1
    Junior Member
    Join Date
    Oct 2012
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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.
     
    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

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


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,607
    My Mood
    Hungover
    Thanks
    145
    Thanked 658 Times in 563 Posts

    Default Re: java gui menu , saveing

    This is only partial code- can you provide an SSCCE that we can copy and paste to run and see exactly what's going on?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Java to HTML, enable user to enter a number of menu items
    By @passat in forum What's Wrong With My Code?
    Replies: 4
    Last Post: December 3rd, 2012, 08:42 AM
  2. Replies: 21
    Last Post: May 29th, 2011, 01:48 PM
  3. Is it possible to use card layout for menu and menu items?
    By jai2rul in forum AWT / Java Swing
    Replies: 0
    Last Post: April 11th, 2011, 09:19 AM