Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    a fundamental problem?

    hello everyone!
    i just made an account here so to introduce myself: im Ruben,
    a dutch 18 year old guy. recently got into programming and now i'm
    usually on my own studying (geeky) (still learning is never a bad thing).

    now my question is fairly simple, and if this has been posted before,
    i couldnt find it(so please dont get mad at me if i ask something very dumb,
    i did my best) and its this: i have made a simple application to get some info, and
    save some when needed, for this i used BufferedWriter. now the thing is that
    by default it will save the contents of the empty textfield (so to say, nothing)
    at launch, and is useless from there on. now i wanted to make this save button,
    but how do i make this work? i tried wait and notify, or even tried to get the textfield contents to the actionlistener of the button! yes, probably all very lame, i just dont get the hang on this. i know it wouldve been useful to post the source code, but i deleted everything, because it was an utter mess and i deleted it.
    thanks in progress, and happy new year!
    Ruben


    ps.
    okay im onto something now,
    i got a way to save, yet it prints the name off the class file in the text, followed by some numbers.

    ill give some code, if it helps, yet it might be sloppy ofcourse(im a beginner/student, obviously)

    Code:
    import java.awt.FlowLayout;
    import javax.swing.JButton;
    import javax.swing.JPanel;
    import javax.swing.JTextArea;
    
    
    public class notebook {
    
    
    	public JPanel notebook(){
    		JPanel p = new JPanel();	
    		
    		JTextArea txt = new JTextArea("      ");
    		txt.setSize(200, 300);
    		txt.setEditable(true);
    		txt.setWrapStyleWord(true);
    		txt.setLineWrap(true);
    	
    	//check this
    	Object ts = txt.getText();
    	ts.toString();
    	
    		
    		JButton b = new JButton("Save This");
    		b.addActionListener(new ALsaver());
    		FlowLayout l = new FlowLayout();
    		p.setLayout(l); 
    		
    		p.add(txt);
    		p.add(b);
    		return p;
    		}
    }
    and then...


    Code:
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.io.BufferedWriter;
    import java.io.FileWriter;
    import java.io.IOException;
    
    
    public class ALsaver implements ActionListener {
    
    	@Override
    	public void actionPerformed(ActionEvent arg0) {
    		// TODO Auto-generated method stub
    		
    		notebook n = new notebook();
    		
    		BufferedWriter bw = null;
    		try{
    			BufferedWriter fileOut = new BufferedWriter(new FileWriter("savednote.txt")); 
    			fileOut.write(String.valueOf(n)); //it probably goes wrong here, aint it?
    			fileOut.close();
    			}catch(IOException e){}
    		}                                             
    	}
    anyone knows the problem, or just something i plain forgot
    greetings,
    Ruben
    Last edited by this.isnoob; 01-04-2012 at 02:43 PM. Reason: some more info


 

Posting Permissions

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