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.

EchoChar abschalten

Empfohlene Antworten

Veröffentlicht

Hi Leute,

ich hab ein Textfeld mit einem EchoChar versehen.

Dieses EchoChar soll per Option abschaltbar sein.

Wie soll das Funktionieren? Laut API, wenn man das EchoChar auf 0 setzt, aber

wenn ich das so mache:

textfield.setEchoChar('0');

überschreibt er mir nur alle Stelle mit 0 und nicht mit dem eigentlich Inhalt.

Und

textfield.setEchoChar(0);

geht ja auch nicht, da ein Character erwartet wird.

Was mache ich falsch?

Danke & Gruß

LordK

Mit 0 ist der ASCII-Wert gemeint.


package de.lgm.test.gui;


import java.awt.*;

import java.awt.event.*;


public class Fenster extends Frame

{

	//Attribute

	private Button btnBeenden;

	private Button btnSchalter;

	private TextField txtFeld;

	private LayoutManager layMain;

	//Ende Attribute


	private void erzeugeKomponenten()

	{

		this.layMain = new BorderLayout();

		this.setLayout(this.layMain);

		this.btnBeenden = new Button("beenden");

		this.btnBeenden.addActionListener(new BeendenListener());

		this.btnSchalter = new Button("Echo-Schalter");

		this.btnSchalter.addActionListener(new SchalterListener());

		this.txtFeld = new TextField();

		this.add(this.btnBeenden, BorderLayout.SOUTH);

		this.add(this.btnSchalter, BorderLayout.NORTH);

		this.add(this.txtFeld, BorderLayout.CENTER);

	}


	private class BeendenListener implements ActionListener

	{

		public void actionPerformed(ActionEvent evt)

		{

			System.exit(0);

		}

	}


	private class SchalterListener implements ActionListener

	{

		public void actionPerformed(ActionEvent evt)

		{

			//Unschöner Code, da mit if's gearbeitet wird

			if (txtFeld.echoCharIsSet())

			{

				txtFeld.setEchoChar('\u0000');

			}

			else

			{

				txtFeld.setEchoChar('*');

			}

		}		

	}


	//Konstruktor

	public Fenster(String strTitel, int intBreite, int intHoehe)

	{

		this.erzeugeKomponenten();

		this.setTitle(strTitel);

		this.setBounds(1, 1, intBreite, intHoehe);

		this.setVisible(true);

	}

	//Ende Konstruktor

}

ah Besten Dank, da muss man erst mal drauf kommen... :rolleyes:

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.