2012-08-10 120 views
0

我是一個總的諾基亞到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); 
} 
} 

我真的需要你的幫助。謝謝。

+2

這不是一個可回答的問題,類似於「我怎樣才能把貓變成狗」。解決方案:學習android編程。你聲稱你「沒有線索」,但有很多教程和資源可以讓你得到線索。我建議你這樣做。投票結束這個非問題。 – 2012-08-10 03:23:44

回答

3

我不認爲你可以混合這兩個。如果你想要android原生應用,你需要使用Android API而不是Swing。這裏是android documentation

+1

這就是我的想法,但我將如何開始? – AndroidMoron 2012-08-10 03:23:05

+2

查找教程或購買書籍並學習android API。 – 2012-08-10 03:25:16

+0

@AndroidMoron:更新與Android文檔的網址。 – kosa 2012-08-10 03:27:11

1

只要我知道,沒有可以直接將它們轉換爲android佈局的程序,但事實上android和java非常相似。如果您使用的是Eclipse,那麼構建用戶界面不會那麼困難。您還可以使用Android開發人員的這些layout tutorial,events tutorialcontrol tutorial開始學習。

2

開始簡單。你先建立接口。然後開始添加一些「管道」。

把這個過程分解成幾個小步驟,你就知道了。當你遇到困難時,你會更容易獲得幫助。

恐怕最好的你可以希望的是重用你的swig應用程序使用的業務邏輯。除此之外,你必須從頭開始創建。

相關問題