gpt4 book ai didi

java - 带有问答系列的多项选择测试 GUI

转载 作者:行者123 更新时间:2023-12-02 07:27:03 25 4
gpt4 key购买 nike

我正在为学校开发一个 Java 编程项目。我需要设计一个 GUI,它将接受问题和答案并将它们存储在文件中。它应该能够包含无限数量的问题。我们已经介绍了二进制 I/O。

如何将他们提供的输入写入文件?我该如何让他们通过此 GUI 添加多个问题?

package multiplechoice;
import java.awt.*;
import javax.swing.*;

public class MultipleChoice extends JFrame {
public MultipleChoice() {
/*
* Setting Layout
*/
setLayout(new GridLayout(10,10));

/*
* First Question
*/

add(new JLabel("What is the category of the question?: "));
JTextField category = new JTextField();
add(category);

add(new JLabel("Please enter the question you wish to ask: "));
JTextField question = new JTextField();
add(question);

add(new JLabel("Please enter the correct answer: "));
JTextField correctAnswer = new JTextField();
add(correctAnswer);

add(new JLabel("Please enter a reccomended answer to display: "));
JTextField reccomendedAnswer = new JTextField();
add(reccomendedAnswer);

add(new JLabel("Please enter a choice for multiple choice option "
+ "A"));
JTextField A = new JTextField();
add(A);

add(new JLabel("Please enter a choice for multiple choice option "
+ "B"));
JTextField B = new JTextField();
add(B);

add(new JLabel("Please enter a choice for multiple choice option "
+ "C"));
JTextField C = new JTextField();
add(C);

add(new JLabel("Please enter a choice for multiple choice option "
+ "D"));
JTextField D = new JTextField();
add(D);

add(new JButton("Compile Questions"));
add(new JButton("Next Question"));


}

public static void main(String[] args) {
/*
* Creating JFrame to contain questions
*/
FinalProject frame = new FinalProject();
// FileOutputStream output = new FileOutputStream("Questions.dat");


JPanel panel = new JPanel();

// button.setLayout();
// frame.add(panel);

panel.setSize(100,100);

// button.setPreferredSize(new Dimension(100,100));
frame.setTitle("FinalProject");
frame.setSize(600, 400);
frame.setLocationRelativeTo(null); // Center the frame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}

最佳答案

第一:

在 Java 中写入文件基本上有两种方法。

  1. ObjectOutputStream(FileOutputStream("blah")) API
  2. PrintWriter("blah") API

第二个:

Three or more; use a for.

这就是我在阅读 JTextField A = new JTextField();JTextField B = new JTextField();

时想到的内容

关于java - 带有问答系列的多项选择测试 GUI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13427048/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com