Пример #1
0
  public ChatWindowTab(String title, JTabbedPane parent, ChatWindow owner) {
    // JPanel für Tabbeschriftung erzeugen und durchsichtig machen:
    this.parent = parent;
    this.owner = owner;
    ((FlowLayout) this.getLayout()).setHgap(5);
    this.setOpaque(false);

    // TitelLabel für Tabbeschriftung erzeugen:
    lblTitle = new JLabel(title);
    // MouseListener zu JLabel (lblTitle) hinzufügen:
    lblTitle.addMouseListener(this);

    // ImageIcon für SchließenLabel erstellen:
    tabCloseImgIcon = new ImageIcon(getClass().getResource("TabCloseBlack.png"));
    // SchließenLabel für Tabbeschriftung erzeugen und gestalten:
    lblClose = new JLabel(tabCloseImgIcon);
    // Observer für das Image auf das lblClose setzen:
    tabCloseImgIcon.setImageObserver(lblClose);
    // MouseListener für Schließenlabel (lblClose) hinzufügen:
    lblClose.addMouseListener(this);

    lblIcon = new JLabel();
    if (owner.isPrivate()) {
      lblIcon.setIcon(new ImageIcon(getClass().getResource("private.png")));
    } else {
      lblIcon.setIcon(new ImageIcon(getClass().getResource("gruppe.png")));
    }

    // TitelLabel (lblTitle) + SchließenLabel (btnClose) zum Tab (pnlTab) hinzufügen:
    this.add(lblIcon);
    this.add(lblTitle);
    this.add(lblClose);

    // den neuen Tab an die Stelle von index setzen:
  }
Пример #2
0
 private void connectToServer() {
   try {
     socket = new Socket(serverIP, port);
     out = new PrintWriter(socket.getOutputStream(), true);
     in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
   } catch (IOException ioe) {
     cw.receiveMessage("Error: Could not connect to server");
   }
 }