 |
|
BaselScript |
Beschreibung
Dialog
▀ ▀ ▀ ▀ JAVA ▀ ▀ ▀ ▀
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Create a button click listener
DialogInterface.OnClickListener buttonClickListener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case DialogInterface.BUTTON_POSITIVE:
// Handle the positive button click
// This is where you can put your code for the positive button action
break;
case DialogInterface.BUTTON_NEGATIVE:
// Handle the negative button click
// This is where you can put your code for the negative button action
break;
case DialogInterface.BUTTON_NEUTRAL:
// Handle the neutral button click
// This is where you can put your code for the neutral button action
break;
}
}
};
// Create the AlertDialog
AlertDialog alertDialog = new AlertDialog.Builder(this)
.setTitle("Dialog with Three Buttons")
.setMessage("This is a dialog with three buttons.")
.setPositiveButton("Positive", buttonClickListener)
.setNegativeButton("Negative", buttonClickListener)
.setNeutralButton("Neutral", buttonClickListener)
.create();
// Show the AlertDialog
alertDialog.show();
}
}
▀ ▀ ▀ ▀ KOTLIN ▀ ▀ ▀ ▀
import android.app.AlertDialog
import android.content.DialogInterface
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// Create a button click listener
val buttonClickListener = DialogInterface.OnClickListener { dialog, which ->
when (which) {
DialogInterface.BUTTON_POSITIVE -> {
// Handle the positive button click
// This is where you can put your code for the positive button action
}
DialogInterface.BUTTON_NEGATIVE -> {
// Handle the negative button click
// This is where you can put your code for the negative button action
}
DialogInterface.BUTTON_NEUTRAL -> {
// Handle the neutral button click
// This is where you can put your code for the neutral button action
}
}
}
// Create the AlertDialog
val alertDialog = AlertDialog.Builder(this)
.setTitle("Dialog with Three Buttons")
.setMessage("This is a dialog with three buttons.")
.setPositiveButton("Positive", buttonClickListener)
.setNegativeButton("Negative", buttonClickListener)
.setNeutralButton("Neutral", buttonClickListener)
.create()
// Show the AlertDialog
alertDialog.show()
}
}
▀ ▀ ▀ ▀ PYTHON ▀ ▀ ▀ ▀
import tkinter as tk
from tkinter import messagebox
# Function to handle button clicks
def button_click(button_number):
if button_number == 1:
messagebox.showinfo("Button 1", "You clicked Button 1")
elif button_number == 2:
messagebox.showinfo("Button 2", "You clicked Button 2")
elif button_number == 3:
messagebox.showinfo("Button 3", "You clicked Button 3")
# Create the main window
root = tk.Tk()
root.title("Button Dialog")
# Create and place three buttons
button1 = tk.Button(root, text="Button 1", command=lambda: button_click(1))
button2 = tk.Button(root, text="Button 2", command=lambda: button_click(2))
button3 = tk.Button(root, text="Button 3", command=lambda: button_click(3))
button1.pack()
button2.pack()
button3.pack()
▀ ▀ ▀ ▀ DELPHI ▀ ▀ ▀ ▀
unit MainForm;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
ButtonSelected: Integer;
begin
// Show the message dialog with three buttons
ButtonSelected := MessageDlg(`Dialog with Three Buttons`, mtConfirmation, mbYesNoCancel, 0);
// Handle the button click
case ButtonSelected of
mrYes:
begin
// Handle the positive button click
// This is where you can put your code for the positive button action
end;
mrNo:
begin
// Handle the negative button click
// This is where you can put your code for the negative button action
end;
mrCancel:
begin
// Handle the neutral button click
// This is where you can put your code for the neutral button action
end;
end;
end;
end.
▀ ▀ ▀ ▀ BASEL SCRIPT ▀ ▀ ▀ ▀
scene=1 name="dialog with 3 buttons"
section init // this section called first automatically
call dialog=dia
end
dialog dia // dialog definition
tile=title text="Dialog with 3 Buttons"
tile=text text="This is a dialog with 3 buttons"
tile=button1 text=@save action=button1
tile=button2 text=@cancel action=button2
tile=button3 text=@back action=back
end
// button 1 was pressed
action button1
message "You clicked Button 1"
end
// button 2 was pressed
action button2
message "You clicked Button 1"
end
// button BACK was pressed
action back
message "You clicked button BACK"
call script=examples_dialog
end
-------------------------------
end scene