[자바] 소스를 짜는데 문의사항있습니다.
시나브로
간단한 창을 만들어서 카드Layout으로 그림을 보고
텍스트필드에 친 내용을 txt파일에 저장하려는 프로그램을 만들어보았습니다.
다른부분은 돌아가는데 유독 저장 이벤트 부분만이 오류가 발생하는데...
이부분 어떤부분이 틀렸는지 보고 지적부탁드립니다.
import java.awt.BorderLayout;
import java.awt.Button;
import jamport java.awt.CardLayout;
import java.awt.Container;
import java.awt.Label;
import java.awt.TextArea;
import java.awt.TextField;
import java.awt.Panel;
import java.io.*;
import java.util.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.*;
public class PicMemo extends JFrame implements ActionListener {
private CardLayout cardLayout;
private Panel topPanel;
private JLabel picLb1, picLb2, picLb3;
private TextField fileName;
File f = new File(random.txt);
public PicMemo(){
// 프레임 생성
super(간단한 메모장);
Container pane = getContentPane();
topPanel = new Panel();
Panel pane01 = new Panel();
Panel pane02 = new Panel();
Panel pane03 = new Panel();
cardLayout = new CardLayout();
topPanel.setLayout(cardLayout);
topPanel.add(pane01,1번 패널);
topPanel.add(pane02,2번 패널);
topPanel.add(pane03,3번 패널);ImageIcon icon1 = new ImageIcon(this.getClass().getResource(pic.jpg));
ImageIcon icon2 = new ImageIcon(this.getClass().getResource(pic1.jpg));
ImageIcon icon3 = new ImageIcon(this.getClass().getResource(pic2.jpg));
picLb1 = new JLabel(icon1);
picLb2 = new JLabel(icon2);
picLb3 = new JLabel(icon3);
pane01.add(picLb1);
pane02.add(picLb2);
pane03.add(picLb3);
pane.setLayout(new BorderLayout());
pane.add(topPanel,BorderLayout.SOUTH);
Panel buttonPane = new Panel();
// TextArea ct = new TextArea(15,50);
// buttonPane.add(ct);
pane.add(buttonPane,BorderLayout.CENTER);Panel textPane = new Panel();
Label filenameLabel = new Label(저장할 내용 :);
TextField fileName = new TextField(,30);
Button save = new Button(저장);
Button exit = new Button(종료);
Button prev = new Button(이전);
Button next = new Button(다음);
save.addActionListener(this);
prev.addActionListener(this);
next.addActionListener(this);
exit.addActionListener(this);
textPane.add(filenameLabel);
textPane.add(fileName);
buttonPane.add(prev);
buttonPane.add(next);
textPane.add(save);
textPane.add(exit);
pane.add(textPane,BorderLayout.NORTH);
}
public void actionPerformed(ActionEvent e) {
String cmd = e.getActionCommand();
if(cmd.equals(이전)) {
cardLayout.previous(topPanel);
} else if(cmd.equals(다음)) {
cardLayout.next(topPanel);
} else if(cmd.equals(종료)) {
System.exit(0);
} else if(cmd.equals(저장)) {
try {
File file = new File(test.txt);
FileOutputStream fos = new FileOutputStream(file);
OutputStreamWriter out = new OutputStreamWriter(fos);
out.write(fileName.getText());
out.close();
} catch (FileNotFoundException fnfe) {
fnfe.printStackTrace();
return;
} catch(IOException ioe){
ioe.printStackTrace();
return;
}
}} public static void main(String args[]){
PicMemo ex = new PicMemo();
ex.setSize(600,550);
ex.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ex.setVisible(true);
}
}
밑에} else if(cmd.equals(저장)) { 부분부터 시작됩니다.
-
Sonya
어떤 에러가 발생한다는거죠~? 난해하넹.... 소스에서는 out.flush(); 가 빠진거 같은데....
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2699944 | 자바스크립트가 많은 사이트는... (6) | 희나리 | 2025-06-30 |
2699918 | 브라우저마다 다른 input과 텍스트 정렬 (3) | 늘봄 | 2025-06-30 |
2699887 | 동적텍스트를 그래픽으로?? (2) | 족장 | 2025-06-30 |
2699862 | scope넣기 (1) | 아인 | 2025-06-29 |
2699835 | exe로 만드는 방법을....알려주세요.. (5) | 방방 | 2025-06-29 |
2699809 | 롤오버할때 백그라운드 이미지로할때 alt설명은 어떻게해야하죠?..ㅠ (4) | 반혈 | 2025-06-29 |
2699757 | 리스트뷰에 있는 내용을 랜덤으로 추출 | 세실 | 2025-06-28 |
2699725 | JMX 질문입니다. (1) | 시나브로 | 2025-06-28 |
2699695 | 으으아으ㅏ으ㅏ 정말미쳐버리겟네요 | 진달래 | 2025-06-28 |
2699665 | absolute에 대해서 궁금한게 있습니다 (1) | 영빈이 | 2025-06-28 |
2699629 | 테마 적용이 잘 안됩니다. ㅠㅜ (2) | 서희 | 2025-06-27 |
2699601 | html코딩 브라우져 확인 할때.. (5) | 에드워드 | 2025-06-27 |
2699575 | [질문] 고수님들...가르쳐주세염....renameTo에 관하여 | 일본드립 | 2025-06-27 |
2699547 | [급]레이어보다 object태그가 우선순위가 되는 문제 (5) | DevilsTears | 2025-06-27 |
2699518 | javaScript중복체크 하는법좀.. 알려주세요 (3) | 비 | 2025-06-26 |
2699495 | 이런 탭메뉴를 뭐라고 해야 하는지 모르겠네요 (1) | 들빛 | 2025-06-26 |
2699380 | 메뉴가 계단식으로 나타나요.. ㅠ.ㅠ (5) | 스릉흔다 | 2025-06-25 |
2699354 | 영문 웹폰트 관련 질문입니다!!! (1) | 치킨마루 | 2025-06-25 |
2699329 | 윈도우 미디어 플레이어 URL 질문!!! (1) | 제철 | 2025-06-25 |
2699296 | 동영상 배경 질문드려요!!!!!!!!!!!!!! | 핫파랑 | 2025-06-24 |