首页>代码>Java swing开发创意版贪吃蛇小游戏>/StarGame/src/com/game/Main.java
package com.game;
import java.awt.event.*;
import javax.swing.*;

public class Main {
	private static int id=0;	//若已登录则是用户id,未登录则是0
	private static JLabel label_account;
	
	public static void main(String[] args) {
		JFrame frame=new JFrame();
		frame.setSize(400, 300);
		frame.setLocationRelativeTo(null);
		frame.setTitle("Snake");
		frame.setResizable(false);
		frame.setLayout(null);
		
		label_account=new JLabel("账号:未登录");
		label_account.setBounds(5,5,400,30);
		frame.add(label_account);
		
		ImageIcon logo1=new ImageIcon("pic/logo.png");
		JLabel logo=new JLabel();
		logo.setIcon(logo1);
		logo.setBounds(0,40,400,70);
		frame.add(logo);

		JButton btn_game=new JButton("开始游戏");
		btn_game.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(id==0) {
					if(JOptionPane.showConfirmDialog(frame, "是否打开登录界面?", "未登录",JOptionPane.YES_NO_OPTION)==JOptionPane.YES_OPTION) {
						frame.setVisible(false);
						new Account(frame);
					}
				}else {
					frame.setVisible(false);
					new Game(frame,id);
				}
			}
		});
		btn_game.setBounds(frame.getWidth()/2-75,130,150,30);
		frame.add(btn_game);
		
		JButton btn_account=new JButton("账号管理");
		btn_account.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				frame.setVisible(false);
				new Account(frame);
			}
		});
		btn_account.setBounds(frame.getWidth()/2-75,170,150,30);
		frame.add(btn_account);
		
		JButton btn_charts=new JButton("排行榜");
		btn_charts.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				frame.setVisible(false);
				new Charts(frame);
			}
		});
		btn_charts.setBounds(frame.getWidth()/2-75,210,150,30);
		frame.add(btn_charts);
		
		frame.setVisible(true);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
	
	//由Account对象调用,如果登录成功则给id赋值
	public static void login(int i) {
		id=i;
		label_account.setText("账号:"+new Users().getAccount(i));
	}

}
最近下载更多
huangzy  LV12 2023年6月7日
微信网友_6268131861106688  LV5 2022年12月21日
Demo1111  LV30 2021年12月10日
tangjj7260  LV18 2021年11月17日
qsyqa0  LV6 2021年9月4日
顽皮的imp  LV5 2021年6月23日
你们的代码都是我的了  LV16 2021年5月16日
live1018  LV12 2020年12月23日
JacksonLee  LV1 2020年12月17日
675104182  LV14 2020年9月21日
最近浏览更多
ClydeSon  LV5 2023年12月27日
zhihong fan  LV2 2023年12月26日
jkjfdgbkl  LV2 2023年11月1日
wty1132 2023年6月27日
暂无贡献等级
baihaushu  LV1 2023年6月13日
不会敲代码 2023年6月11日
暂无贡献等级
sdyawd 2023年6月10日
暂无贡献等级
huangzy  LV12 2023年6月7日
493240689  LV3 2023年5月11日
微信网友_6438918626938880  LV1 2023年4月19日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友