# Buttons erstellen  ... schwer für anfänger ... bitte helft



## Sinnlos (6. Jun 2004)

also folgendes: ich bau an einenn GPL Chat und will ich da Buttons hinzufügen.
Der originalcode lautet:

```
/*
 * Copyright (c) 2000 Lyrisoft Solutions, Inc.
 * Used by permission
 */
package com.lyrisoft.chat.client.gui.awt102;

import java.awt.Button;
import java.awt.Color;
import java.awt.Component;
import java.awt.Event;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.Insets;
import java.awt.Label;
import java.awt.List;
import java.awt.Menu;
import java.awt.MenuItem;
import java.awt.Panel;
import java.awt.TextArea;
import java.awt.TextField;

import com.lyrisoft.awt.ImageButton;
import com.lyrisoft.chat.ICommands;
import com.lyrisoft.chat.Translator;
import com.lyrisoft.chat.client.gui.IChatClientInputReceiver;
import com.lyrisoft.chat.client.gui.IChatGUIFactory;
import com.lyrisoft.chat.client.gui.IChatRoom;
import com.lyrisoft.chat.client.gui.IQuery;
import com.lyrisoft.chat.client.gui.IQueryCallback;

/**
 * JDK1.0.2 compliant ChatPanel.
 *
 * This object implements IChatRoom.  It is a Panel, not a Frame.  This way, we
 * can stick these things anywhere, not necessarily just in a frame.
 */
public class ChatPanel
    extends Panel
    implements IChatRoom, IQueryCallback {
  protected Color bgColor;
  protected IChatClientInputReceiver _inputReceiver;
  protected String _room;
  protected String _title;
  protected IChatGUIFactory _factory;

  protected GridBagLayout gridbag = new GridBagLayout();
  protected TextArea txtMessages;
  protected List lstUsers;
  protected TextField txtInput;

  protected Panel _buttonPanel;

  protected Component btnClose;
  protected Component btnEmote;
  protected Component btnPing;
  protected Component btnUserInfo;
  protected Component btnEmotePrivate;
  protected Component btnPrivate;
  protected Component btnStats;
  protected Component btnHelp;

  protected MenuItem miPrivate = new MenuItem(Translator.getMessage(
      "label.private"));
  protected MenuItem miEmotePrivate = new MenuItem(Translator.getMessage(
      "label.mesg"));
  protected MenuItem miEmote = new MenuItem(Translator.getMessage("label.emote"));
  protected MenuItem miStats = new MenuItem(Translator.getMessage("label.stats"));
  protected MenuItem miPing = new MenuItem(Translator.getMessage("label.ping"));
  protected MenuItem miWhois = new MenuItem(Translator.getMessage("label.whois"));

  protected boolean _showingBigButtons = true;

  protected static final int PING = 0;
  protected static final int PRIVATE = 1;
  protected static final int EMOTE = 2;
  protected static final int PRIVATE_EMOTE = 3;
  protected static final int WHOIS = 4;

  // Netscape for Mac doesn't like my pop up dialog windows....
  public static boolean s_useDialogs = false;

  public ChatPanel(IChatGUIFactory factory, String room, String title,
                   IChatClientInputReceiver inputReceiver) {
    _title = title;
    _factory = factory;

    bgColor = (Color) factory.getAttribute("bgColor");
    if (bgColor == null) {
      bgColor = new Color(0x384CC7);
    }

    _room = room;
    _inputReceiver = inputReceiver;
    try {
      jbInit();
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }

  public ChatPanel(IChatGUIFactory factory, String room,
                   IChatClientInputReceiver inputReceiver) {
    this(factory, room, room, inputReceiver);
  }

  public String getName() {
    return _room;
  }

  public void requestFocus() {
    txtInput.requestFocus();
  }

  // receive messages from the ChatPanel
  public void inputEvent(String txt) {
    _inputReceiver.inputEvent(_room, txt);
  }

  public void displayPrivateMessage(String user, String message) {
    displayMessage(Translator.getMessage("private", user, message));
  }

  public void displayPrivateEmote(String user, String message) {
    displayMessage(Translator.getMessage("mesg", user, message));
  }

  public void displayMessage(String user, String message) {
    displayMessage(user + ": " + message);
  }

  public void displayMessage(String message) {
    txtMessages.appendText(message + "\n");
  }

  public void displayError(String error) {
//        _factory.playAudioClip("error.au");
    displayMessage(Translator.getMessage("error", error));
  }

  public void setUserList(String[] users) {
    synchronized (lstUsers) {
      lstUsers.clear();
      for (int i = 0; i < users.length; i++) {
        lstUsers.addItem(users[i]);
      }
      forceUserListRepaint();
    }
  }

  // Netscape-on-Windows problem workaround
  void forceUserListRepaint() {
    lstUsers.invalidate();
    lstUsers.getParent().validate();
    /*        lstUsers.validate();
            lstUsers.getParent().repaint();
            lstUsers.repaint(); */
  }

  public String[] getUserList() {
    synchronized (lstUsers) {
      String[] list = new String[lstUsers.countItems()];
      for (int i = 0; i < list.length; i++) {
        list[i] = lstUsers.getItem(i);
      }
      return list;
    }
  }

  public void userJoinedRoom(String user) {
    displayMessage(Translator.getMessage("joined", user));
    if (!listContains(user)) {
      lstUsers.addItem(user);
      forceUserListRepaint();
    }
  }

  private boolean listContains(String s) {
    int len = lstUsers.countItems();
    for (int i = 0; i < len; i++) {
      if (s.equals(lstUsers.getItem(i))) {
        return true;
      }
    }
    return false;
  }

  public void userPartedRoom(String user, boolean signoff) {
    if (signoff) {
      displayMessage(Translator.getMessage("part2", user));
    }
    else {
      displayMessage(Translator.getMessage("part1", user));
    }
    int len = lstUsers.countItems();
    for (int i = 0; i < len; i++) {
      if (user.equals(lstUsers.getItem(i))) {
        lstUsers.delItem(i);
        forceUserListRepaint();
        break;
      }
    }
  }

  protected Component createTextWidget() {
    txtMessages = new TextArea();
    txtMessages.setBackground(Color.white);
    txtMessages.setText("");
    txtMessages.setEditable(false);
    return txtMessages;
  }

  protected Component createTitleArea() {
    Label l = new Label(_title);
    l.setBackground(bgColor);
    l.setForeground(Color.white);
    l.setFont(new Font("Dialog", Font.BOLD, 14));
    return l;
  }

  private void jbInit() throws Exception {
    setLayout(gridbag);

    Component lblTitle = createTitleArea();
    if (lblTitle != null) {
      gridbag.setConstraints(lblTitle,
                             Constraints.create(0, 0, 2, 1, 1.0, 0,
                                                GridBagConstraints.WEST,
                                                GridBagConstraints.BOTH,
                                                new Insets(0, 0, 0, 0), 0, 0));
      add(lblTitle);
    }

    Component c = createButtonPanel();
    _buttonPanel = new Panel();
    _buttonPanel.setBackground(bgColor);
    GridBagLayout gb2 = new GridBagLayout();
    _buttonPanel.setLayout(gb2);
    gb2.setConstraints(c, Constraints.create(0, 0, 1, 1, 1.0, 1.0,
                                             GridBagConstraints.EAST,
                                             GridBagConstraints.NONE,
                                             new Insets(0, 0, 0, 0), 0, 0));
    _buttonPanel.add(c);
    gridbag.setConstraints(_buttonPanel,
                           Constraints.create(0, 1, 2, 1, 1.0, 0,
                                              GridBagConstraints.EAST,
                                              GridBagConstraints.HORIZONTAL,
                                              new Insets(0, 0, 0, 0), 0, 0));
    add(_buttonPanel);

    Component txtWidget = createTextWidget();
    gridbag.setConstraints(txtWidget,
                           Constraints.create(0, 2, 1, 1, 1.0, 1.0,
                                              GridBagConstraints.CENTER,
                                              GridBagConstraints.BOTH,
                                              new Insets(0, 0, 0, 0), 0, 0));
    add(txtWidget);

    lstUsers = new List();
    gridbag.setConstraints(lstUsers,
                           Constraints.create(1, 2, 1, 1, 0.0, 1.0,
                                              GridBagConstraints.CENTER,
                                              GridBagConstraints.VERTICAL,
                                              new Insets(0, 0, 0, 0), 0, 0));
    add(lstUsers);

    txtInput = new TextField();
    txtInput.setBackground(Color.white);
    gridbag.setConstraints(txtInput,
                           Constraints.create(0, 3, 2, 1, 1.0, 0.0,
                                              GridBagConstraints.WEST,
                                              GridBagConstraints.HORIZONTAL,
                                              new Insets(0, 0, 0, 0), 0, 4));
    add(txtInput);
  }

  protected Component createButton(String img, String name) {
    if (img != null) {
      try {
        Image i = _factory.getImage(img);
        if (i != null && i.getHeight(this) > 0 && i.getWidth(this) > 0) {
          return new ImageButton(i, name);
        }
      }
      catch (Exception e) {
        e.printStackTrace();
      }
    }
    Button b = new Button(name);
    b.setBackground(bgColor);
    b.setForeground(Color.yellow);
    return b;
  }

  protected GridBagConstraints createButtonConstraints(int number) {
    return Constraints.create(number, 0, 1, 1, 0.0, 0.0,
                              GridBagConstraints.EAST,
                              GridBagConstraints.NONE,
                              new Insets(2, 2, 2, 2), 0, 0);
  }

  protected Component createButtonPanel() {
    Panel p = new Panel(); // panel to contain the button
    p.setBackground(bgColor);
    GridBagLayout gb2 = new GridBagLayout();
    p.setLayout(gb2);

    int i = 0;

    btnPrivate = createButton("private.gif",
                              Translator.getMessage("label.private"));
    gb2.setConstraints(btnPrivate, createButtonConstraints(i++));
    p.add(btnPrivate);

    btnEmote = createButton("emote.gif", Translator.getMessage("label.emote"));
    gb2.setConstraints(btnEmote, createButtonConstraints(i++));
    p.add(btnEmote);

    /*        btnEmotePrivate = createButton("pemote.gif", Translator.getMessage("label.mesg"));
            gb2.setConstraints(btnEmotePrivate, createButtonConstraints(i++));
            p.add(btnEmotePrivate);
     */
    btnPing = createButton("ping.gif", Translator.getMessage("label.ping"));
    gb2.setConstraints(btnPing, createButtonConstraints(i++));
    p.add(btnPing);

    btnUserInfo = createButton("whois.gif", Translator.getMessage("label.whois"));
    gb2.setConstraints(btnUserInfo, createButtonConstraints(i++));
    p.add(btnUserInfo);

    btnStats = createButton("stats.gif", Translator.getMessage("label.stats"));
    gb2.setConstraints(btnStats, createButtonConstraints(i++));
    p.add(btnStats);

    /*        btnClose = createButton("blank.gif", Translator.getMessage("label.close"));
            gb2.setConstraints(btnClose, createButtonConstraints(i++));
            p.add(btnClose);
     */
    btnHelp = createButton("help.gif", Translator.getMessage("label.help"));
    gb2.setConstraints(btnHelp, createButtonConstraints(i++));
    p.add(btnHelp);

    return p;
  }

  public boolean action(Event e, Object o) {
    if (e.id == Event.ACTION_EVENT) {
      if (e.target == lstUsers) {
        _inputReceiver.userDoubleClick( (String) o);
        return true;
      }
      if (e.target == txtInput) {
        _inputReceiver.inputEvent(_room, (String) o);
        txtInput.setText("");
        return true;
      }
      if (e.target == btnStats || e.target == miStats) {
        _inputReceiver.inputEvent(_room, ICommands.STATS);
        return true;
      }
      if (e.target == btnClose) {
        _inputReceiver.inputEvent(_room, ICommands.PART_ROOM);
        return true;
      }
      if (e.target == btnPing || e.target == miPing) {
        if (!s_useDialogs) {
          String user = lstUsers.getSelectedItem();
          if (user != null) {
            _inputReceiver.inputEvent(_room, ICommands.PING + " " + user);
          }
          else {
            displayError(Translator.getMessage("error.ping"));
          }
        }
        else {
          IQuery q = _factory.createQuery(Translator.getMessage("ping"),
                                          Translator.getMessage("label.user") +
                                          ":",
                                          getUserList(), false, null);
          q.setCallbackParams(PING, this);
          String def = lstUsers.getSelectedItem();
          if (def != null) {
            q.setDefaultSelection(def);
          }
          q.show();
        }
        return true;
      }
      if (e.target == btnUserInfo || e.target == miWhois) {
        if (!s_useDialogs) {
          String user = lstUsers.getSelectedItem();
          if (user != null) {
            _inputReceiver.inputEvent(_room, ICommands.WHOIS + " " + user);
          }
          else {
            displayError(Translator.getMessage("error.whois"));
          }
        }
        else {
          IQuery q = _factory.createQuery(Translator.getMessage(
              "label.compose.whois"),
                                          Translator.getMessage("label.user") +
                                          ":",
                                          getUserList(), false, null);
          q.setCallbackParams(WHOIS, this);
          String def = lstUsers.getSelectedItem();
          if (def != null) {
            q.setDefaultSelection(def);
          }
          q.show();
        }
        return true;
      }
      if (e.target == btnPrivate || e.target == miPrivate) {
        if (!s_useDialogs) {
          String user = lstUsers.getSelectedItem();
          if (user != null) {
            String msg = txtInput.getText();
            if (msg != null && msg.length() > 0) {
              _inputReceiver.inputEvent(_room,
                                        ICommands.SAY_TO_USER + " " + user +
                                        " " + msg);
              txtInput.setText("");
            }
            else {
              displayError(Translator.getMessage("error.private2"));
            }
          }
          else {
            displayError(Translator.getMessage("error.private1"));
          }
        }
        else {
          IQuery q = _factory.createQuery(Translator.getMessage(
              "label.compose.private"),
                                          Translator.getMessage("label.to") +
                                          ":",
                                          getUserList(), true,
                                          Translator.getMessage("label.private") +
                                          ":");
          q.setCallbackParams(PRIVATE, this);
          String def = lstUsers.getSelectedItem();
          if (def != null) {
            q.setDefaultSelection(def);
          }
          q.show();
        }

        return true;
      }
      if (e.target == btnEmotePrivate || e.target == miEmotePrivate) {
        if (!s_useDialogs) {
          String user = lstUsers.getSelectedItem();
          if (user != null) {
            String msg = txtInput.getText();
            if (msg != null && msg.length() > 0) {
              _inputReceiver.inputEvent(_room,
                                        ICommands.EMOTE_TO_USER + " " + user +
                                        " " + msg);
              txtInput.setText("");
            }
            else {
              displayError(Translator.getMessage("error.mesg2"));
            }
          }
          else {
            displayError(Translator.getMessage("error.mesg1"));
          }
        }
        else {
          IQuery q = _factory.createQuery(Translator.getMessage(
              "label.compose.mesg"),
                                          Translator.getMessage("label.to" +
              ":"),
                                          getUserList(), true,
                                          Translator.getMessage("label.emote") +
                                          ":");
          q.setCallbackParams(PRIVATE_EMOTE, this);
          String def = lstUsers.getSelectedItem();
          if (def != null) {
            q.setDefaultSelection(def);
          }
          q.show();
        }

        return true;
      }
      if (e.target == btnEmote || e.target == miEmote) {
        if (!s_useDialogs) {
          String msg = txtInput.getText();
          if (msg != null && msg.length() > 0) {
            _inputReceiver.inputEvent(_room,
                                      ICommands.EMOTE_TO_ROOM + " " + msg);
            txtInput.setText("");
          }
          else {
            displayError(Translator.getMessage("error.emote"));
          }
        }
        else {
          IQuery q = _factory.createQuery(Translator.getMessage(
              "label.compose.emote"),
                                          null, null, true,
                                          Translator.getMessage("label.emote"));
          q.setCallbackParams(EMOTE, this);
          q.show();
        }
        return true;
      }
      if (e.target == btnHelp) {
        _inputReceiver.inputEvent(_room, ICommands.HELP);
      }
    }
    return super.action(e, o);
  }

  public void handleQuery(int id, IQuery q) {
    if (q.getCanceled()) {
      q.dispose();
      return;
    }

    String user;
    String msg;

    switch (id) {
      case PING:
        user = q.getSelection();
        _inputReceiver.inputEvent(_room, ICommands.PING + " " + user);
        break;
      case PRIVATE:
        user = q.getSelection();
        msg = q.getText();
        _inputReceiver.inputEvent(_room,
                                  ICommands.SAY_TO_USER + " " + user + " " +
                                  msg);
        txtInput.setText("");
        break;
      case PRIVATE_EMOTE:
        user = q.getSelection();
        msg = q.getText();
        _inputReceiver.inputEvent(_room,
                                  ICommands.EMOTE_TO_USER + " " + user + " " +
                                  msg);
        txtInput.setText("");
        break;
      case EMOTE:
        msg = q.getText();
        _inputReceiver.inputEvent(_room, ICommands.EMOTE_TO_ROOM + " " + msg);
        txtInput.setText("");
        break;
      case WHOIS:
        user = q.getSelection();
        _inputReceiver.inputEvent(_room, ICommands.WHOIS + " " + user);
        break;
    }
    q.dispose();
  }

  protected Menu createActionMenu() {
    Menu m = new Menu(Translator.getMessage("label.action"));
    m.add(miPrivate);
    m.add(miEmotePrivate);
    m.add(miEmote);
    m.add(miStats);
    m.add(miPing);
    m.add(miWhois);
    return m;
  }

  public void showBigButtons(boolean b) {
    if (b) {
      if (!_showingBigButtons) {
        add(_buttonPanel);
        gridbag.setConstraints(_buttonPanel,
                               Constraints.create(0, 1, 2, 1, 1.0, 0,
                                                  GridBagConstraints.EAST,
                                                  GridBagConstraints.HORIZONTAL,
                                                  new Insets(0, 0, 0, 0), 0, 0));
        _buttonPanel.invalidate();
        validate();
      }
      _showingBigButtons = true;
    }
    else {
      if (_showingBigButtons) {
        remove(_buttonPanel);
        validate();
        _showingBigButtons = false;
      }
    }
  }
}
```

hier mein code, der den button "kick" hinzufüen sollte :


```
package com.lyrisoft.chat.client.gui.awt102;

import com.lyrisoft.awt.ImageButton;
import com.lyrisoft.chat.ICommands;
import com.lyrisoft.chat.Translator;
import com.lyrisoft.chat.client.gui.*;
import java.awt.*;

// Referenced classes of package com.lyrisoft.chat.client.gui.awt102:
//            Constraints

public class ChatPanel extends Panel
    implements IChatRoom, IQueryCallback
{

    public ChatPanel(IChatGUIFactory ichatguifactory, String s, IChatClientInputReceiver ichatclientinputreceiver)
    {
        this(ichatguifactory, s, s, ichatclientinputreceiver);
    }

    public ChatPanel(IChatGUIFactory ichatguifactory, String s, String s1, IChatClientInputReceiver ichatclientinputreceiver)
    {
        gridbag = new GridBagLayout();
        miPrivate = new MenuItem(Translator.getMessage("label.private"));
        miEmotePrivate = new MenuItem(Translator.getMessage("label.mesg"));
        miEmote = new MenuItem(Translator.getMessage("label.emote"));
        miStats = new MenuItem(Translator.getMessage("label.stats"));
        miPing = new MenuItem(Translator.getMessage("label.ping"));
        miWhois = new MenuItem(Translator.getMessage("label.whois"));
		miKick = new MenuItem(Translator.getMessage("label.kick"));
        _showingBigButtons = true;
        _title = s1;
        _factory = ichatguifactory;
        bgColor = (Color)ichatguifactory.getAttribute("bgColor");
        if(bgColor == null)
            bgColor = new Color(0x384cc7);
        _room = s;
        _inputReceiver = ichatclientinputreceiver;
        try
        {
            jbInit();
        }
        catch(Exception exception)
        {
            exception.printStackTrace();
        }
    }

    public boolean action(Event event, Object obj)
    {
        if(event.id == 1001)
        {
            if(event.target == lstUsers)
            {
                _inputReceiver.userDoubleClick((String)obj);
                return true;
            }
            if(event.target == txtInput)
            {
                _inputReceiver.inputEvent(_room, (String)obj);
                txtInput.setText("");
                return true;
            }
            if(event.target == btnStats || event.target == miStats)
            {
                _inputReceiver.inputEvent(_room, "/stats");
                return true;
            }
            if(event.target == btnClose)
            {
                _inputReceiver.inputEvent(_room, "/leave");
                return true;
            }
            if(event.target == btnPing || event.target == miPing)
            {
                if(!s_useDialogs)
                {
                    String s = lstUsers.getSelectedItem();
                    if(s != null)
                        _inputReceiver.inputEvent(_room, "/ping " + s);
                    else
                        displayError(Translator.getMessage("error.ping"));
                } else
                {
                    IQuery iquery = _factory.createQuery(Translator.getMessage("ping"), Translator.getMessage("label.user") + ":", getUserList(), false, null);
                    iquery.setCallbackParams(0, this);
                    String s5 = lstUsers.getSelectedItem();
                    if(s5 != null)
                        iquery.setDefaultSelection(s5);
                    iquery.show();
                }
                return true;
            }
            if(event.target == btnUserInfo || event.target == miWhois)
            {
                if(!s_useDialogs)
                {
                    String s1 = lstUsers.getSelectedItem();
                    if(s1 != null)
                        _inputReceiver.inputEvent(_room, "/whois " + s1);
                    else
                        displayError(Translator.getMessage("error.whois"));
                } else
                
                {
                    IQuery iquery1 = _factory.createQuery(Translator.getMessage("label.compose.whois"), Translator.getMessage("label.user") + ":", getUserList(), false, null);
                    iquery1.setCallbackParams(4, this);
                    String s6 = lstUsers.getSelectedItem();
                    if(s6 != null)
                        iquery1.setDefaultSelection(s6);
                    iquery1.show();
                }
                return true;
                
            }
            
			if(event.target == btnKick || event.target == miKick)
			{
				if(!s_useDialogs)
				{
					String s1 = lstUsers.getSelectedItem();
					if(s1 != null)
						_inputReceiver.inputEvent(_room, "/kick " + s1);
					else
						displayError(Translator.getMessage("error.kick"));
				} else
                
				{
					IQuery iquery1 = _factory.createQuery(Translator.getMessage("label.compose.kick"), Translator.getMessage("label.user") + ":", getUserList(), false, null);
					iquery1.setCallbackParams(4, this);
					String s6 = lstUsers.getSelectedItem();
					if(s6 != null)
						iquery1.setDefaultSelection(s6);
					iquery1.show();
				}
				
				return true;
			}
            if(event.target == btnPrivate || event.target == miPrivate)
            {
                if(!s_useDialogs)
                {
                    String s2 = lstUsers.getSelectedItem();
                    if(s2 != null)
                    {
                        String s7 = txtInput.getText();
                        if(s7 != null && s7.length() > 0)
                        {
                            _inputReceiver.inputEvent(_room, "/msg " + s2 + " " + s7);
                            txtInput.setText("");
                        } else
                        {
                            displayError(Translator.getMessage("error.private2"));
                        }
                    } else
                    {
                        displayError(Translator.getMessage("error.private1"));
                    }
                } else
                {
                    IQuery iquery2 = _factory.createQuery(Translator.getMessage("label.compose.private"), Translator.getMessage("label.to") + ":", getUserList(), true, Translator.getMessage("label.private") + ":");
                    iquery2.setCallbackParams(1, this);
                    String s8 = lstUsers.getSelectedItem();
                    if(s8 != null)
                        iquery2.setDefaultSelection(s8);
                    iquery2.show();
                }
                return true;
            }
            if(event.target == btnEmotePrivate || event.target == miEmotePrivate)
            {
                if(!s_useDialogs)
                {
                    String s3 = lstUsers.getSelectedItem();
                    if(s3 != null)
                    {
                        String s9 = txtInput.getText();
                        if(s9 != null && s9.length() > 0)
                        {
                            _inputReceiver.inputEvent(_room, "/mesg " + s3 + " " + s9);
                            txtInput.setText("");
                        } else
                        {
                            displayError(Translator.getMessage("error.mesg2"));
                        }
                    } else
                    {
                        displayError(Translator.getMessage("error.mesg1"));
                    }
                } else
                {
                    IQuery iquery3 = _factory.createQuery(Translator.getMessage("label.compose.mesg"), Translator.getMessage("label.to:"), getUserList(), true, Translator.getMessage("label.emote") + ":");
                    iquery3.setCallbackParams(3, this);
                    String s10 = lstUsers.getSelectedItem();
                    if(s10 != null)
                        iquery3.setDefaultSelection(s10);
                    iquery3.show();
                }
                return true;
            }
            if(event.target == btnEmote || event.target == miEmote)
            {
                if(!s_useDialogs)
                {
                    String s4 = txtInput.getText();
                    if(s4 != null && s4.length() > 0)
                    {
                        _inputReceiver.inputEvent(_room, "/me " + s4);
                        txtInput.setText("");
                    } else
                    {
                        displayError(Translator.getMessage("error.emote"));
                    }
                } else
                {
                    IQuery iquery4 = _factory.createQuery(Translator.getMessage("label.compose.emote"), null, null, true, Translator.getMessage("label.emote"));
                    iquery4.setCallbackParams(2, this);
                    iquery4.show();
                }
                return true;
            }
            if(event.target == btnHelp)
                _inputReceiver.inputEvent(_room, "/help");
        }
        return super.action(event, obj);
    }

    protected Menu createActionMenu()
    {
        Menu menu = new Menu(Translator.getMessage("label.action"));
        menu.add(miPrivate);
        menu.add(miEmotePrivate);
        menu.add(miEmote);
        menu.add(miStats);
        menu.add(miPing);
        menu.add(miWhois);
        menu.add(miKick);
        return menu;
    }

    protected Component createButton(String s, String s1)
    {
        if(s != null)
            try
            {
                Image image = _factory.getImage(s);
                if(image != null && image.getHeight(this) > 0 && image.getWidth(this) > 0)
                    return new ImageButton(image, s1);
            }
            catch(Exception exception)
            {
                exception.printStackTrace();
            }
        Button button = new Button(s1);
        button.setBackground(bgColor);
        button.setForeground(Color.yellow);
        return button;
    }

    protected GridBagConstraints createButtonConstraints(int i)
    {
        return Constraints.create(i, 0, 1, 1, 0.0D, 0.0D, 13, 0, new Insets(2, 2, 2, 2), 0, 0);
    }

    protected Component createButtonPanel()
    {
        Panel panel = new Panel();
        panel.setBackground(bgColor);
        GridBagLayout gridbaglayout = new GridBagLayout();
        panel.setLayout(gridbaglayout);
        int i = 0;
        btnPrivate = createButton("private.gif", Translator.getMessage("label.private"));
        gridbaglayout.setConstraints(btnPrivate, createButtonConstraints(i++));
        panel.add(btnPrivate);
        btnEmote = createButton("emote.gif", Translator.getMessage("label.emote"));
        gridbaglayout.setConstraints(btnEmote, createButtonConstraints(i++));
        panel.add(btnEmote);
        btnPing = createButton("ping.gif", Translator.getMessage("label.ping"));
        gridbaglayout.setConstraints(btnPing, createButtonConstraints(i++));
        panel.add(btnPing);
        btnUserInfo = createButton("whois.gif", Translator.getMessage("label.whois"));
        gridbaglayout.setConstraints(btnUserInfo, createButtonConstraints(i++));
        panel.add(btnUserInfo);
        btnStats = createButton("stats.gif", Translator.getMessage("label.stats"));
        gridbaglayout.setConstraints(btnStats, createButtonConstraints(i++));
        panel.add(btnStats);
        btnHelp = createButton("help.gif", Translator.getMessage("label.help"));
        gridbaglayout.setConstraints(btnHelp, createButtonConstraints(i++));
        panel.add(btnHelp);
		btnPrivate = createButton("kick.gif", Translator.getMessage("label.kick"));
		gridbaglayout.setConstraints(btnKick, createButtonConstraints(i++));
		panel.add(btnKick);
        return panel;
    }

    protected Component createTextWidget()
    {
        txtMessages = new TextArea();
        txtMessages.setBackground(Color.decode("#FECB67"));
        txtMessages.setText(" ");
        txtMessages.setEditable(true);
        return txtMessages;
    }

    protected Component createTitleArea()
    {
        Label label = new Label(_title);
        label.setBackground(Color.decode("#EEBB66"));
        label.setForeground(Color.black);
        label.setFont(new Font("Dialog", 1, 17));
        return label;
    }

    public void displayError(String s)
    {
        displayMessage(Translator.getMessage("error", s));
    }

    public void displayMessage(String s)
    {
        txtMessages.appendText(s + "\n");
    }

    public void displayMessage(String s, String s1)
    {
        displayMessage("<" + s + "> " + s1);
    }

    public void displayPrivateEmote(String s, String s1)
    {
        displayMessage(Translator.getMessage("mesg", s, s1));
    }

    public void displayPrivateMessage(String s, String s1)
    {
        displayMessage(Translator.getMessage("private", s, s1));
    }

    void forceUserListRepaint()
    {
        lstUsers.invalidate();
        lstUsers.getParent().validate();
    }

    public String getName()
    {
        return _room;
    }

    public String[] getUserList()
    {
        synchronized(lstUsers)
        {
            String as1[] = new String[lstUsers.countItems()];
            for(int i = 0; i < as1.length; i++)
                as1[i] = lstUsers.getItem(i);

            String as[] = as1;
            return as;
        }
    }

    public void handleQuery(int i, IQuery iquery)
    {
        if(iquery.getCanceled())
        {
            iquery.dispose();
            return;
        }
        switch(i)
        {
        case 0: // '\0'
            String s = iquery.getSelection();
            _inputReceiver.inputEvent(_room, "/ping " + s);
            break;

        case 1: // '\001'
            String s1 = iquery.getSelection();
            String s4 = iquery.getText();
            _inputReceiver.inputEvent(_room, "/msg " + s1 + " " + s4);
            txtInput.setText("");
            break;

        case 3: // '\003'
            String s2 = iquery.getSelection();
            String s5 = iquery.getText();
            _inputReceiver.inputEvent(_room, "/mesg " + s2 + " " + s5);
            txtInput.setText("");
            break;

        case 2: // '\002'
            String s6 = iquery.getText();
            _inputReceiver.inputEvent(_room, "/me " + s6);
            txtInput.setText("");
            break;

        case 4: // '\004'
            String s3 = iquery.getSelection();
            _inputReceiver.inputEvent(_room, "/whois " + s3);
            break;

		case 5: // '\005'
				String s7 = iquery.getSelection();
				_inputReceiver.inputEvent(_room, "/kick " + s7);
			break;
       }
        iquery.dispose();
    }

    public void inputEvent(String s)
    {
        _inputReceiver.inputEvent(_room, s);
    }

    private void jbInit()
        throws Exception
    {
        setLayout(gridbag);
        Component component = createTitleArea();
        if(component != null)
        {
            gridbag.setConstraints(component, Constraints.create(0, 0, 2, 1, 1.0D, 0.0D, 17, 1, new Insets(0, 0, 0, 0), 0, 0));
            add(component);
        }
        Component component1 = createButtonPanel();
        _buttonPanel = new Panel();
        _buttonPanel.setBackground(bgColor);
        GridBagLayout gridbaglayout = new GridBagLayout();
        _buttonPanel.setLayout(gridbaglayout);
        gridbaglayout.setConstraints(component1, Constraints.create(0, 0, 1, 1, 1.0D, 1.0D, 13, 0, new Insets(0, 0, 0, 0), 0, 0));
        _buttonPanel.add(component1);
        gridbag.setConstraints(_buttonPanel, Constraints.create(0, 1, 2, 1, 1.0D, 0.0D, 13, 2, new Insets(0, 0, 0, 0), 0, 0));
        add(_buttonPanel);
        Component component2 = createTextWidget();
        gridbag.setConstraints(component2, Constraints.create(0, 2, 1, 1, 1.0D, 1.0D, 10, 1, new Insets(0, 0, 0, 0), 0, 0));
        add(component2);
        lstUsers = new List();
	lstUsers.setBackground(Color.decode("#FFCC66"));
        gridbag.setConstraints(lstUsers, Constraints.create(1, 2, 1, 1, 0.0D, 1.0D, 10, 3, new Insets(0, 0, 0, 0), 0, 0));
        add(lstUsers);
        txtInput = new TextField();
        txtInput.setBackground(Color.decode("#FFCC66"));
        gridbag.setConstraints(txtInput, Constraints.create(0, 3, 2, 1, 1.0D, 0.0D, 17, 2, new Insets(0, 0, 0, 0), 0, 4));
        add(txtInput);
    }

    private boolean listContains(String s)
    {
        int i = lstUsers.countItems();
        for(int j = 0; j < i; j++)
            if(s.equals(lstUsers.getItem(j)))
                return true;

        return false;
    }

    public void requestFocus()
    {
        txtInput.requestFocus();
    }

    public void setUserList(String as[])
    {
        synchronized(lstUsers)
        {
            lstUsers.clear();
            for(int i = 0; i < as.length; i++)
                lstUsers.addItem(as[i]);

            forceUserListRepaint();
        }
    }

    public void showBigButtons(boolean flag)
    {
        if(flag)
        {
            if(!_showingBigButtons)
            {
                add(_buttonPanel);
                gridbag.setConstraints(_buttonPanel, Constraints.create(0, 1, 2, 1, 1.0D, 0.0D, 13, 2, new Insets(0, 0, 0, 0), 0, 0));
                _buttonPanel.invalidate();
                validate();
            }
            _showingBigButtons = true;
        } else
        if(_showingBigButtons)
        {
            remove(_buttonPanel);
            validate();
            _showingBigButtons = false;
        }
    }

    public void userJoinedRoom(String s)
    {
        displayMessage(Translator.getMessage("joined", s));
        if(!listContains(s))
        {
            lstUsers.addItem(s);
            forceUserListRepaint();
        }
    }

    public void userPartedRoom(String s, boolean flag)
    {
        if(flag)
            displayMessage(Translator.getMessage("part2", s));
        else
            displayMessage(Translator.getMessage("part1", s));
        int i = lstUsers.countItems();
        for(int j = 0; j < i; j++)
        {
            if(!s.equals(lstUsers.getItem(j)))
                continue;
            lstUsers.delItem(j);
            forceUserListRepaint();
            break;
        }

    }

    protected Color bgColor;
    protected IChatClientInputReceiver _inputReceiver;
    protected String _room;
    protected String _title;
    protected IChatGUIFactory _factory;
    protected GridBagLayout gridbag;
    protected TextArea txtMessages;
    protected List lstUsers;
    protected TextField txtInput;
    protected Panel _buttonPanel;
    protected Component btnClose;
    protected Component btnEmote;
    protected Component btnPing;
    protected Component btnUserInfo;
    protected Component btnKick;
    protected Component btnEmotePrivate;
    protected Component btnPrivate;
    protected Component btnStats;
    protected Component btnHelp;
    protected MenuItem miPrivate;
    protected MenuItem miEmotePrivate;
    protected MenuItem miEmote;
    protected MenuItem miKick;
    protected MenuItem miStats;
    protected MenuItem miPing;
    protected MenuItem miWhois;
    protected boolean _showingBigButtons;
    protected static final int PING = 0;
    protected static final int PRIVATE = 1;
    protected static final int EMOTE = 2;
    protected static final int PRIVATE_EMOTE = 3;
    protected static final int WHOIS = 4;
    protected static final int KICK = 5;
    public static boolean s_useDialogs = false;

}
```

so angezzeigter fehler ist :

java.lang.NullPointerException
	at java.util.Hashtable.put(Hashtable.java:398)
	at java.awt.GridBagLayout.setConstraints(GridBagLayout.java:403)
	at com.lyrisoft.chat.client.gui.awt102.ChatPanel.createButtonPanel(ChatPanel.java:292)
	at com.lyrisoft.chat.client.gui.awt102.ChatPanel.jbInit(ChatPanel.java:426)
	at com.lyrisoft.chat.client.gui.awt102.ChatPanel.<init>(ChatPanel.java:42)
	at com.lyrisoft.chat.client.gui.awt102.EnhancedChatPanel.<init>(EnhancedChatPanel.java:27)
	at com.lyrisoft.chat.client.gui.awt102.ChatRoom.createPanel(ChatRoom.java:121)
	at com.lyrisoft.chat.client.gui.awt102.ChatRoom.<init>(ChatRoom.java:31)
	at com.lyrisoft.chat.client.gui.awt102.ChatRoom.<init>(ChatRoom.java:18)
	at com.lyrisoft.chat.client.gui.awt102.GUIFactory.createChatRoom(GUIFactory.java:35)
	at com.lyrisoft.chat.client.gui.ChatGUI.ackRoomJoined(ChatGUI.java:92)
	at com.lyrisoft.chat.client.Client.ackJoinRoom(Client.java:238)
	at com.lyrisoft.chat.server.local.command.AckJoinRoom.process(AckJoinRoom.java:15)
	at com.lyrisoft.chat.server.local.CommandProcessorLocal.process(CommandProcessorLocal.java:78)
	at com.lyrisoft.chat.server.local.ChatServerLocal.incomingMessage(ChatServerLocal.java:100)
	at com.lyrisoft.chat.server.local.ReaderThread.run(ReaderThread.java:39)

was mach ich falsch ?


----------



## KSG9|sebastian (6. Jun 2004)

java.lang.NullPointerException 

Das heist, dass du in ne Hashmap was einfügen willst, obwohl du sie noch net erzeugt hast..!


----------



## Sinnlos (6. Jun 2004)

Wie funktioniert so eine "hashmap" ?


----------



## Beni (6. Jun 2004)

Sinnlos hat gesagt.:
			
		

> Wie funktioniert so eine "hashmap" ?


Das ist für dieses Problem eigentlich egal, aber guck mal bei google vorbei, da findest du garantiert was.

Das Problem findest du eher hier:

```
at com.lyrisoft.chat.client.gui.awt102.ChatPanel.createButtonPanel(ChatPanel.java:292)
```
Guck mal nach, ob da komische Variablen rumschwirren...


----------



## Sinnlos (6. Jun 2004)

da war ein fehlerchen ...

```
btn>>>Kick<<< = createButton("kick.gif", Translator.getMessage("label.kick"));
```

Danke ) es funktioniert nun so wie es sollte ....
[/quote]


----------

