- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章java实现简单美女拼图游戏由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
拼图小游戏,学习阶段。很多不足,改进了一下 。
演示图片:
J_Puzzle.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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
|
import
java.awt.BorderLayout;
import
java.awt.Component;
import
java.awt.Container;
import
java.awt.Dimension;
import
java.awt.Font;
import
java.awt.Graphics;
import
java.awt.GridBagConstraints;
import
java.awt.GridBagLayout;
import
java.awt.Image;
import
java.awt.Point;
import
java.awt.event.ActionEvent;
import
java.awt.event.ActionListener;
import
java.awt.Toolkit;
import
java.io.File;
import
java.io.IOException;
import
java.util.Random;
import
javax.imageio.ImageIO;
import
javax.swing.ImageIcon;
import
javax.swing.JButton;
import
javax.swing.JFrame;
import
javax.swing.JMenu;
import
javax.swing.JMenuBar;
import
javax.swing.JMenuItem;
import
javax.swing.JOptionPane;
import
javax.swing.JPanel;
import
javax.swing.KeyStroke;
class
J_JPanel
extends
JPanel
{
/**
*
*/
private
static
final
long
serialVersionUID = 1L;
Image m_image;
int
showpicture=
0
;
@SuppressWarnings
(
"static-access"
)
public
J_JPanel()
throws
IOException
{ J_Puzzle a =
new
J_Puzzle();
if
(a.changetime==-
1
)
showpicture =
1
;
File f =
new
File(
"样图"
+showpicture+
".jpg"
);
m_image = ImageIO.read(f);
}
public
void
paintComponent(Graphics g)
{
g.drawImage(m_image,
0
,
0
,
360
,
360
,
this
);
}
}
public
class
J_Puzzle
extends
JFrame
implements
ActionListener
{
/**
*
*/
private
static
final
long
serialVersionUID = 1L;
int
i,j;
static
int
changetime =
0
;
Container c = getContentPane();
JButton b[] =
new
JButton[
16
];
ImageIcon ic[][] =
new
ImageIcon[
2
][
15
];
public
J_Puzzle()
throws
IOException
{
super
(
"拼图小游戏"
);
String pic_name[] =
new
String[
15
];
for
(i =
0
;i <
2
;i ++)
for
(j =
0
;j <
15
;j ++)
{
pic_name[j] = String.valueOf(j+
1
+i*
15
)+
".jpg"
;
ic[i][j] =
new
ImageIcon(pic_name[j]);
}
JMenuBar mBar =
new
JMenuBar();
setJMenuBar(mBar);
int
k =
0
;
JMenu []m = {
new
JMenu(
"菜单(M)"
),
new
JMenu(
"帮助(H)"
)};
char
mC[][] = {{
'M'
,
'H'
},{
'S'
,
'X'
,
'C'
,
'Z'
},{
'E'
,
'T'
}};
JMenuItem mItem[][] = {{
new
JMenuItem(
"开始(S)"
),
new
JMenuItem(
"重置(X)"
),
new
JMenuItem(
"背景更换(C)"
),
new
JMenuItem(
"退出(Z)"
)},{
new
JMenuItem(
"查看样图(E)"
),
new
JMenuItem(
"关于(T)"
)}};
for
(i =
0
;i <
2
;i ++)
{
mBar.add(m[i]);
m[i].setMnemonic(mC[
0
][i]);
if
(i==
0
)k =
0
;
else
k =
1
;
for
(j =
0
;j <
4
-i-k;j ++)
{
m[i].add(mItem[i][j]);
mItem[i][j].setMnemonic(mC[i+
1
][j]);
mItem[i][j].setAccelerator(KeyStroke.getKeyStroke(
"ctrl"
+mC[i+
1
][j]));
mItem[i][j].addActionListener(
new
ActionListener(){
public
void
actionPerformed(ActionEvent e)
{
JMenuItem mItem = (JMenuItem)e.getSource();
if
(mItem.getText().equalsIgnoreCase(
"重置(X)"
)||mItem.getText().equalsIgnoreCase(
"开始(S)"
))
{
int
location[][] = {{
17
,
13
},{
17
,
103
},{
17
,
193
},{
17
,
283
},{
107
,
13
},{
107
,
103
},{
107
,
193
},{
107
,
283
}
,{
197
,
13
},{
197
,
103
},{
197
,
193
},{
197
,
283
},{
287
,
13
},{
287
,
103
},{
287
,
193
},{
287
,
283
}};
int
rd_number[] =
new
int
[
16
];
rd_number = randomnumber();
for
(i =
1
;i <
16
;i ++)
b[i].setLocation(location[rd_number[i-
1
]-
1
][
0
],location[rd_number[i-
1
]-
1
][
1
]);
}
else
if
(mItem.getText().equalsIgnoreCase(
"背景更换(C)"
))
{
changetime++;
for
(i =
0
;i <
15
;i ++)
{
b[i+
1
].setIcon(
null
);
b[i+
1
].setIcon(ic[changetime][i]);
}
if
(changetime==
1
)
changetime = -
1
;
}
else
if
(mItem.getText().equalsIgnoreCase(
"退出(Z)"
))
{
int
a = JOptionPane.showConfirmDialog(
null
,
"您确定退出游戏?"
);
if
(a==
0
)
System.exit(
0
);
}
else
if
(mItem.getText().equalsIgnoreCase(
"查看样图(E)"
))
{
JFrame jj =
new
JFrame(
"样图"
);
jj.setSize(
360
,
360
);
jj.setLocation(Toolkit.getDefaultToolkit().getScreenSize().width/
3
-
360
,
Toolkit.getDefaultToolkit().getScreenSize().height/
4
);
jj.setVisible(
true
);
Container c1 = jj.getContentPane();
try
{
c1.add(
new
J_JPanel(),BorderLayout.CENTER);
}
catch
(IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
if
(mItem.getText().equalsIgnoreCase(
"关于(T)"
))
{
JOptionPane.showMessageDialog(
null
,
"简单拼图小游戏\n制作人:菜鸟"
);
}
}
});
}
}
m[
0
].insertSeparator(
1
);m[
1
].insertSeparator(
1
);
GridBagLayout gr =
new
GridBagLayout();
c.setLayout(gr);
int
gx[] = {
0
,
1
,
2
,
3
};
int
gy[] = {
0
,
1
,
2
,
3
};
int
k1;
Dimension d =
new
Dimension(
90
,
90
);
String s_number;
GridBagConstraints gc =
new
GridBagConstraints();
for
(i =
1
;i <
5
;i ++)
{
if
(i==
4
)k1=
4
;
else
k1=
5
;
for
(j =
1
;j < k1;j ++)
{
gc.gridx = gx[j-
1
];
gc.gridy = gy[i-
1
];
gc.fill = GridBagConstraints.NONE;
s_number = String.valueOf(j+(i-
1
)*
4
);
b[j+(i-
1
)*
4
] =
new
JButton(s_number,ic[
0
][j+(i-
1
)*
4
-
1
]);
b[j+(i-
1
)*
4
].setPreferredSize(d);
b[j+(i-
1
)*
4
].setFont(
new
Font(
"宋体"
,Font.PLAIN,
0
));
gr.setConstraints(b[j+(i-
1
)*
4
],gc);
c.add(b[j+(i-
1
)*
4
]);
}
}
for
(i =
1
;i <
16
;i ++)
b[i].addActionListener(
this
);
}
public
void
actionPerformed(ActionEvent e)
{
int
j;
JButton b = (JButton)e.getSource();
Point p = b.getLocation();
Point p1 =
null
;
for
(j = -
1
;j <
2
;j ++)
{
if
(p.y+j*
90
>
283
||p.y+j*
90
<
13
)
continue
;
else
{
Component a = c.getComponentAt(p.x, p.y+j*
90
);
if
(a.getHeight()!=
90
)
p1 =
new
Point(p.x,p.y+j*
90
);
}
}
for
(j = -
1
;j <
2
;j ++)
{
if
(p.x+j*
90
>
287
||p.x+j*
90
<
17
)
continue
;
else
{
Component a = c.getComponentAt(p.x+j*
90
, p.y);
if
(a.getHeight()!=
90
)
p1 =
new
Point(p.x+j*
90
,p.y);
}
}
if
(p1!=
null
)
b.setLocation(p1.x, p1.y);
if
(check()==
true
)
JOptionPane.showMessageDialog(
null
,
"恭喜您成功了"
);
}
/*产生随机数*/
public int[] randomnumber()
{
Random rd = new Random();
int n[] = new int[15];
for(int i = 0 ;i < 15;i ++)
{
int temp = rd.nextInt(15)+1;
n[i] = temp;
for(int j = 0;j < i;j ++)
if(n[j]==temp)
{
i--;
break;
}
}
return n;
}
/*判断是否排序成功*/
public
boolean
check()
{
Point location[] =
new
Point[
16
];
boolean
bo =
false
;
int
count=
0
;
for
(
int
i =
0
;i <
4
;i ++)
for
(
int
j =
0
;j <
4
;j ++)
location[i*
4
+j] =
new
Point(
17
+j*
90
,
13
+i*
90
);
for
(
int
i =
0
;i <
15
;i ++)
{
if
(b[i+
1
].getLocation().x==location[i].x&&b[i+
1
].getLocation().y==location[i].y)
count++;
if
(count==
15
)
bo=
true
;
}
return
bo;
}
public
static
void
main(String args[])
throws
IOException
{
J_Puzzle app =
new
J_Puzzle();
app.setDefaultCloseOperation(EXIT_ON_CLOSE);
app.setLocation(Toolkit.getDefaultToolkit().getScreenSize().width/
3
, Toolkit.getDefaultToolkit().getScreenSize().height/
4
);
app.setSize(
400
,
440
);
app.setVisible(
true
);
app.setResizable(
false
);
}
}
|
以上所述就是本文的全部内容了,希望对大家学习java能够有所帮助.
最后此篇关于java实现简单美女拼图游戏的文章就讲到这里了,如果你想了解更多关于java实现简单美女拼图游戏的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
我在某处遇到了以下难题 #include int main() { { /*Fill in something here to make this code compile
我正在尝试为 iOS 创建一个拼图游戏应用程序。从我在互联网上的搜索来看,确实没有任何关于这个主题的教程。有谁知道任何人都知道的好教程或游戏教程的链接?谢谢。顺便说一下,iOS4 将不胜感激。 最佳答
如果必须使用 Promises,您会如何编写以下代码? 这个想法是,“私有(private)”方法 p1 调用一个执行异步操作的函数,然后,当异步调用的结果准备就绪时,控制权将传递给“私有(priva
下面是其中一个 facebook 谜题:我无法理解如何进行此操作。 你有 C 个容器、B 个黑球和无限数量的白球。您希望以一种方式在容器之间分配球,即每个容器至少包含一个球,并且选择白球的概率大于或等
有 5 位成员围坐在一张 table 旁。关键值是坐在 table 周围的成员数量。所以现在关键值将是 5。一个恐怖分子告诉成员,因为你们是 5 个成员,所以我将从第一个成员开始数,数到 5 的人将被
你能在不抛出错误的情况下解决这个问题吗?答案是单线。这是来自一个死的职位发布,在回复中要求回答。我认为这是剔除受访者的聪明方法,但我似乎无法在不出错的情况下回答它。 显而易见的解决方案: f.moo(
此源输出 G'Day Mate. 这是怎么发生的? public static void main(String args[]) { System.out.println("Hello Wor
我正在 android 中开发一个 slider 拼图,它有一个图像被分解成小图像,我们需要对这些 fragment 进行排序以形成正确的图像。我使用了一个 3x3 的 GridView ,其中包含
我遇到了以下难题,无法在 Picat 中制定解决方案: You will generate 5-digit numbers, where each digit is in 1..5 and diffe
我是 Javascript 新手,并且正在努力解决 CodeWars 中的这个难题。 约翰想用壁纸装饰房间。房间的尺寸为:宽度(w)、高度(h)、长度(l)。一卷壁纸的尺寸为 52cm 宽,10m 长
我对 Java 还很陌生,尝试过 Best Before puzzle from Spotify昨天。当我发送它时,我收到“错误答案”错误。检查其他解决方案没有帮助,我无法弄清楚哪个输入给出了错误的答
我正在尝试恢复我拥有的一些旧代码,这是一个拼图游戏。它从文件夹中加载图像(拼图),将它们随机放置在页面周围,然后拖放到板上。这曾经有效,但当我今天尝试使用它时,它只是抛出错误(见下文)。 HTML:
这对你们来说可能是个愚蠢的问题。它是关于 CSS Sprites 的。我有一个包含 4 个菜单的导航,例如 .. HOME COMPANY SERVICES SUPPORT 尽管我使用了一个 css
我需要创建一个标题,可以根据正在构建的页面轻松添加或删除部分,但我在处理其中一部分时遇到了问题。 我有一个标题,看起来像这样将所有组件放在 如果导航被移除,它应该看起来像这样(垂直居中) 我的问题是如
我在 JS 中构建了一个 15 拼图,但我的随机拼图生成正在创建无法解决的拼图实例。这可能是因为我不是计算机科学专业的负责人,但我不确定如何计算代码排列中的反转次数。我想知道如何编写我的代码,以便我可
我正在寻找 8 Puzzle graphs tree generator,最好是 (php+) html+css+javascript。我需要的是类似 3 2 1 6 8 7 5 4 会生成所有可
我住在德国,在 Android Market 上发布“Last Call Widget”。随着时间的推移,我一直在稳步改进它,但一组用户仍然提示它无法在他们的设备上运行。 我的小部件监听“androi
这个问题不太可能帮助任何 future 的访问者;它只与一个小的地理区域、一个特定的时间点或一个非常狭窄的情况相关,这些情况并不普遍适用于互联网的全局受众。为了帮助使这个问题更广泛地适用,visit
我正在尝试制作一个看起来像这样的拼图游戏。我试过的看起来像这样。 https://jsfiddle.net/uccfb46z/ 现在如果我想改变碎片的形状我需要修改这部分 - outside: fu
首先,让我为缺少 SSCCE 表示歉意。我在这方面真的没有足够的专业知识来弄清楚什么是相关的,什么不是。 简而言之,问题是在两台运行相同分辨率 (1366x768) 的不同计算机上,我女朋友的 tum
我是一名优秀的程序员,十分优秀!