-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainView.java
234 lines (161 loc) · 5.97 KB
/
MainView.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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
import java.awt.*;
import static java.awt.Frame.MAXIMIZED_BOTH;
import java.awt.event.*;
import java.awt.event.MouseMotionListener;
import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import javafx.scene.Scene;
import javafx.scene.web.WebView;
import javax.swing.*;
public class MainView extends SlidingPanel1 implements Runnable,MouseMotionListener,ActionListener
{
JFrame frame;
JButton b1,b2,b3;
JPanel panel1,panel2,panel3;
JButton btn1;
int X = 20;
int Y = 50;
boolean x=false;
boolean y=false;
int p1x = 1364;
int p1y = 0;
int p2x = -798;
int p2y = 0;
int p3x = 0;
int p3y = -768;
public static void main(String[] args)
{
MainView example = new MainView();
SwingUtilities.invokeLater(example);
}
public void run()
{
frame = new JFrame("My JFrame Example");
JButton btn = new JButton("Settings");
btn.setBounds(100, 200, 120, 40);
panel1 = new JPanel();
panel1.setLayout(null);
panel1.setBackground(Color.YELLOW);
panel1.add(btn);
panel1.setBounds(p3x, p3y, 1350, 770);
b1 = new JButton();
b1.setBounds(650, 1, 15, 5);
b1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
((JButton) e.getSource()).setEnabled(false);
new Timer(1, new ActionListener(){
public void actionPerformed(ActionEvent e) {
p3y = panel1.getY()+1;
panel1.setLocation(p3x, p3y);
if (p3y ==-100)
{
((Timer) e.getSource()).stop();
System.out.println("Timer stopped");
}
}
}).start();
}
});
panel2 = new JPanel();
panel2.setLayout(null);
panel2.setBackground(Color.red);
panel2.setBounds(p2x, p2y, 800, 720);
b2 = new JButton();
b2.setBounds(0, 350, 15, 5);
b2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
((JButton) e.getSource()).setEnabled(false);
new Timer(1, new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
p2x = panel2.getX() + 1;
panel2.setLocation(p2x, p2y);
//if (panel2.getX() + panel2.getWidth() == 0)
if ( p2x == -100 && p2y == 0)
{
((Timer) e.getSource()).stop();
System.out.println("Timer stopped");
}
}
}).start();
}
});
panel3 = new JPanel();
panel3.setLayout(null);
panel3.setBackground(Color.blue);
panel3.setBounds(p1x, p1y, 800, 720);
b3 = new JButton();
b3.setBounds(1350, 350, 15, 5);
b3.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
((JButton) e.getSource()).setEnabled(false);
new Timer(1, new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
p2x = panel3.getX() - 1;
panel3.setLocation(p2x, p2y);
//if (panel2.getX() + panel2.getWidth() == 0)
if ( p2x == 100 && p2y == 0)
{
((Timer) e.getSource()).stop();
System.out.println("Timer stopped");
}
}
}).start();
}
});
ImageIcon ic1 = new ImageIcon("E:\\ci.png");
//Button One
btn1 =new JButton(ic1);
btn1.setBounds(X,Y,100,50);
btn1.setOpaque(false);
btn1.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
btn1.setContentAreaFilled(false);
btn1.setBorderPainted(false);
btn1.setVisible(true);
btn1.setBorder(BorderFactory.createEmptyBorder(0,0,0,0));
btn1.addMouseMotionListener(this);
btn1.addActionListener(this);
frame.add(b1);
frame.add(b2);
frame.add(b3);
frame.add(btn1);
frame.add(panel1);
frame.add(panel2);
frame.add(panel3);
JFXPanel jfxPanel = new JFXPanel();
frame.add(jfxPanel);
Platform.runLater(() -> {
WebView webView = new WebView();
jfxPanel.setScene(new Scene(webView));
webView.getEngine().load("http://www.google.com/");
});
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.setExtendedState(MAXIMIZED_BOTH);
frame.pack();
frame.setVisible(true);
}
public void mouseDragged(MouseEvent e) {
X = e.getX()+X;
Y = e.getY()+Y;
btn1.setBounds(X, Y, 100, 50);
x=true;
}
@Override
public void mouseMoved(MouseEvent e) {
btn1.setLocation(300, 420);
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==btn1 && x==true){
btn1.setLocation(300, 420);
}
}
}