자바로 메모장의 일부분을 만드는데요..
-
게시물 수정 , 삭제는 로그인 필요
메모장이 뜨고 글을 쓴다음 저장을 하면
저장된 척 하는 파일이 생기는데 파일 크기가 0바이트에요 ㅠ
이 소스도 다 제가 만든건 아니고 왕초보라서 어처구니 없는걸 모를수도 있거든요?;
알려주세요~ ㅠ
import java.io.*;
import java.awt.*;
import java.awt.event.*;
public class H2301248 extends Frame {
private TextArea ta = null;
private TextField tf = null;
private Button button = null;
public H2301248() {
setLayout(new BorderLayout());
setTitle("Notepad");
setBounds(100,100, 600, 400);
Panel p = new Panel();
button = new Button("Save");
tf = new TextField(30);
p.add(button);
p.add(tf);
this.add(p, "South");
ta = new TextArea();
ta.setEditable(true);
add(ta, "Center");
button.addActionListener(new MyActionListener(this, tf, ta));
addWindowListener(
new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
setVisible(false);
System.exit(0);
}
}
);
}
public static void main(String args[]) {
H2301248 note = new H2301248();
note.setVisible(true);
}
}
class MyActionListener implements ActionListener {
private TextField tf = null;
private TextArea ta = null;
private Frame f = null;
public MyActionListener(Frame f, TextField tf, TextArea ta) {
this.tf = tf;
this.ta = ta;
this.f = f;
}
public void actionPerformed(ActionEvent arg0) {
FileDialog fd = new FileDialog(f, "Save..", FileDialog.SAVE);
fd.setVisible(true);
String dir = fd.getDirectory();
String fileName = fd.getFile();
File f = new File(dir, fileName);
try {
FileOutputStream fos = new FileOutputStream(f);
byte[] buf = new byte[(int)f.length()];
fos.write(buf);
tf.setText(dir+fileName);
ta.setText(new String(buf));
} catch (IOException e) {
e.printStackTrace();
}
}
}
메모장이 뜨고 글을 쓴다음 저장을 하면
저장된 척 하는 파일이 생기는데 파일 크기가 0바이트에요 ㅠ
이 소스도 다 제가 만든건 아니고 왕초보라서 어처구니 없는걸 모를수도 있거든요?;
알려주세요~ ㅠ
import java.io.*;
import java.awt.*;
import java.awt.event.*;
public class H2301248 extends Frame {
private TextArea ta = null;
private TextField tf = null;
private Button button = null;
public H2301248() {
setLayout(new BorderLayout());
setTitle("Notepad");
setBounds(100,100, 600, 400);
Panel p = new Panel();
button = new Button("Save");
tf = new TextField(30);
p.add(button);
p.add(tf);
this.add(p, "South");
ta = new TextArea();
ta.setEditable(true);
add(ta, "Center");
button.addActionListener(new MyActionListener(this, tf, ta));
addWindowListener(
new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
setVisible(false);
System.exit(0);
}
}
);
}
public static void main(String args[]) {
H2301248 note = new H2301248();
note.setVisible(true);
}
}
class MyActionListener implements ActionListener {
private TextField tf = null;
private TextArea ta = null;
private Frame f = null;
public MyActionListener(Frame f, TextField tf, TextArea ta) {
this.tf = tf;
this.ta = ta;
this.f = f;
}
public void actionPerformed(ActionEvent arg0) {
FileDialog fd = new FileDialog(f, "Save..", FileDialog.SAVE);
fd.setVisible(true);
String dir = fd.getDirectory();
String fileName = fd.getFile();
File f = new File(dir, fileName);
try {
FileOutputStream fos = new FileOutputStream(f);
byte[] buf = new byte[(int)f.length()];
fos.write(buf);
tf.setText(dir+fileName);
ta.setText(new String(buf));
} catch (IOException e) {
e.printStackTrace();
}
}
}