我是一個總的諾基亞到android,真的很難理解一些概念。我也對Java swing有一些瞭解。我對使用spring mvc的java web應用程序有點了解。我使用的Eclipse靛藍android-如何將java swing轉換爲android?
事情是這樣的:
我成功創建Android應用程序命名爲AndroidExer
我創建了一個包com.swing.demo
並放置在已經運行的擺動源代碼JTextAreaDemo.java
(來源是一個教程後,這是在純java中工作)。看起來這個android不能識別swing軟件包(我不知道我是否理解正確,請幫助我),因爲我得到了很多錯誤,其中大部分都是這樣說的<Class name> cannot be resolved to a type.
當我檢查建議時,eclipse不包含任何關於導入的建議讓我認爲android不認識swing。
我試了一下研究,發現android無法運行swing。 can we run java swing and applet on android
我的問題是如何將簡單的擺動演示轉換爲android。我不知道在哪裏以及如何開始。我真的需要幫助。順便說一句,該代碼是JTextAreaDemo.java
低於下來:
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);
}
}
我真的需要你的幫助。謝謝。
這不是一個可回答的問題,類似於「我怎樣才能把貓變成狗」。解決方案:學習android編程。你聲稱你「沒有線索」,但有很多教程和資源可以讓你得到線索。我建議你這樣做。投票結束這個非問題。 – 2012-08-10 03:23:44