android-如何将java swing转换为android? [英] android - how to convert java swing to android?
问题描述
我对android完全不了解,确实很难理解某些概念.我对Java swing也有一点了解.我对使用Spring MVC的Java Web应用程序有所了解.我正在使用日食靛蓝
I am a total noob to android and really have very hard time understanding some concepts. I also have a little understanding of java swing. I am a bit knowledgeable about java web app using spring mvc. I am using eclipse indigo
这是发生了什么
在成功创建名为AndroidExer
的android应用之后,我创建了一个包com.swing.demo
并放置了已经运行的swing源代码JTextAreaDemo.java
(源于教程.这在纯Java中工作).似乎android无法识别swing包(我不知道我是否理解正确,请帮助我),因为我遇到了很多错误,并且大多数错误提示<Class name> cannot be resolved to a type.
当我检查建议时,eclipse并没有包括有关导入的任何建议,这使我认为android无法识别swing.
After I successfully created android app named AndroidExer
I created a package com.swing.demo
and placed the already running swing source code JTextAreaDemo.java
(The source is from a tutorial. This is working in pure java). It seems that that android doesn't recognize swing packages (I don't know if I understand it correctly, please help me) because I got alot of errors and most of them says <Class name> cannot be resolved to a type.
When I check for suggestions, eclipse does not include any suggestion about importing which makes me think that android doesn't recognize swing.
我尝试了一些研究,发现android无法运行. 我们能否在android上运行java swing和applet
I tried a bit of research and I found out that android cannot run swing. can we run java swing and applet on android
我的问题是如何将简单的swing演示转换为android.我不知道从哪里开始以及如何开始.我真的需要帮助顺便说一句,JTextAreaDemo.java
的代码在下面:
My problem is how will I convert the simple swing demo to android. I don't have any clue where and how to start. I really need help. BTW, the code is for JTextAreaDemo.java
is down below:
JTextAreaDemo.java
package com.swing.demo;
import java.awt.Container;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
public class JTextAreaDemo extends JFrame implements ActionListener {
/**
*
*/
private static final long serialVersionUID = 5416184196156296457L;
JTextField jtfInput;
JTextArea jtAreaOutput;
String newline = "\n";
public JTextAreaDemo() {
createGui();
}
public void createGui() {
jtfInput = new JTextField(20);
jtfInput.addActionListener(this);
jtAreaOutput = new JTextArea(5, 20);
jtAreaOutput.setCaretPosition(jtAreaOutput.getDocument()
.getLength());
jtAreaOutput.setEditable(false);
JScrollPane scrollPane = new JScrollPane(jtAreaOutput,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
GridBagLayout gridBag = new GridBagLayout();
Container contentPane = getContentPane();
contentPane.setLayout(gridBag);
GridBagConstraints gridCons1 = new GridBagConstraints();
gridCons1.gridwidth = GridBagConstraints.REMAINDER;
gridCons1.fill = GridBagConstraints.HORIZONTAL;
contentPane.add(jtfInput, gridCons1);
GridBagConstraints gridCons2 = new GridBagConstraints();
gridCons2.weightx = 1.0;
gridCons2.weighty = 1.0;
contentPane.add(scrollPane, gridCons2);
}
public void actionPerformed(ActionEvent evt) {
String text = jtfInput.getText();
jtAreaOutput.append(text + newline);
jtfInput.selectAll();
}
public static void main(String[] args) {
JTextAreaDemo jtfTfDemo = new JTextAreaDemo();
jtfTfDemo.pack();
jtfTfDemo.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
jtfTfDemo.setVisible(true);
}
}
我真的需要你的帮助.谢谢.
I really need your help. Thanks.
推荐答案
我认为您不能将两者混为一谈.如果您要使用Android本机应用程序,则需要使用Android API,而不是Swing.这是android 文档.
I don't think you can mix those two. If you want android native app, you need to use Android API than Swing. Here is android documentation.
这篇关于android-如何将java swing转换为android?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!