]> code.citadel.org Git - citadel.git/blob - shaggy/enterRoomWindow.java
* fix_scrollbar_bug is now a class instead of an id. Fixes validator warnings.
[citadel.git] / shaggy / enterRoomWindow.java
1 import javax.swing.*;
2 import java.awt.*;
3 import java.awt.event.*;
4
5 public class enterRoomWindow extends JFrame {
6     JTextField  room, pass;
7
8     public enterRoomWindow() {
9         this( null );
10     }
11
12     public enterRoomWindow( String def ) {
13         Container       c = getContentPane();
14         pass = null;
15
16         addWindowListener( new WindowAdapter() {
17             public void windowClosing( WindowEvent e ) {
18                 closeWin();
19             } } );
20
21         c.setLayout( new BorderLayout() );
22
23         PairPanel       pp = new PairPanel();
24         pp.addLeft( new JLabel( "Name:" ) );
25         pp.addRight( room = new JTextField(10) );
26         room.addActionListener( new ActionListener() {
27             public void actionPerformed( ActionEvent e ) {
28                 if( pass != null )
29                     pass.requestFocus();
30                 else
31                     enterRoom();
32             } } );
33
34         if( def != null ) {
35             room.setText( def );
36
37             pp.addLeft( new JLabel( "Password: " ) );
38             pp.addRight( pass = new JPasswordField(10) );
39
40             pass.addActionListener( new ActionListener() {
41                 public void actionPerformed( ActionEvent e ) {
42                     enterRoom();
43                 } } );
44         }
45
46         c.add( "Center", pp );
47
48         JPanel  p = new JPanel();
49         JButton b = new JButton( "Go" );
50         p.add( b );
51
52         b.addActionListener( new ActionListener() {
53             public void actionPerformed( ActionEvent e ) {
54                 enterRoom();
55             } } );
56
57         p.add( b = new JButton( "Cancel" ) );
58         b.addActionListener( new ActionListener() {
59             public void actionPerformed( ActionEvent e ) {
60                 closeWin();
61             } } );
62
63         c.add( "South", p );
64
65         citadel.me.registerWindow( this );
66         pack();
67         show();
68     }
69
70     public void closeWin() {
71         citadel.me.removeWindow( this );
72         dispose();
73     }
74
75     public void enterRoom() {
76         String  r, p=null;
77         r = room.getText();
78         if( pass != null ) p = pass.getText();
79         citadel.me.enterRoom( r, p );
80         closeWin();
81     }
82 }