View Full Version : a fundamental problem?

01-04-2012, 11:35 AM
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) :p (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!

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)

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);

//check this
Object ts = txt.getText();

JButton b = new JButton("Save This");
b.addActionListener(new ALsaver());
FlowLayout l = new FlowLayout();

return p;

and then...

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 {

public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub

notebook n = new notebook();

BufferedWriter bw = null;
BufferedWriter fileOut = new BufferedWriter(new FileWriter("savednote.txt"));
fileOut.write(String.valueOf(n)); //it probably goes wrong here, aint it?
}catch(IOException e){}

anyone knows the problem, or just something i plain forgot :p