-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCreateUser.java
71 lines (59 loc) · 2.51 KB
/
CreateUser.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class CreateUser extends JFrame implements ActionListener {
private JTextField nameField;
private JButton createButton;
private JButton chooseColorButton; // Button to open the color picker
private Color selectedColor; // Store the selected theme color
public CreateUser() {
setTitle("Create New User");
setSize(400, 200);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
panel.setLayout(new GridLayout(3, 2, 10, 10));
JLabel nameLabel = new JLabel("Enter Name:");
nameField = new JTextField(15);
createButton = new JButton("Create User");
chooseColorButton = new JButton("Choose Theme Color");
getRootPane().setDefaultButton(createButton);
createButton.addActionListener(this);
chooseColorButton.addActionListener(this);
panel.add(nameLabel);
panel.add(nameField);
panel.add(new JLabel()); // Empty label for spacing
panel.add(chooseColorButton);
panel.add(new JLabel()); // Empty label for spacing
panel.add(createButton);
add(panel);
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == createButton) {
String username = nameField.getText().trim();
if (!username.isEmpty()) {
// Create a new client2 object with the entered username and selected color
SwingUtilities.invokeLater(() -> {
Client client = new Client("127.0.0.1", 6001, username, selectedColor);
client.connectToServer();
});
// Clear the textField after creating the user
nameField.setText("");
}
} else if (e.getSource() == chooseColorButton) {
// Open the color picker dialog
selectedColor = JColorChooser.showDialog(this, "Choose Theme Color", selectedColor);
if (selectedColor != null) {
// Set the background color of the frame to the selected color
getContentPane().setBackground(selectedColor);
}
}
}
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
CreateUser createUser = new CreateUser();
createUser.setVisible(true);
});
}
}