如何导入javax。摇摆在android的工作室

时间:2023-01-26 19:37:06

I have just setup Android Studio and started a simple application. Well started is an over statement, I got stuck on first few lines and am unable to import JFrame into android studio.

我刚刚安装了Android Studio,并启动了一个简单的应用程序。好的开始是一个过度的声明,我被卡在最初的几行并且不能导入JFrame到android studio。

I have the latest SDK installed aling with LibGDX. I am still not able to setup JFrame. I have searched the net/youtube and no solutions have been found.

我有最新的SDK安装了LibGDX。我仍然不能设置JFrame。我搜索了网络/youtube,没有找到解决方案。

I can see the javax and swing in my external libraries but just cannot import.

我可以在我的外部库中看到javax和swing,但是不能导入。

Any ideas what I am doing wrong or not doing?

知道我做错了什么吗?

I am not looking for a "how to tutorial", I just a pointer where I should go hunting for the answer.

我不是在寻找“如何指导”,我只是一个我应该去寻找答案的指针。

wow, not huge amount of response.

哇,反响不是很大。

Please advise if I have asked a stupid question or difficult question.

如果我问了一个愚蠢的问题或困难的问题,请建议。

public hungryDog() {

        JFrame jframe = new JFrame(); 
        Timer timer = new Timer(20, this); 

                renderer = new Renderer(); 
        rand = new Random(); 


        jframe.add(renderer); 
        jframe.setTitle("Hungry Dog"); 
        jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
        jframe.setSize(WIDTH, HEIGHT); 
        jframe.addMouseListener(this); 
        jframe.addKeyListener(this); 
        jframe.setResizable(false); 
        jframe.setVisible(true); 


        dog = new Rectangle(WIDTH / 2 - 10, HEIGHT / 2 - 10, 20, 20); 
        columns = new ArrayList<Rectangle>(); 


        addColumn(true); 
        addColumn(true); 
        addColumn(true); 
        addColumn(true); 


        timer.start(); 
    } 

如何导入javax。摇摆在android的工作室

2 个解决方案

#1


6  

I used to have the same problem; here's how to solve it. You see, we were trying to use swing lib in a totally wrong context, that is, within an Android app. As Scott Barta pointed out, Android has its own mechanisms for doing what we wanted to achieve and that's why IntelliJ didn't let us import anything that would interfere with Android API. Hence, do NOT use Android app when, say, simply learning how to code in Java or, on a more advanced level, when testing/debugging your algorithms. Instead, build a standalone Java program (yes, in Android Studio). This very topic is covered here: Can Android Studio be used to run standard Java projects? , "Tested on Android Studio 0.8.6 - 1.0.2" by idunnololz). A few clarifying remarks to this solution: 1) wnen preparing your configuration (Run | Edit Configurations...), use your new Java module name and its main class in the appropriate fields. 2) before clicking Run make sure you selected same configuration.

我以前也有同样的问题;这是怎么解决的。你看,我们试图使用swing*在一个完全错误的环境中,也就是说,在一个Android应用程序。斯科特Barta指出,Android有自己的做我们想实现的机制,这就是为什么IntelliJ没有让我们导入任何干扰Android API。因此,不要在仅仅学习如何用Java编写代码时使用Android应用程序,或者在更高级的级别上,在测试/调试算法时使用Android应用程序。相反,构建一个独立的Java程序(是的,在Android Studio中)。这里讨论了这个主题:Android Studio可以用来运行标准的Java项目吗?,“在idunnololz设计的Android Studio 0.8.6 - 1.0.2上测试”。对这个解决方案的一些澄清:1)wnen准备配置(运行|编辑配置……),在适当的字段中使用新的Java模块名及其主类。2)在单击Run之前,请确保选择了相同的配置。

Incidentally, there indeed IS a way to import swing library into any Android app: based on http://www.youtube.com/watch?v=fHEvI_G6UtI. Specifically, add a new line to build.gradle file for your Module:app: compile files ('<path_to_your_jdk's_rt.jar>') Like this: compile files ('C:/Program Files/Java/jdk1.8.0_31/jre/lib/rt.jar') Note single quotes and forward slashes. Then click Sync Gradle icon and enjoy the view.

顺便说一句,确实有一种方法可以将swing库导入任何Android应用程序:基于http://www.youtube.com/watch?v=fHEvI_G6UtI。具体地说,添加一个新的行来构建。应用程序:编译文件(' '):编译文件('C:/Program files /Java/jdk1.8.0_31/jre/lib/rt.jar')注意单引号和前斜线。然后点击“同步渐变”图标,欣赏这个画面。 's_rt.jar>

In our particular case, however, the program won't run. The code itself will be clean, there'll be no errors; with swing lib well in place and connected, IntelliJ won't suspect a thing; the project WILL compile... but then we'll get a runtime error. Now your know why. On the other hand, this method works like magic when we do not interfere with Android API --- which we shouldn't in the first place.

然而,在我们的特殊情况下,程序不会运行。代码本身是干净的,不会有错误;有了swing lib, IntelliJ不会怀疑任何事情;该项目将编译…然后我们会得到一个运行时错误。现在你知道为什么。另一方面,当我们不干预Android API时,这种方法就像魔法一样,我们不应该在一开始就使用它。

That's all there is to it.

这就是一切。

#2


4  

You can't use Swing on Android. Android has its own UI framework which is different, and Swing isn't supported. To see what Java APIs are supported on Android look at the API docs at http://developer.android.com/reference/packages.html

你不能在Android上使用Swing。Android有自己不同的UI框架,而且不支持Swing。要查看在Android上支持哪些Java API,请查看http://developer.android.com/reference/packages.html的API文档。

#1


6  

I used to have the same problem; here's how to solve it. You see, we were trying to use swing lib in a totally wrong context, that is, within an Android app. As Scott Barta pointed out, Android has its own mechanisms for doing what we wanted to achieve and that's why IntelliJ didn't let us import anything that would interfere with Android API. Hence, do NOT use Android app when, say, simply learning how to code in Java or, on a more advanced level, when testing/debugging your algorithms. Instead, build a standalone Java program (yes, in Android Studio). This very topic is covered here: Can Android Studio be used to run standard Java projects? , "Tested on Android Studio 0.8.6 - 1.0.2" by idunnololz). A few clarifying remarks to this solution: 1) wnen preparing your configuration (Run | Edit Configurations...), use your new Java module name and its main class in the appropriate fields. 2) before clicking Run make sure you selected same configuration.

我以前也有同样的问题;这是怎么解决的。你看,我们试图使用swing*在一个完全错误的环境中,也就是说,在一个Android应用程序。斯科特Barta指出,Android有自己的做我们想实现的机制,这就是为什么IntelliJ没有让我们导入任何干扰Android API。因此,不要在仅仅学习如何用Java编写代码时使用Android应用程序,或者在更高级的级别上,在测试/调试算法时使用Android应用程序。相反,构建一个独立的Java程序(是的,在Android Studio中)。这里讨论了这个主题:Android Studio可以用来运行标准的Java项目吗?,“在idunnololz设计的Android Studio 0.8.6 - 1.0.2上测试”。对这个解决方案的一些澄清:1)wnen准备配置(运行|编辑配置……),在适当的字段中使用新的Java模块名及其主类。2)在单击Run之前,请确保选择了相同的配置。

Incidentally, there indeed IS a way to import swing library into any Android app: based on http://www.youtube.com/watch?v=fHEvI_G6UtI. Specifically, add a new line to build.gradle file for your Module:app: compile files ('<path_to_your_jdk's_rt.jar>') Like this: compile files ('C:/Program Files/Java/jdk1.8.0_31/jre/lib/rt.jar') Note single quotes and forward slashes. Then click Sync Gradle icon and enjoy the view.

顺便说一句,确实有一种方法可以将swing库导入任何Android应用程序:基于http://www.youtube.com/watch?v=fHEvI_G6UtI。具体地说,添加一个新的行来构建。应用程序:编译文件(' '):编译文件('C:/Program files /Java/jdk1.8.0_31/jre/lib/rt.jar')注意单引号和前斜线。然后点击“同步渐变”图标,欣赏这个画面。 's_rt.jar>

In our particular case, however, the program won't run. The code itself will be clean, there'll be no errors; with swing lib well in place and connected, IntelliJ won't suspect a thing; the project WILL compile... but then we'll get a runtime error. Now your know why. On the other hand, this method works like magic when we do not interfere with Android API --- which we shouldn't in the first place.

然而,在我们的特殊情况下,程序不会运行。代码本身是干净的,不会有错误;有了swing lib, IntelliJ不会怀疑任何事情;该项目将编译…然后我们会得到一个运行时错误。现在你知道为什么。另一方面,当我们不干预Android API时,这种方法就像魔法一样,我们不应该在一开始就使用它。

That's all there is to it.

这就是一切。

#2


4  

You can't use Swing on Android. Android has its own UI framework which is different, and Swing isn't supported. To see what Java APIs are supported on Android look at the API docs at http://developer.android.com/reference/packages.html

你不能在Android上使用Swing。Android有自己不同的UI框架,而且不支持Swing。要查看在Android上支持哪些Java API,请查看http://developer.android.com/reference/packages.html的API文档。