Java 自己写的一个快速记忆卡(flash card)的小程序1.0版
package flashcard;
import javax.swing.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class FlashCard {
private JFrame frame;
private JPanel mainPanel;
private JMenuBar menuBar;
private JMenu fileMenu;
private JMenuItem newMenuItem;
private JMenuItem loadMenuItem;
private JMenuItem saveMenuItem;
private JMenuItem exitMenuItem;
private JTextArea question;
private JTextArea answer;
private JTextArea display;
private ArrayList<QuizCard> cardBuildList; //新建卡片时,临时储存卡片数据,保存时数据输入文件
private ArrayList<QuizCard> cardPlayList; //载入卡片时,储存卡片数据
private JButton nextButtonBuild;
private JButton saveButtonBuild;
private JButton nextButtonPlay;
private boolean isShowAnswer;
private int currentCardIndex;
private QuizCard currentCard;
public static void main(String[] args) {
FlashCard fc = new FlashCard();
fc.setFrameGui();
}
public void setFrameGui() {
frame = new JFrame("快速记忆卡");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mainPanel = new JPanel();
menuBar = new JMenuBar();
fileMenu = new JMenu("文件");
newMenuItem = new JMenuItem("新建卡片");
loadMenuItem = new JMenuItem("载入卡片");
saveMenuItem = new JMenuItem("保存");
exitMenuItem = new JMenuItem("退出");
saveMenuItem.setEnabled(false); //在初始界面,saveMenuItem不能操作
//给四个菜单项添加监听器
newMenuItem.addActionListener(new NewMenuListener());
loadMenuItem.addActionListener(new LoadMenuListener());
saveMenuItem.addActionListener(new SaveMenuListener());
exitMenuItem.addActionListener(new ExitListener());
fileMenu.add(newMenuItem);
fileMenu.add(saveMenuItem);
fileMenu.add(loadMenuItem);
fileMenu.add(exitMenuItem);
menuBar.add(fileMenu);
frame.setJMenuBar(menuBar);
frame.getContentPane().add(BorderLayout.CENTER, mainPanel);
frame.setSize(500