Can someone please tell me whats wrong with my gui script.
//Gui Script
var Runnable = java.lang.Runnable;
var PopupWindow = android.widget.PopupWindow;
var Button = android.widget.Button;
var Widget = android.widget;
var LinearLayout = Widget.LinearLayout;
var ViewGroup = android.view.ViewGroup;
var Gravity = android.view.Gravity;
var View = android.view.View;
var AlertDialog = android.app.AlertDialog;
var DialogInterface = android.content.DialogInterface;
var IO = java.io;
var File = IO.File;
var FileOutputStream = IO.FileOutputStream;
var String = java.lang.String;
var Dialog = android.app.Dialog;
var ScrollView = android.widget.ScrollView;
var EditText = Widget.EditText;
var GUI;
var ctx = com.mojang.minecraftpe.MainActivity.currentMainActivity.get();
ctx.runOnUiThread(new Runnable(){
run: function(){
try{
var layout = new LinearLayout(ctx);
var btn = new Button(ctx);
btn.setText("This is a Button");
btn.setOnClickListener(new View.OnClickListener(){
onClick: function(view){
var builder = new AlertDialog.Builder(ctx);
builder.setTitle("This is a Dialog");
builder.setMessage("NICE GUI!!");
builder.setNegativeButton("OK", new DialogInterface.OnClickListener(){
onClick: function(di, view){
di.dismiss();
}
});
var alert = builder.create();
alert.show();
}
});
layout.addView(btn);
var dialog = new Dialog(ctx);
var scroll = new Dialog(ctx);
var dLayout = new LinearLayout(ctx);
var inputname = new EditText(ctx);
var input = new EditText(ctx);
var create = new Button(ctx);
inputname.setHint("File Name");
input.setHint("Enter text here...");
create.setText("Create File!");
Dialog.setTitle("Create this file!!!");
dLayout.setOrientation(LinearLayout.VERTICAL);
dLayout.addView(inputname);
dLayout.addView(input);
dLayout.addView(create);
scroll.addView(dLayout);
Dialog.setContentView(scroll);
create.setOnClickListener(new View.OnClickListener(){
onClick: function(view){
var file = new File(SDCARD, inputname.getText().toString() + ".txt");
try{
file.createNewFile();
var fos = new FileOutputStream(file);
fos.write(input.getText().toString().getBytes());
}catch(e){print(e)}
}
});
GUI = new PopupWindow(layout, ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
GUI.showAtLocation(ctx.getWindow().getDecorView(), Gravity.TOP | Gravity.RIGHT, 0, 100);
}catch(e){
print("Error: " + e);
}
}
});
//Gui Script var Runnable = java.lang.Runnable; var PopupWindow = android.widget.PopupWindow; var Button = android.widget.Button; var Widget = android.widget; var LinearLayout = Widget.LinearLayout; var ViewGroup = android.view.ViewGroup; var Gravity = android.view.Gravity; var View = android.view.View; var AlertDialog = android.app.AlertDialog; var DialogInterface = android.content.DialogInterface; var IO = java.io; var File = IO.File; var FileOutputStream = IO.FileOutputStream; var String = java.lang.String; var Dialog = android.app.Dialog; var ScrollView = android.widget.ScrollView; var EditText = Widget.EditText; var GUI; var ctx = com.mojang.minecraftpe.MainActivity.currentMainActivity.get(); ctx.runOnUiThread(new Runnable(){ run: function(){ try{ var layout = new LinearLayout(ctx); var btn = new Button(ctx); btn.setText("This is a Button"); btn.setOnClickListener(new View.OnClickListener(){ onClick: function(view){ var builder = new AlertDialog.Builder(ctx); builder.setTitle("This is a Dialog"); builder.setMessage("NICE GUI!!"); builder.setNegativeButton("OK", new DialogInterface.OnClickListener(){ onClick: function(di, view){ di.dismiss(); } }); var alert = builder.create(); alert.show(); } }); layout.addView(btn); var dialog = new Dialog(ctx); var scroll = new Dialog(ctx); var dLayout = new LinearLayout(ctx); var inputname = new EditText(ctx); var input = new EditText(ctx); var create = new Button(ctx); inputname.setHint("File Name"); input.setHint("Enter text here..."); create.setText("Create File!"); Dialog.setTitle("Create this file!!!"); dLayout.setOrientation(LinearLayout.VERTICAL); dLayout.addView(inputname); dLayout.addView(input); dLayout.addView(create); scroll.addView(dLayout); Dialog.setContentView(scroll); create.setOnClickListener(new View.OnClickListener(){ onClick: function(view){ var file = new File(SDCARD, inputname.getText().toString() + ".txt"); try{ file.createNewFile(); var fos = new FileOutputStream(file); fos.write(input.getText().toString().getBytes()); }catch(e){print(e)} } }); GUI = new PopupWindow(layout, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); GUI.showAtLocation(ctx.getWindow().getDecorView(), Gravity.TOP | Gravity.RIGHT, 0, 100); }catch(e){ print("Error: " + e); } } });Want GUI Templates? Done!
https://github.com/BeATz-UnKNoWN/ModPE_Scripts/wiki/ModPE-Script-Templates
P.S. Feel free to follow me so you know when I post "awesome" content and make the MCForums a brighter place (totally).
If you need to contact me you can either shoot a Kik message to beatz_unknown or send an email to [email protected]
Want GUI Templates? Done!
https://github.com/BeATz-UnKNoWN/ModPE_Scripts/wiki/ModPE-Script-Templates
P.S. Feel free to follow me so you know when I post "awesome" content and make the MCForums a brighter place (totally).
If you need to contact me you can either shoot a Kik message to beatz_unknown or send an email to [email protected]