-
Notifications
You must be signed in to change notification settings - Fork 0
/
entryPoint.java
207 lines (188 loc) · 6.6 KB
/
entryPoint.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import javax.imageio.ImageIO;
import javax.swing.UIManager.*;
class entryPoint implements Runnable
{
public static void test()
{
}
public static void main(String args[])
{
SwingUtilities.invokeLater(new entryPoint());
}
public static void main()
{
entryPoint.main(new String[]{});
}
public static void close(boolean ask)
{
if(ask==true)
{
modalYesNo ex=new modalYesNo("Do you really want to leave the game?","Continue game","Leave game",gui.cover);
int result=ex.run();
System.out.println(result);
if(result==modalYesNo.NO)
{
return;
}
}
//these throw exception when game hasnt started and tried to exit
FileHandler.exitTask();
if(game.getHerePlayer()!=null)
game.getHerePlayer().destroy();
if(game.getOppositePlayer()!=null)
game.getOppositePlayer().destroy();
if(game.getChessBoard()!=null)
game.getChessBoard().removemouselisteners();
Environment.log("almost about to end");
Thread t=new utility.fadeout(gui.frame,true,true);
t.start();
}
static JLabel p=new JLabel("Choose an option");
static JTextField num=new JTextField();
static String gametype="";
static JFrame frame;
public void run()
{
//System.out.println(.getClassName());
try
{
//UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
game.icon=ImageIO.read(game.class.getResourceAsStream("/imgz/icon.png"));
}
catch (Exception cnfe)
{
cnfe.printStackTrace();
}
try {
for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
UIManager.setLookAndFeel(info.getClassName());
//UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
break;
}
}
} catch (Exception e) {
// If Nimbus is not available, you can set the GUI to another look and feel.
}
frame=new JFrame("Login panel");
frame.setIconImage(game.icon);
frame.setUndecorated(true);
//frame.setLayout(null);
frame.setSize(400,400);
frame.setShape(new RoundRectangle2D.Double(0,0,frame.getWidth(),frame.getHeight(),15,15));
frame.setLocationRelativeTo(null);
new Thread(new colortrans()).start();
entryPane ep=new entryPane(frame);
ep.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE,0),"close");//0 specified no modifier: see https://docs.oracle.com/javase/7/docs/api/javax/swing/KeyStroke.html
ep.getActionMap().put("close",new AbstractAction()
{
public void actionPerformed(ActionEvent ae)
{
close(false);
Thread t=new utility.fadeout(frame,true,true);
t.start();
}
});
frame.add(ep);
//frame.setOpacity(0);
frame.setVisible(true);
//new Thread(new utility.fadein(frame)).start();
}
static entryPane t;
static class entryPane extends JTabbedPane
{
public entryPane(JFrame container)
{
add(Human.getEntryMenu(container),"2 player");
add(AI.getEntryMenu(container),"AI");
add(Online.getHostEntryMenu(container),"Host a game");
add(Online.getClientEntryMenu(container),"Join a game");
addTab("Others",SavedGameReader.getEntryMenu(container));//addTab(string,icon,component) for adding icon to tabs
add(new utility.GradientPanel(),"Exit");
setFocusable(false);
t=this;
addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent me)
{
if(t.getSelectedIndex()==5)
{
close(false);
Thread t=new utility.fadeout(frame,true,true);
t.start();
}
offs=new Point(me.getX(),me.getY());
}
});
addMouseMotionListener(new MouseAdapter()
{
public void mouseDragged(MouseEvent me)
{
Point now=container.getLocation();
container.setLocation(new Point(now.x+me.getX()-offs.x,now.y+me.getY()-offs.y));
}
});
new javax.swing.Timer(40,new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
repaint();
}
}).start();
}
@Override
public void paintComponent(Graphics g)
{
super.paintComponent(g);
}
}
public static void disableAllOptions()
{
for(int i=0;i<t.getTabCount()-1;i++)
{
if(i!=t.getSelectedIndex() )
t.setEnabledAt(i,false);
}
}
static Point offs;
static class loadLabel extends JLabel
{
double t=0;
utility.rgbButton b;
public loadLabel(utility.rgbButton b)
{
super(b.getText(),JLabel.CENTER);
this.b=b;
this.setBounds(b.getBounds());
this.setFont(b.getFont());
new javax.swing.Timer(16,new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
t+=.02;
repaint();
}
}).start();
addMouseListener(new MouseAdapter()
{
public void mouseClicked(MouseEvent e)
{
System.out.println(t);
}
});
}
public void paintComponent(Graphics gg)
{
super.paintComponent(gg);
Graphics2D g=(Graphics2D)gg;
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
g.setColor(new Color((int)(Math.sin(t)*120+128),(int)(Math.cos(t)*120+128),(int)(Math.sin(t+1.3)*120+128)));
g.drawString("🙄",-25+(int)((getWidth()/2)+( ((getWidth()/2)-50)*Math.sin(t))),getHeight()-5);
}
}
static String ip=null;
}