How to import javax.swing into android studio

I just installed Android Studio and started a simple application. A good start is an overorder, I was stuck on the first few lines and could not import JFrame into android studio.

I have the latest SDK with LibGDX installed. I still can not configure JFrame. I searched the network / youtube and no solutions were found.

I see javax and swing in my external libraries, but just can't import.

Any ideas what I'm doing wrong or not doing?

I'm not looking “like a textbook,” I'm just a pointer to where I should look for an answer.

wow, not a huge number of answers.

Please let me know if I asked a stupid question or a 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(); 
    } 

enter image description here

+4
source share
3

; . , swing lib , Android. , Android , , IntelliJ -, Android API. , Android-, , , Java , , / . Java- (, Android Studio). : Android Studio Java?, " Android Studio 0.8.6 - 1.0.2" idunnololz). : 1) ( | ...), Java . 2) , .

, swing Android: http://www.youtube.com/watch?v=fHEvI_G6UtI. , build.gradle : : compile files ('<path_to_your_jdk's_rt.jar>') : compile files ('C:/Program Files/Java/jdk1.8.0_31/jre/lib/rt.jar') . Gradle .

. , ; swing lib , IntelliJ ; WILL ... . , . , , Android API, .

, .

+7

Swing Android. Android , Swing . , API Java Android, API http://developer.android.com/reference/packages.html.

+5

, . :

  1. Android Studio: → → → → , Java ( Kotlin) , .
  2. Java: → → → Java
  3. Android: → → → , -.
  4. : 5, , . .
  5. Edit the build.gradle of your java module and add a JRE pointing to you in the implementation fileTreedependencies .implementation fileTreeimplementation fileTree

Build.gradle example:

apply plugin: 'java-library'

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation fileTree ('/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/jre/lib/rt.jar')
}

sourceCompatibility = "6"
targetCompatibility = "6"

Now code completion works, and you can even run the application :

  • Click on Add Configuration:the start button button next to
  • Click on +→ Application
  • Choose your Main Class
  • When Use classpath of module: select your Java module there (not a project)
0
source

All Articles