| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1488 人关注过本帖
标题:啊!不知道哪里错,看得我快要怀疑人生了。
只看楼主 加入收藏
成成成
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2016-8-1
结帖率:66.67%
收藏
 问题点数:0 回复次数:0 
啊!不知道哪里错,看得我快要怀疑人生了。
import java.util.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
import *;

public class QuizCardBuilder{
    private JTextArea question;         
    private JTextArea answer;               
    private ArrayList<QuizCard> cardList;  
    private JFrame frame;         
    public static void main(String[] args){
        QuizCardBuilder builder=new QuizCardBuilder();
        builder.go();
    }
   
    public void go(){
        //创建GUI
        frame=new JFrame("Quiz Card Builder");
        JPanel mainPanel=new JPanel();      
        Font bigFont =new Font("sanserif",Font.BOLD,24);  
        question =new JTextArea(6,20);
        question.setLineWrap(true);
        question.setWrapStyleWord(true);
        question.setFont(bigFont);
        
        JScrollPane qScroller=new JScrollPane(question);  
        qScroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
        qScroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        
        answer =new JTextArea(6,20);
        answer.setLineWrap(true);
        answer.setWrapStyleWord(true);
        answer.setFont(bigFont);
        
        JScrollPane aScroller=new JScrollPane(answer);
        aScroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
        aScroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        
        JButton nextButton =new JButton("Next Card");
        
        cardList =new ArrayList<QuizCard>();
        
        JLabel qLabel=new JLabel("问题:");
        JLabel aLabel=new JLabel("答案:");
        
        mainPanel.add(qLabel);
        mainPanel.add(qScroller);
        mainPanel.add(aLabel);
        mainPanel.add(aScroller);
        mainPanel.add(nextButton);
        nextButton.addActionListener(new NextCardListener());
        JMenuBar menuBar =new JMenuBar();
        JMenu fileMenu=new JMenu("File");
        JMenuItem newMenuItem=new JMenuItem("New");  
        JMenuItem saveMenuItem=new JMenuItem("Save");
        newMenuItem.addActionListener(new NewMenuListener());
        
        saveMenuItem.addActionListener(new SaveMenuListener());
        fileMenu.add(newMenuItem);
        fileMenu.add(saveMenuItem);
        menuBar.add(fileMenu);
        frame.setJMenuBar(menuBar);
        frame.getContentPane().add(BorderLayout.CENTER,mainPanel);
        frame.setSize(500,600);
        frame.setVisible(true);
    }
   
    public class NextCardListtener implements ActionListener{
        public void actionPerformed(ActionEvent ev){
            
            QuizCard card=new QuizCard(question.getText(),answer.getText());
            cardList.add(card);
            clearCard();
        }
    }
   
    public class SaveMenuListtener implements ActionListener{
        public void actionPerformed(ActionEvent ev){
            QuizCard card=new QuizCard(question.getText(),answer.getText());
            cardList.add(card);
            
            JFileChooser fileSave=new JFileChooser();
            fileSave.showSaveDialog(frame);
            saveFile(fileSave.getSelectedFile());
        }
    }
   
    public class NewMenuListtener implements ActionListener{
        public void actionPerformed(ActionEvent ev){
            cardList.clear();
            clearCard();
        }
    }
   
    private void clearCard(){
        question.setText("");
        answer.setText("");
        question.requestFocus();
    }
   
    private void saveFile(File file){
        try{
            BufferedWriter writer=new BufferedWriter(new FileWriter(file));
            for(QuizCard card:cardList){
                writer.write(card.getQuestion()+"/");
                writer.write(card.getAnswer()+"\n");
            }
            writer.close();
        }catch(IOException ex){
            System.out.println("couldn't weite the cardList out");
            ex.printStackTrace();
        }
    }
}


import javax.swing.JTextArea;

public class QuizCard {
private JTextArea question;
private JTextArea answer;
public QuizCard(String text, String text2) {

}
public JTextArea getQuestion() {
return question;
}
//public void setQuestion(JTextArea question) {
//this.question = question;
//}
public JTextArea getAnswer() {
return answer;
}
//public void setAnswer(JTextArea answer) {
//this.answer = answer;
//}
}

到底哪里错了??
搜索更多相关主题的帖子: question private builder public frame 
2017-03-24 01:51
快速回复:啊!不知道哪里错,看得我快要怀疑人生了。
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.102216 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved