• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Handle the app

 
Ant Leung
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
How to add

JFrame frame = new JFrame();
JPanel panel = new JPanel();
JTextField textField = new JTextField();

CustomForm form = new CustomForm();

to the code below?

package com.example.myapplication;

import android.os.Bundle;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class MainActivity extends AppCompatActivity {

   @Override
   protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       
       EdgeToEdge.enable(this);
       setContentView(R.layout.activity_main);
       ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
           Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
           v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
           return insets;
       });
   }
}
 
Rob Spoor
Sheriff
Posts: 22802
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JFrame, JPanel and JTextField are all Swing classes. Those don't work on Android. You need to use the Android equivalents. Someone that actually does Android development can probably easily tell you what these are.
 
Tim Holloway
Saloon Keeper
Posts: 28121
198
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The standard way to develop for Android is to use the Android Developer Kit. It contains everything needed to code and develop for Android, including the IntelliJ IDE with support for both Java and Kotlin and the Gradle build tool.

GUI development for Android is a lot easier, since there's a drag-and-drop editor in the IDE. The GUI definitions are defined in resource files, which are XML files.

But as Rob has said, Android is a LOT different than Swing, and you really need a good book on Android development to get anywhere.
 
Ant Leung
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How to make Android developer kit available to the app within Android studio?
 
Tim Holloway
Saloon Keeper
Posts: 28121
198
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ant Leung wrote:How to make Android developer kit available to the app within Android studio?


It's part of Android Studio.
 
Ant Leung
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you have the similar items (or approach) on Android studio, for the following?

JFrame frame = new JFrame();
JPanel panel = new JPanel();
JTextField textField = new JTextField();
 
Tim Moores
Saloon Keeper
Posts: 7632
177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No. For Android, you need to forget about Swing, its GUI toolkit is substantially different. Thinking about it in terms of Swing classes will get you nowhere.

The Android developer site has lots of introductions and tutorials; start reading at https://developer.android.com/develop/ui
 
Ant Leung
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From the given URL, I get no exact sample for the way in Android studio. Please help. Thanks.
 
Tim Holloway
Saloon Keeper
Posts: 28121
198
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ant Leung wrote:From the given URL, I get no exact sample for the way in Android studio. Please help. Thanks.


As I said earlier, Android doesn't generally create UIs in code. Instead you use the Android Studio UI designer to lay out your GUI graphically. The layout you define is stored as an XML resource.

Forget almost EVERYTHING you know about Swing. It's about as useful as being a DOS expert is in designing Windows apps. Even the threading is done differently.

A good book or tutorial on Android is essential.
 
Tim Moores
Saloon Keeper
Posts: 7632
177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ant Leung wrote:From the given URL, I get no exact sample for the way in Android studio.


That's correct. There is no shortcut to learning Android GUI programming. If you work through that material, you'll discover that somewhere in there are code examples.
 
Ant Leung
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any advice to design a window having the different areas for the different purpose?

 
Tim Moores
Saloon Keeper
Posts: 7632
177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is no difficulty in having different areas of a screen contain different GUI elements. Android has various layout styles for different kinds of presentations, just like Swing has different layout managers. https://developer.android.com/develop/ui/views/layout/declaring-layout talks about that.
 
Tim Holloway
Saloon Keeper
Posts: 28121
198
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Another UI difference. Swing is expected to share the desktop with child windows from multiple apps. Android, as originally designed was expected that the entire display would be dedicated to to current foreground app. so the layout should cover the whole screen.

Recent versions of Android allow a split screen, so two apps can be visible at the same time, but each app displays entirely within its split. still no overlapping windows or shared display space.
 
30 seconds to difuse a loaf of bread ... here, use this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic