home *** CD-ROM | disk | FTP | other *** search
- // BlinkText.java
- // Einfaches Java Bean, das einen Text darstellt
-
- package demo.beans;
-
- import java.awt.*;
- import java.awt.event.*;
-
- public class TextBean extends Canvas implements MouseListener {
-
- // Eigenschaften
- ActionListener actionlistener = null;
- protected String text = "Hallo!";
-
- // Initialisierung
- public TextBean() {
- setSize(100, 100);
- addMouseListener(this);
- }
-
- // Schnittstellenfunktionen
- public void setText(String t) {
- text = t;
- }
-
- public String getText() {
- return text;
- }
-
- // Ausgabe des Texts
- public void paint(Graphics g) {
- g.drawString(text, 10, 20);
- }
-
- // Austauschen von Vordergrund- und Hintergrundfarbe
- public void swapColors() {
- Color c = getBackground();
- setBackground(getForeground());
- setForeground(c);
- }
-
- // Registrierung von Listenern
- public void addActionListener(ActionListener listener) throws java.util.TooManyListenersException {
- if (actionlistener == null)
- actionlistener = listener;
- else
- throw new java.util.TooManyListenersException();
- }
-
- public void removeActionListener(ActionListener listener) {
- if (actionlistener == listener)
- actionlistener = null;
- }
-
- // Ereignisbearbeitung
- public void mouseClicked(MouseEvent e) {
- if (actionlistener != null)
- actionlistener.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "Click!"));
- }
-
- public void mouseEntered(MouseEvent e) {
- }
-
- public void mouseExited(MouseEvent e) {
- }
-
- public void mousePressed(MouseEvent e) {
- }
-
- public void mouseReleased(MouseEvent e) {
- }
- }
-
-
-
-