This repository was archived by the owner on Jul 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTakeinputfor2users.java
More file actions
54 lines (50 loc) · 1.71 KB
/
Takeinputfor2users.java
File metadata and controls
54 lines (50 loc) · 1.71 KB
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
package com.company;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Takeinputfor2users {
private JFrame frame = new JFrame();
private JPanel panel = new JPanel();
private JLabel label1 = new JLabel();
private JLabel label2 = new JLabel();
private JTextField name1 = new JTextField(20);
private JTextField name2 = new JTextField(20);
private JButton button = new JButton("Submit");
GameBoardforuservsuser game;
String s,s1;
Takeinputfor2users()
{
label1.setText("Name 1 : ");
panel.setLayout(new BoxLayout(panel,BoxLayout.Y_AXIS));
panel.setBackground(Color.WHITE);
panel.add(label1);
panel.add(name1);
label2.setText("Name 2 : ");
panel.add(label2);
panel.add(name2);
panel.add(button);
frame.add(panel);
frame.pack();
frame.setBackground(Color.DARK_GRAY);
frame.setVisible(true);
init();
}
public void init() {
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String s = name1.getText();
String s1 = name2.getText();
if(s.isEmpty()||s1.isEmpty())
{
JOptionPane.showMessageDialog(null,"Name is Empty");
Takeinputfor2users takeinputgui = new Takeinputfor2users();
}
frame.dispose();
if((!s.isEmpty())&&(!s1.isEmpty()))
game = new GameBoardforuservsuser(s,s1);
}
});
}
}