Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Einfach gehaltene GUI- kleines Problem

Empfohlene Antworten

Veröffentlicht

Hallo Leute, innerhalb meines Praktikums als Anwendungsentwickler wurde mir die Aufgabe gestellt, eine einfach gehaltene GUI für einen Taschenrechner mithilfe von SWT zu schreiben.


import org.eclipse.swt.SWT;

import org.eclipse.swt.widgets.*;



public class Taschenrechnerdeluxe {


	public static void main(String[] args) {

		Display display = new Display();


		Shell shell = new Shell(display, SWT.SHELL_TRIM);

		shell.setSize(200, 260);

		shell.setText("TR © by Lukas");



		// Eingabefeld


		final Text Eingabefeld = new Text(shell, SWT.BORDER);

		// Buttons


		// Off

		Button Beenden = new Button(shell, SWT.PUSH);

		Beenden.setText("OFF");

		Beenden.setSize(65, 30);

		Beenden.setLocation(10, 185);


		// =

		Button gleich = new Button(shell, SWT.PUSH);

		gleich.setText("=");

		gleich.setSize(65, 30);

		gleich.setLocation(80, 185);


		// Zeile1


		// 7

		Button sieben = new Button(shell, SWT.PUSH);

		sieben.setText("7");

		sieben.setSize(30, 30);

		sieben.setLocation(10, 80);


		// 8

		Button acht = new Button(shell, SWT.PUSH);

		acht.setText("8");

		acht.setSize(30, 30);

		acht.setLocation(45, 80);


		// 9

		Button neun = new Button(shell, SWT.PUSH);

		neun.setText("9");

		neun.setSize(30, 30);

		neun.setLocation(80, 80);


		// DEL

		Button del = new Button(shell, SWT.PUSH);

		del.setText("DEL");

		del.setSize(30, 30);

		del.setLocation(115, 80);

		// 9

		Button ce = new Button(shell, SWT.PUSH);

		ce.setText("CE");

		ce.setSize(30, 30);

		ce.setLocation(150, 80);


		// Zeile2


		// 4

		Button vier = new Button(shell, SWT.PUSH);

		vier.setText("4");

		vier.setSize(30, 30);

		vier.setLocation(10, 115);


		// 5

		Button fuenf = new Button(shell, SWT.PUSH);

		fuenf.setText("5");

		fuenf.setSize(30, 30);

		fuenf.setLocation(45, 115);


		// 6

		Button sechs = new Button(shell, SWT.PUSH);

		sechs.setText("6");

		sechs.setSize(30, 30);

		sechs.setLocation(80, 115);


		// *

		Button mal = new Button(shell, SWT.PUSH);

		mal.setText("*");

		mal.setSize(30, 30);

		mal.setLocation(115, 115);


		// *

		Button teilen = new Button(shell, SWT.PUSH);

		teilen.setText("/");

		teilen.setSize(30, 30);

		teilen.setLocation(150, 115);


		// Zeile3

		// 1

		Button eins = new Button(shell, SWT.PUSH);

		eins.setText("1");

		eins.setSize(30, 30);

		eins.setLocation(10, 150);


		// 2

		Button zwei = new Button(shell, SWT.PUSH);

		zwei.setText("2");

		zwei.setSize(30, 30);

		zwei.setLocation(45, 150);


		// 3

		Button drei = new Button(shell, SWT.PUSH);

		drei.setText("3");

		drei.setSize(30, 30);

		drei.setLocation(80, 150);


		// -

		Button minus = new Button(shell, SWT.PUSH);

		minus.setText("-");

		minus.setSize(30, 30);

		minus.setLocation(115, 150);


		// +

		Button plus = new Button(shell, SWT.PUSH);

		plus.setText("+");

		plus.setSize(30, 30);

		plus.setLocation(150, 150);


		shell.open();

		while (!shell.isDisposed()) {

			if (!display.readAndDispatch())

				display.sleep();

		}

		display.dispose();

	}

}

Ich habe folgendes Problem:

Wenn man das Ganze, so wie es jetzt ist, startet, ist das von mir festgelegte Eingabe bzw. Textfeld nicht da wo es sein sollte. Mein Betreuer hat mir zum "Row-Layout" oder so ähnlich geraten. Wenn ich den Teil allerdings einfüge, seh ich zwar mein Textfeld (:D), allerdings zerreißt mir das die ganze GUI, so wie ich sie haben wollte!:eek:confused:

// Ich habs nochmal rausgesucht: shell.setLayout(new RowLayout());

Ich hab auch schon in Google recherchiert, und habe dazu nichts gefunden.

Hat jemand von euch vielleicht einen Rat, oder vielleicht eine Seite, die mir weiterhelfen kann ??

Liebe Grüße, Línes

Bearbeitet von Línes93

Ok, danke Lupo !

Unter Google hatte ich den Suchbegriffe "Zeilenumbruch in SWT" benutzt; weil der notfalls auch eine Möglichkeit gewesen wäre ^^

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.