如何让程序在Java窗口中运行?

如何让程序在Java窗口中运行?,java,swing,textbox,jframe,jlabel,Java,Swing,Textbox,Jframe,Jlabel,我正在学习Java,我认为最好的尝试和学习方法是创建一个小的文本冒险,它实际上包含了我正在尝试学习的某些函数 因此,我一直在慢慢地通过尝试和错误构建我的小游戏,现在我正处于这样一个阶段,我希望在实际窗口中显示它,而不是在IDE本身中 以下是名为RoleGame的课程: package rolegame; import java.util.*; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPa

我正在学习Java,我认为最好的尝试和学习方法是创建一个小的文本冒险,它实际上包含了我正在尝试学习的某些函数

因此,我一直在慢慢地通过尝试和错误构建我的小游戏,现在我正处于这样一个阶段,我希望在实际窗口中显示它,而不是在IDE本身中

以下是名为RoleGame的课程:

package rolegame;

import java.util.*;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class RoleGame extends JFrame{


public static void main(String[] args){
    RoleGame RoleGameObject = new RoleGame();
    RoleGameObject.roleGame();

}



public void roleGame() {
    JPanel roleGame = new JPanel();
    add(roleGame);
    this.setSize(1000, 1000);
    // pack();
    setVisible(true);



    TheFellowship TheFellowshipObject = new TheFellowship();
    TheFellowshipObject.yourParty();
    System.out.println();
    FellowshipInventory FellowshipInventoryObject = new FellowshipInventory();
    FellowshipInventoryObject.inventory();
    FellowshipAttributes FellowshipAttributesObject = new FellowshipAttributes();
    FellowshipAttributesObject.characterAttributes();


    Scanner in = new Scanner(System.in);

    System.out.println();
    System.out.println("You face a horde of terrible orcs...\nWhat are you going to do?\n\nYour options are as follows:\n ");
    System.out.println("Roll a 1 to run...\nRoll a 2 to stand your ground...");
    System.out.println("Roll a 3 to attack...\nRoll a 4 to attack the leader...");
    System.out.println("Roll a 5 to have your whole party attack...\nRoll a 6 to kill them all...");
    System.out.println();
    System.out.print("Press return to roll the dice!!");
    in.nextLine();

    //System.out.println("You rolled a "+ num());
    for(int i = 0; i < 1; i++){
        int num = (int) (Math.random() * 6) + 1;
        System.out.println("You rolled a " + num + "\n");
    if(num == 1){
        System.out.println("You run away to fight another day when the odds are better...");
        TheHorde TheHordeObject = new TheHorde();
        TheHordeObject.youRun();
    }
    else if(num == 2)
    {
        System.out.println("You stand your ground before the mighty horde...");
        TheHorde TheHordeObject = new TheHorde();
        TheHordeObject.standGround();
    }
    else if(num == 3)
    {
        System.out.println("You run towards your foe screaming at them as you go...");
        TheHorde TheHordeObject = new TheHorde();
        TheHordeObject.attack();
    }
    else if(num == 4)
    {
        System.out.println("You seek out the horde leader and make for him with your sword swinging...");
        TheHorde TheHordeObject = new TheHorde();
        TheHordeObject.attackLeader();
    }
    else if(num == 5)
    {
        System.out.println("You rally your party by shouting for their assistance to slain the horde...");
        TheHorde TheHordeObject = new TheHorde();
        TheHordeObject.rally();
    }
    else if(num == 6)
    {
        System.out.println("You and your party storm the horde and slain them all and cry    victory...!!");
        TheHorde TheHordeObject = new TheHorde();
        TheHordeObject.killThem();
    }
    Fighting FightingObject = new Fighting();
    FightingObject.fight();

    }

  }

}
package角色扮演;
导入java.util.*;
导入javax.swing.JFrame;
导入javax.swing.JLabel;
导入javax.swing.JPanel;
公共类RoleGame扩展了JFrame{
公共静态void main(字符串[]args){
RoleGame RoleGameObject=新RoleGame();
roleGame对象。roleGame();
}
公共无效roleGame(){
JPanel roleGame=新的JPanel();
添加(roleGame);
此.setSize(10001000);
//包装();
setVisible(真);
OFFELLOWSHIP OFFELLOWSHIPOBJECT=新OFFELLOWSHIP();
offellowshipObject.yourParty();
System.out.println();
研究员库存研究员库存对象=新研究员库存();
FellowshipInventoryObject.inventory();
FellowshipAttributes FellowshipAttributesObject=新的FellowshipAttributes();
FellowshipAttributesObject.characterAttributes();
扫描仪输入=新扫描仪(系统输入);
System.out.println();
System.out.println(“你面对一大群可怕的兽人…\n你打算怎么办?\n\n你的选择如下:\n”);
System.out.println(“滚动1以运行…\n滚动2以站稳脚跟…”);
System.out.println(“掷3攻击…\n掷4攻击首领…);
System.out.println(“掷5让你的全队攻击…\n掷6杀死他们所有…”);
System.out.println();
System.out.print(“按回车键掷骰子!!”;
in.nextLine();
//println(“您滚动了一个”+num());
对于(int i=0;i<1;i++){
intnum=(int)(Math.random()*6)+1;
System.out.println(“您滚动了一个“+num+”\n”);
如果(num==1){
System.out.println(“当胜算更大的时候,你逃跑去战斗…”);
TheHordeThehordoObject=新TheHorde();
ThehordoObject.youRun();
}
else if(num==2)
{
System.out.println(“你在强大的部落面前站稳脚跟……”);
TheHordeThehordoObject=新TheHorde();
TheHordoObject.standGround();
}
else if(num==3)
{
System.out.println(“你跑向你的敌人,一边朝他们尖叫……”);
TheHordeThehordoObject=新TheHorde();
TheHordoObject.attack();
}
else if(num==4)
{
System.out.println(“你找到部落首领,挥舞着你的剑向他冲去…”);
TheHordeThehordoObject=新TheHorde();
TheHordoObject.attackLeader();
}
else if(num==5)
{
println(“你通过呼喊要求他们协助屠杀部落来团结你的队伍……”);
TheHordeThehordoObject=新TheHorde();
ThehordoObject.rally();
}
else if(num==6)
{
System.out.println(“你和你的团队突袭部落,杀死他们,并高呼胜利…);
TheHordeThehordoObject=新TheHorde();
ThehordoObject.killThem();
}
战斗对象=新的战斗();
战斗对象。战斗();
}
}
}
首先,请接受我对原始代码的道歉。我相信您会理解,我们都从底层开始,对于学习Java的人来说,这是一个巨大的学习曲线

目前我的代码有几个小问题,但我真的希望在它自己的窗口中看到它,然后在之后更正我的其他错误


非常感谢。

很好地涵盖了基础知识。确保所有源文件都在一个位置。请记住,您要运行的是IDE编译的.CLASS文件,而不是.JAVA文件


基础知识的覆盖很好。确保所有源文件都在一个位置。请记住,您要运行的是IDE编译的.CLASS文件,而不是.JAVA文件


基础知识的覆盖很好。确保所有源文件都在一个位置。请记住,您要运行的是IDE编译的.CLASS文件,而不是.JAVA文件


基础知识的覆盖很好。确保所有源文件都在一个位置。请记住,您要运行的是IDE编译的.CLASS文件,而不是.JAVA文件


首先必须构建一个可执行文件*。jar文件。这取决于IDE,例如在Eclipse中:

在Netbeans中:

您可以在命令行中使用以下命令运行jar文件:

java -jar <your_jar_file>.jar
java-jar.jar

您也可以从中生成一个exe文件,但这本身就是一个主题。

您首先必须构建一个可执行文件*。jar文件。这取决于IDE,例如在Eclipse中:

在Netbeans中:

您可以在命令行中使用以下命令运行jar文件:

java -jar <your_jar_file>.jar
java-jar.jar

您也可以从中生成一个exe文件,但这本身就是一个主题。

您首先必须构建一个可执行文件*。jar文件。这取决于IDE,例如在Eclipse中:

在Netbeans中:

您可以在命令行中使用以下命令运行jar文件:

java -jar <your_jar_file>.jar
java-jar.jar

您也可以从中生成一个exe文件,但这本身就是一个主题。

您首先必须构建一个可执行文件*。jar文件。这取决于IDE,例如在Eclipse中:

在Netbeans中:

您可以在命令行中使用以下命令运行jar文件:

java -jar <your_jar_file>.jar
java-jar.jar

您也可以生成一个EXE文件,但这本身就是一个主题。

WangWave99对于使用系统.Out.Poad的所有消息都有一个关于空白JFrice的有效点。