forked from Metropolice23/Reversi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Opengame.java
121 lines (115 loc) · 2.76 KB
/
Opengame.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Opengame extends JFrame
{
private Mybutton exit;
private Mybutton start;
private JTextField player1;
private JTextField player2;
private String playerNum;
private String clock;
public Opengame(String playerNum,String clock)
{
setSize(640,363);
setLocation(400,200);
setUndecorated(true);
JPanel p=new JPanel();
p.setLayout(null);
this.clock=clock;
this.playerNum=playerNum;
MyActionListener al=new MyActionListener();
exit=new Mybutton(165,48,24,293);
exit.addActionListener(al);
start=new Mybutton(290,60,185,210);
start.addActionListener(al);
player1=new JTextField();
//player1.addActionListener(al);
player1.setSize(400,35);
player1.setLocation(45,50);
player1.setHorizontalAlignment(JTextField.RIGHT);
player1.setFont(new Font("Ariel",Font.BOLD,14));
player2=new JTextField(playerNum);
//player2.addActionListener(al);
player2.setSize(400,35);
player2.setLocation(45,128);
player2.setHorizontalAlignment(JTextField.RIGHT);
player2.setFont(new Font("Ariel",Font.BOLD,14));
if(playerNum.equals("îçùá"))
{ player2.setForeground(Color.white);
player2.setEnabled(false);
// player2.setForeground(Color.BLACK);
}
p.add(exit);
p.add(start);
p.add(player1);
p.add(player2);
//JLabel =new JLabel (SwingConstants.RIGHT);
JLabel opengame=new JLabel(new ImageIcon("opengame.png"));
opengame.setSize(640,363);
p.add(opengame);
add(p);
setVisible(true);
}
public boolean checkName(String name)
{
int len=name.length();
int a=0;
if(name.equals("îçùá"))
{return false;}
if((len<2)||(len>15))
{return false;}
for (int i=0;i<len;i++)
{
char ch=name.charAt(i);
if ((ch<'à'||ch>'ú')&&(ch!=' '))
{return false;}
if ((ch>='à')&&(ch<='ú'))
{a++;}
}
if (a<2)
{return false;}
return true;
}
public class MyActionListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
JButton b=(JButton)e.getSource();
if(b==exit)
{
new Mainframe();
dispose();
}
if(b==start)
{
String name1=player1.getText();
String name2=player2.getText();
if (!playerNum.equals("îçùá"))
{
if (checkName(name1)&&checkName(name2)&&(!name1.equals(name2)))
{
new Board(name1,name2,clock);
dispose();
}
else
{
JOptionPane.showMessageDialog(null,"îäùí çééá ìäëéì áéï 2 ì15- úååéí, äùí çééá ìäéåú áòì àåúéåú òáøéåú åøååçéí áìáã (äùí àéðå éëåì ìäéåú äîéìä 'îçùá')","ùâéàä- ùí ìà çå÷é ",JOptionPane.DEFAULT_OPTION);
}
}
if (playerNum.equals("îçùá"))
{
if (checkName(name1))
{
new Board(name1,name2,clock);
dispose();
}
else
{
JOptionPane.showMessageDialog(null,"îäùí çééá ìäëéì áéï 2 ì15- úååéí, äùí çééá ìäéåú áòì àåúéåú òáøéåú åøååçéí áìáã (äùí àéðå éëåì ìäéåú äîéìä 'îçùá')","ùâéàä- ùí ìà çå÷é ",JOptionPane.DEFAULT_OPTION);
}
}
}
}
}
}