[자바] 소스를 짜는데 문의사항있습니다.
시나브로
간단한 창을 만들어서 카드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(); 가 빠진거 같은데....
| 번호 | 제 목 | 글쓴이 | 날짜 |
|---|---|---|---|
| 2752024 | 소숫점 뺄셈 !! ㅠㅜ | 초롬 | 2026-10-20 |
| 2751970 | 자바 게임 만들려는데 부탁드립니다 (1) | 라온제나 | 2026-10-19 |
| 2751908 | 자바스크립트 처리속도를 체크할 수 있는 방법 있나요? (1) | 테이 | 2026-10-19 |
| 2751822 | 그누보드 아이프레임으로 구현했는데 제목 클릭해서 들어가면 푸터가 동동...떠다녀요 | 내꺼하자 | 2026-10-18 |
| 2751790 | 자바 그래픽 관련을 공부하고 싶은데요.. 어디 좋은 사이트나 책 없을까요?? (1) | 큰재 | 2026-10-18 |
| 2751733 | CTF가머죠? (5) | 두동 | 2026-10-17 |
| 2751709 | 배열부분 궁금한 부분이있습니다. | 딸기우유 | 2026-10-17 |
| 2751677 | 포인터 책을 보다가,,, (2) | 동백 | 2026-10-17 |
| 2751648 | 익스플로 버전에 따라서 생기는 공백.. (1) | 모아 | 2026-10-17 |
| 2751623 | DEL 태그의에서 선굵기 및 컬러지정이 가능한가 해서요~ (4) | 비치나 | 2026-10-16 |
| 2751573 | 테마 업로드 에러.. (1) | 꽃 | 2026-10-16 |
| 2751548 | 수학? 물리?? (3) | 찬늘 | 2026-10-16 |
| 2751461 | 상단네비 fixed ie6 핵 해결방안이 있을까요? | 맑다 | 2026-10-15 |
| 2751436 | 레이아웃을 잡고 코딩을 하는데 드림위버에서의 결과와 IE에서 결과가 다르게 나오네요. (3) | 키클 | 2026-10-15 |
| 2751403 | 형들좀도와주세요string compression (1) | 알렉산더 | 2026-10-14 |
| 2751349 | 링크 다운로드하기 | 팬지 | 2026-10-14 |
| 2751295 | c++한번도 손않댄 사람이... | 날위해 | 2026-10-13 |
| 2751267 | 플래시8 사용에서 플레이어 만들었는데요 (1) | 블1랙캣 | 2026-10-13 |
| 2751182 | 회원가입 | 파랑새 | 2026-10-12 |
| 2751152 | 소셜 플러그인 문제입니다. | 얀 | 2026-10-12 |
