parent
ca48be9db5
commit
d322a74c3d
@ -0,0 +1,91 @@
|
||||
package keshe;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ItemEvent;
|
||||
import java.awt.event.ItemListener;
|
||||
|
||||
public class StartFrame extends JFrame {
|
||||
JButton btn1 = new JButton("开始游戏");//“开始游戏”按钮
|
||||
JLabel label1 = new JLabel("选择难度:");//“选择难度”按钮
|
||||
JButton btn2 =new JButton("闯关模式");//“闯关模式”按钮
|
||||
String[] a = {"难度1","难度2","难度3"};//下拉列表项
|
||||
JComboBox cbb1=new JComboBox(a);//创建下拉列表,并添加列表项
|
||||
public int level;//难度标识
|
||||
static int ch;//判断是否为闯关模式标识
|
||||
JPanel root;//“开始界面”面板
|
||||
StartFrame(){
|
||||
//设置标题
|
||||
setTitle("开始界面");
|
||||
// 设置窗体位置和大小
|
||||
setBounds(100, 100, 515, 520);
|
||||
// 设置窗体不能改变大小
|
||||
setResizable(false);
|
||||
// 设置窗体居中显示
|
||||
setLocationRelativeTo(null);
|
||||
// 设置窗体关闭即退出
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
//创建面板并添加,布局为空
|
||||
root=new JPanel();
|
||||
setContentPane(root);
|
||||
setLayout(null);
|
||||
|
||||
//按钮1
|
||||
btn1.setBounds(190,100,120,50);
|
||||
btn1.setFont(new Font("微软雅黑", 0, 17));
|
||||
|
||||
//按钮2
|
||||
btn2.setBounds(190,170,120,50);
|
||||
btn2.setFont(new Font("微软雅黑",0,17));
|
||||
//添加监听事件
|
||||
btn1.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if(level==0){//第一关
|
||||
new GameFrame().start();
|
||||
}else if(level==1){//第二关
|
||||
new GameFrame().start2();
|
||||
}else{//第三关
|
||||
new GameFrame(1).start3();
|
||||
}
|
||||
}
|
||||
});
|
||||
btn2.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
ch=1;//将闯关标识设为1
|
||||
new GameFrame().start();//打开第一关
|
||||
}
|
||||
});
|
||||
|
||||
//标签和下拉列表
|
||||
label1.setBounds(180,300,70,40);
|
||||
cbb1.setBounds(250,300,100,40);
|
||||
//列表项添加事件
|
||||
cbb1.addItemListener(new ItemListener() {
|
||||
@Override
|
||||
public void itemStateChanged(ItemEvent e) {
|
||||
if(e.SELECTED==0){//选择第一项
|
||||
level=0;
|
||||
}else if(cbb1.getSelectedIndex()==1){
|
||||
level=1;
|
||||
}else if(cbb1.getSelectedIndex()==2){
|
||||
level=2;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
//给面板添加组件
|
||||
root.add(label1);
|
||||
root.add(cbb1);
|
||||
root.add(btn1);
|
||||
root.add(btn2);
|
||||
//设置面板颜色
|
||||
root.setBackground(Color.pink);
|
||||
// 最后显示窗体
|
||||
setVisible(true);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue