Java 我如何让这段代码在Eclipse之外运行,并允许用户在JFrame或类似的东西中输入/输出

Java 我如何让这段代码在Eclipse之外运行,并允许用户在JFrame或类似的东西中输入/输出,java,Java,我为一个编程类编写了这段代码,它完整而正确,我对这段代码感兴趣只是为了我自己的知识。如何让这个程序在Eclipse之外运行,并将扫描器和输出放在JFrame或类似的东西中?任何评论和建议都意义重大。我对java非常陌生,这是我的第三个程序 这是主课 import java.util.Scanner; public class SeqGenTest { /** * Instance Variables passed to SeqGen.java */ String

我为一个编程类编写了这段代码,它完整而正确,我对这段代码感兴趣只是为了我自己的知识。如何让这个程序在Eclipse之外运行,并将扫描器和输出放在JFrame或类似的东西中?任何评论和建议都意义重大。我对java非常陌生,这是我的第三个程序

这是主课

    import java.util.Scanner;
    public class SeqGenTest 
    {

/**
 * Instance Variables passed to SeqGen.java
 */
String max;
String minmax;
String maxdiv;
boolean loop = true;
int a;
int b;
int c;
/**
 * main method that allows user input to select and execute commands
 * based upon the input of said user
 * @param max, minmax, maxdiv,
 * @return ints based upon calculation
 */
public static void main(String[] args) 
{
    boolean loop = true;
    while(loop = true)
    {
    System.out.println("Enter a command (max, minmax, maxdiv, end)");
    Scanner inpt = new Scanner(System.in);
    String userInpt = inpt.nextLine();

    if (userInpt.equalsIgnoreCase("max"))
    {
        System.out.println("Please enter your Max (intergers)");
        int maximum = 0; //= inpt.nextInt();
        try {
            maximum = inpt.nextInt();    
        } catch (Exception e) {
            System.out.println("The value you have input is not an integer");
            inpt.close();
            return;
        }
        if (maximum <= 0)
        {
            System.out.println("Error, empty sequence");
        }
        else if (maximum < -9 || maximum > 200)
        {
            System.out.println("Error, bounds exception");
        }
        else if (maximum > 0 && maximum < 201)
        {
        System.out.println("Here is your sequence:");
        SeqGen x = new SeqGen (maximum);
            while(x.hasNextValue()){
            System.out.println(x.getNextValue());}
        }
        }
    else if (userInpt.equalsIgnoreCase("minmax"))
        {
        System.out.println("Please enter your min, max (intergers)");
        int minimum = 0;
        int maximum = 0;
        try {
            minimum = inpt.nextInt();    
        } catch (Exception e) {
            System.out.println("The value you have input is not an integer");
            inpt.close();
            return;
        }
        try {
            maximum = inpt.nextInt();    
        } catch (Exception e) {
            System.out.println("The value you have input is not an integer");
            inpt.close();
            return;
        }
        if (minimum > maximum)
        {
            System.out.println("Error, empty sequence");
        }
        else if (maximum < -9 || maximum > 200 || minimum < -9 || minimum > 200)
        {
            System.out.println("Error, bounds exception");
        }
        else if (maximum > 0 && maximum < 201 && minimum > 0 && minimum < 201)
        {
        System.out.println("Here is your sequence:");
        SeqGen x = new SeqGen (minimum, maximum);
            while(x.hasNextValue()){
            System.out.println(x.getNextValue());}
        }
        }
    else if (userInpt.equalsIgnoreCase("maxdiv"))
        {
        System.out.println("Please enter your min, max, div (intergers)");
        int minimum = 0;
        int maximum = 0;
        int divisor = 0;
        try {
            minimum = inpt.nextInt();    
        } catch (Exception e) {
            System.out.println("The value you have input is not an integer");
            inpt.close();
            return;
        }
        try {
            maximum = inpt.nextInt();    
        } catch (Exception e) {
            System.out.println("The value you have input is not an integer");
            inpt.close();
            return;
        }
        try {
            divisor = inpt.nextInt();    
        } catch (Exception e) {
            System.out.println("The value you have input is not an integer");
            inpt.close();
            return;
        }
        if (maximum < minimum || minimum < 1 || divisor > maximum)
        {
            System.out.println("Error, empty sequence");
        }
        else if (maximum < -9 || maximum > 200 || minimum < -9 || minimum > 200 || divisor < -9 || divisor > 200)
        {
            System.out.println("Error, bounds exception");
        }
        else if (maximum > 0 && maximum < 201 && minimum > 0 && minimum < 201 && divisor > 0 && divisor < 201)
        {
        System.out.println("Here is your sequence:");
        SeqGen x = new SeqGen (minimum, maximum, divisor);
            while(x.hasNextValue()){
            System.out.println(x.getNextValue());}
        }
        }
    else if (userInpt.equalsIgnoreCase("end"))
        {
        System.out.println("Program Terminated Normally");
        inpt.close();
        System.exit(0);
        }
    else
        {
        System.out.println("Error, bounds exception. System will now     exit");
        inpt.close();
        System.exit(0);
        }

    }   
    }
    }
import java.util.Scanner;
公共类SeqGenTest
{
/**
*传递给SeqGen.java的实例变量
*/
字符串最大值;
字符串最小值;
字符串maxdiv;
布尔循环=真;
INTA;
int b;
INTC;
/**
*允许用户输入选择和执行命令的主方法
*基于所述用户的输入
*@param max,minmax,maxdiv,
*@根据计算返回整数
*/
公共静态void main(字符串[]args)
{
布尔循环=真;
while(loop=true)
{
System.out.println(“输入命令(max,minmax,maxdiv,end)”;
扫描仪输入=新扫描仪(系统输入);
字符串userInpt=inpt.nextLine();
if(userInpt.equalsIgnoreCase(“max”))
{
System.out.println(“请输入您的最大值(整数)”);
int max=0;/=inpt.nextInt();
试一试{
最大值=inpt.nextInt();
}捕获(例外e){
System.out.println(“您输入的值不是整数”);
inpt.close();
返回;
}
如果(最多200)
{
System.out.println(“错误,边界异常”);
}
否则如果(最大值>0&&最大值<201)
{
System.out.println(“这是您的序列:”);
SeqGen x=新SeqGen(最大值);
while(x.hasNextValue()){
System.out.println(x.getNextValue());}
}
}
else if(userInpt.equalsIgnoreCase(“minmax”))
{
System.out.println(“请输入您的最小值、最大值(整数)”;
int最小值=0;
int最大值=0;
试一试{
最小值=inpt.nextInt();
}捕获(例外e){
System.out.println(“您输入的值不是整数”);
inpt.close();
返回;
}
试一试{
最大值=inpt.nextInt();
}捕获(例外e){
System.out.println(“您输入的值不是整数”);
inpt.close();
返回;
}
如果(最小值>最大值)
{
System.out.println(“错误,空序列”);
}
否则如果(最大值<-9 |最大值>200 |最小值<-9 |最小值>200)
{
System.out.println(“错误,边界异常”);
}
否则如果(最大值>0&&最大值<201&&最小值>0&&最小值<201)
{
System.out.println(“这是您的序列:”);
SeqGen x=新SeqGen(最小值、最大值);
while(x.hasNextValue()){
System.out.println(x.getNextValue());}
}
}
else if(userInpt.equalsIgnoreCase(“maxdiv”))
{
System.out.println(“请输入您的最小值、最大值、div(整数)”;
int最小值=0;
int最大值=0;
整数除数=0;
试一试{
最小值=inpt.nextInt();
}捕获(例外e){
System.out.println(“您输入的值不是整数”);
inpt.close();
返回;
}
试一试{
最大值=inpt.nextInt();
}捕获(例外e){
System.out.println(“您输入的值不是整数”);
inpt.close();
返回;
}
试一试{
除数=inpt.nextInt();
}捕获(例外e){
System.out.println(“您输入的值不是整数”);
inpt.close();
返回;
}
if(最大值<最小值| |最小值<1 | |除数>最大值)
{
System.out.println(“错误,空序列”);
}
否则如果(最大值<-9 |最大值>200 |最小值<-9 |最小值>200 |除数<-9 |除数>200)
{
System.out.println(“错误,边界异常”);
}
else if(最大值>0&&最大值<201&&最小值>0&&最小值<201&&除数>0&&除数<201)
{
System.out.println(“这是您的序列:”);
SeqGen x=新的SeqGen(最小值、最大值、除数);
while(x.hasNextValue()){
System.out.println(x.getNextValue());}
}
}
else if(userInpt.equalsIgnoreCase(“end”))
{
System.out.println(“程序正常终止”);
inpt.close();
系统出口(0);
}
其他的
{
System.out.println(“错误,边界异常。系统现在将退出”);
inpt.close();
系统出口(0);
}
}   
}
}
这是“另一门课”,我不知道正确的术语是什么

    public class SeqGen
{
//instance vars
int minmax;
int max;
int maxdiv;
int current;
boolean hasNextValue;
boolean nextValue;
boolean isMax;
boolean isMinMax;
boolean isMaxDiv;
int getNextValue;
/**
 * Constructor for objects of class SeqGen
 */
public SeqGen(int a)
{
     minmax = 1;
     max = a;
     maxdiv = 1;
     current = minmax;
     isMax = true;

}

/**
 * Constructor for objects of class SeqGen 
 */
public SeqGen(int b, int a)
{
     minmax = b;
     max = a;
     maxdiv = 1;
     current = minmax;
     isMinMax = true;
}
public SeqGen(int b, int a, int c)
{
    minmax = b;
    max = a;
    maxdiv = c;
    current = minmax;
    isMaxDiv = true;

}

public boolean hasNextValue()
{
    if (current <= max) {return true; }
    else {return false;}
}
/**
 * Computes math based upon user entered commands
 * @return correct computation (int)
 */
public int getNextValue()
{
    while (current < max)
    {
        if (current%maxdiv == 0)
       {
         return current++;
       }
    else
       {
         current++;
       }
    }   
    return current++;

}
}
公共类SeqGen
{
//实例变量
int最小值;
int max;
int-maxdiv;
电流;
布尔具有下一个值;
布尔次值;
布尔isMax;
布尔isMinMax;
布尔isMaxDiv;
int getNextValue;
/**
*SeqGen类对象的构造函数
*/
公共序列(内部a)
{
最小最大值=1;
max=a;
maxdiv=1;
电流=最小最大值;
isMax=真;
}
/**
*SeqGen类对象的构造函数
*/
公共SeqGen(内部b、内部a)
{
minmax=b;
max=a;
maxdiv=1;
电流=最小最大值;
isMinMax=真;
}
公共SeqGen(内部b、内部a、内部c)
{
minmax=b;
max=a;
maxdiv=c;
电流=最小最大值;
isMaxDiv=真;
}
公共布尔值hasNextValue()
{

如果(当前基本上我可以想到两种选择:

  • 扩展
    JFrame
    类,并使用带有
    JTextArea
    的嵌入式控制台,如图所示

  • 扩展
    JFrame
    类并创建一个
    public class SeqGenTest extends JFrame{
    
        public SeqGenTest(){
    
            //set up all you UI here.
    
            //use these to show the frame.
            setSize(600, 600);
            setVisible(true);
        }
    }
    
    java -jar myProgram.jar