从VB2010到Java(android) [英] From VB2010 to Java(android)
本文介绍了从VB2010到Java(android)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用android中的按钮进行游戏。我正在用java翻译我的VB2010游戏,但我不知道什么是相当于VB编码的java,如Button1.TEXT = Button2.TEXT和...
Sub CheckButton( ByRef Butt1 作为按钮, ByRef Butt2 作为按钮)
如果 Butt2.Text = 然后
Butt2.Text = Butt1.Text
Butt1.Text =
结束 如果
结束 Sub
Sub CheckSolved()
如果 Form1.Button1.Text = 1 和 Form1.Button2.Text = 2 和 Form1.Button3.Text = 3 和
Form1.Button4.Text = 4 < span class =code-keyword>和 Form1.Button5.Text = 5 和 Form1.Button6.Text = 6 和
Form1.Button7.Text = 7 和 Form1.Button8.Text = 8 和 Form1.Button9.Text = 9 和
Form1.Button10.Text = 10 和 Form1.Button11.Text = 11 和 Form1.Button12.Text = 12 和
Form1.Button13.Text = 13 和 Form1.Button14.Text = 14 和 Form1.Button15。 Text = 15 然后
MsgBox( 哇,你在& Form1.Count& 点击,vbInformation, < span class =code-string>随机播放)
结束 如果
Form1.Count = Form1.Count + 1
Form1.Text = 随机播放:& Form1.Count& 点击
结束 Sub
...到Java。简而言之,我正在将我的VB2010项目翻译成一个Android应用程序。
这是我在eclipse中的代码,我无法使其工作。
import android.widget.Button;
import android.widget.TextView;
public class Activ2 extends 活动 implements OnClickListener {
Button btn1,btn2;
@ Override
protected void onCreate(Bundle savedInstanceState){
super .onCreate(savedInstanceState);
setContentView(R.layout.activity_activ2);
btn1 =(Button)findViewById(R.id.btn1);
btn2 =(Button)findViewById(R.id.btn2);
btn1.setOnClickListener( new View.OnClickListener(){
public void onClick(查看v){
CheckButton(btn1,btn2);
}
});
public static void CheckButton (Button Butt1,Button Butt2)
{
if (Butt2.equals( ))
{
Butt2.setText(Butt1.getText());
Butt1.setText( );
}
}
}
i在这些行中有错误:
CheckButton(btn1,btn2);
错误:方法CheckButton(Button,Button)未定义 类型 new 视图。 OnClickListener(){}
AND
public static void CheckButton(Button Butt1,Button Butt2)
错误:此行的多个标记
- 令牌上的语法错误 ),;预期
- void 是一个无效的类型 变量
CheckButton
- 令牌上的语法错误 (,;;
- 令牌上的语法错误< span class =code-string> , ,;预期
- btn无法解析为
类型 - 令牌语法错误 , ,;预期
解决方案
首先,你没有清楚你的问题,你遇到了哪些Android代码或获得任何异常?其次,我认为你需要进行一些编辑来制作它起作用:
public static < span class =code-keyword> void CheckButton(Button Butt1,Button Butt2)
{
if (但是t2.getText()。toString()== null || Butt2.getText()。length()== 0 )
{
Butt2.setText(Butt1.getText()。toString()) ;
Butt1.setText( );
}
}
如果不对其进行限定,则无法在父类上调用静态方法。另外我想你想在CheckButton
中对你的if语句进行排序。
尝试更改你的Activ2类来查看像这样的东西;
import android.widget.Button;
import android.widget.TextView;
public class Activ2 extends 活动 implements OnClickListener {
Button btn1,btn2;
@ Override
protected void onCreate(Bundle savedInstanceState){
super .onCreate(savedInstanceState);
setContentView(R.layout.activity_activ2);
btn1 =(Button)findViewById(R.id.btn1);
btn2 =(Button)findViewById(R.id.btn2);
btn1.setOnClickListener( new View.OnClickListener(){
public void onClick(查看v){
Activ2.CheckButton(btn1,btn2);
}
});
}
public static void CheckButton(Button Butt1,Button Butt2)
{
if (Butt2.getText()。equals(< span class =code-string> ))
{
Butt2.setText(Butt1.getText()) ;
Butt1.setText( );
}
}
}
希望这有帮助,
弗雷德里克
Im working on a game with buttons in android. I am translating my VB2010 game on java but i dont know what is the equivalent of VB coding to java such as "Button1.TEXT = Button2.TEXT" and...
Sub CheckButton(ByRef Butt1 As Button, ByRef Butt2 As Button)
If Butt2.Text = "" Then
Butt2.Text = Butt1.Text
Butt1.Text = ""
End If
End Sub
Sub CheckSolved()
If Form1.Button1.Text = "1" And Form1.Button2.Text = "2" And Form1.Button3.Text = "3" And
Form1.Button4.Text = "4" And Form1.Button5.Text = "5" And Form1.Button6.Text = "6" And
Form1.Button7.Text = "7" And Form1.Button8.Text = "8" And Form1.Button9.Text = "9" And
Form1.Button10.Text = "10" And Form1.Button11.Text = "11" And Form1.Button12.Text = "12" And
Form1.Button13.Text = "13" And Form1.Button14.Text = "14" And Form1.Button15.Text = "15" Then
MsgBox("Wow, You did it in " & Form1.Count & " Clicks ", vbInformation, "Shuffle")
End If
Form1.Count = Form1.Count + 1
Form1.Text = "Shuffle : " & Form1.Count & " Clicks"
End Sub
...to Java. In short, I am translating my VB2010 project into an android app.
Here's my codes in eclipse and i cant make it work.
import android.widget.Button;
import android.widget.TextView;
public class Activ2 extends Activity implements OnClickListener {
Button btn1, btn2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_activ2);
btn1 = (Button) findViewById(R.id.btn1);
btn2 = (Button) findViewById(R.id.btn2);
btn1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
CheckButton(btn1, btn2);
}
});
public static void CheckButton(Button Butt1, Button Butt2)
{
if (Butt2.equals(""))
{
Butt2.setText(Butt1.getText());
Butt1.setText("");
}
}
}
i have an error in these lines:
CheckButton(btn1, btn2);
Error: The method CheckButton(Button, Button) is undefined for the type new View.OnClickListener(){}
AND
public static void CheckButton(Button Butt1, Button Butt2)
Error: Multiple markers at this line
- Syntax error on token ")", ; expected
- void is an invalid type for the variable
CheckButton
- Syntax error on token "(", ; expected
- Syntax error on token ",", ; expected
- btn cannot be resolved to a type
- Syntax error on token ",", ; expected
解决方案
First of all, you don't clear your question, on which line of android code you got stuck or get any exception? Second, i think you need a little bit edit to make it work:
public static void CheckButton(Button Butt1, Button Butt2) { if (Butt2.getText().toString() == null || Butt2.getText().length() == 0) { Butt2.setText(Butt1.getText().toString()); Butt1.setText(""); } }
You can't call a static method on a parent class without qualifying it. Also I think you want to sort your if-statement inCheckButton
.
Try changing your Activ2 class to look something like this;
import android.widget.Button; import android.widget.TextView; public class Activ2 extends Activity implements OnClickListener { Button btn1, btn2; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_activ2); btn1 = (Button) findViewById(R.id.btn1); btn2 = (Button) findViewById(R.id.btn2); btn1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Activ2.CheckButton(btn1, btn2); } }); } public static void CheckButton(Button Butt1, Button Butt2) { if (Butt2.getText().equals("")) { Butt2.setText(Butt1.getText()); Butt1.setText(""); } } }
Hope this helps,
Fredrik
这篇关于从VB2010到Java(android)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文