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)); } }

zhuangshouna LV14
8月19日
lsglsg9 LV23
2024年5月23日
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日

zhuangshouna LV14
8月19日
dushine LV3
4月14日
三角阀 LV4
2024年7月13日
long123_356 LV8
2024年6月22日
lsglsg9 LV23
2024年5月23日
zattttt LV1
2024年5月15日
ClydeSon LV5
2023年12月27日
zhihong fan LV2
2023年12月26日
jkjfdgbkl LV2
2023年11月1日
wty1132
2023年6月27日
暂无贡献等级