如何导入在Android Studio中的javax.swing [英] how to import javax.swing in android studio

查看:4683
本文介绍了如何导入在Android Studio中的javax.swing的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚安装的Andr​​oid工作室,并开始一个简单的应用程序。好了开始是过说法,我就死在第几行,但无法导入的JFrame到机器人工作室。

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.

我有LibGDX最新的SDK安装阿玲。我仍然无法安装的JFrame。我已经搜索网/ YouTube和没有解决办法已被发现。

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.

我可以看到我的外部库使用javax和摆动,但就是无法导入。

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

任何想法,我做错了还是没做?

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(); 
    } 

推荐答案

我以前也有同样的问题;这里是如何解决这个问题。
你看,我们试图使用Swing LIB在一个完全错误的情况下,即 Android应用的范围内。正如斯科特·巴塔指出,Android有自己的机制做什么,我们要实现的目标,这就是为什么的IntelliJ没有让我们导入任何可能与Android API干扰。
因此,不要使用Android应用程序的时候,比方说,只是学习如何或美元的Java C $ C,在更先进的水平,当时的测试/调试算法。相反,建立一个独立的Java程序(是的,Android Studio中)。这个题目是这里介绍:<一href=\"http://stackoverflow.com/questions/16626810/can-android-studio-be-used-to-run-standard-java-projects\">Can Android的工作室被用于运行标准的Java项目,测试在Android工作室0.8.6 - 1.0.2?按idunnololz)。一些澄清言论,这一解决方案:
1)wnen preparing配置(生成|编辑配置... ),在相应的字段使用新的Java模块的名称和它的主类。
2)点击之前的运行请确认您选择了相同的配置。

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应用:的基于http://www.youtube.com/watch?v=fHEvI_G6UtI 。具体来说,添加一个新的行为的build.gradle 文件为您的模块:应用
编译文件('&LT; path_to_your_jdk's_rt.jar&GT;')
喜欢这个:
编译文件(C:/ Program Files文件/的Java / jdk1.8.0_31 / JRE / lib目录/ rt.jar的')
注单引号和正斜杠。然后点击同步摇篮图标,并欣赏美景。

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.

在我们的特殊情况,但是,该程序将无法运行。在code本身是干净的,就会有错误;摆动到位LIB好,连接的IntelliJ不会怀疑的事情;该项目将编译......但我们会得到一个运行时错误。现在你知道为什么。在另一方面,这种方法的工作原理像变魔术一样,当我们不与Android API干扰---这是我们不应该摆在首位。

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.

这是所有有给它。

这篇关于如何导入在Android Studio中的javax.swing的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆