我正在创建一个应向人们传授数学基础知识的应用,我是
我尝试导入这些库:
enter code here
import java.io.IOException;
import java.io.OutputStream;
import javax.swing.JTextArea;
import java.util.Scanner;
import java.util.Random;
import java.awt.Color;
import java.awt.Component;
import java.awt.Frame;
import javax.swing.JFrame;
import java.awt.BorderLayout;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.FlowLayout;
import javax.swing.JTextField;
这是游戏的主要类别,它链接到其他类别,这些类别只是带有数字的普通文字游戏
mainGame类扩展了JFrame {
static JTextField textfield1, textfield2, textfield3;
public static void main(String[] args) {
Scanner playerInt = new Scanner(System.in);
JFrame frame = new JFrame("math game");
frame.setDefaultLookAndFeelDecorated(true);
frame.pack();
frame.setSize(300,300);
frame.getContentPane().setBackground(Color.YELLOW);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
textfield1 = new JTextField("Text field 1",10);
System.out.println("What kind of math would you like to practice? 1. addition, 2. subtraction, 3. multiplication, 4. division");
int p = playerInt.nextInt();
if(p == 1){
// link to addition
addition.main(args);
}
else if(p == 2){
// link to subtraction
subtraction.main(args);
}
else if(p == 3){
// link to multiplication
multiplication.main(args);
}
else if(p == 4){
// link to division
division.main(args);
}
} }
我想要的结果是jframe窗口内的基于文本的游戏,以便玩家完全在窗口内玩游戏,相反,我在eclipse领事中获得了基于文本的游戏,并在侧面放置了一个黄色窗口。