网吧管理系统(javafx)

这个博客介绍了使用JavaFX构建的网吧管理系统。系统包括管理员登录功能,配置文件用于存储折扣和登录信息。代码中展示了登录验证的过程,当登录成功时会跳转到新的界面。此外,配置文件还定义了上网价格,系统支持按时间计费。FXML文件用于界面布局,控制器处理用户交互。博客还包含了系统的运行截图和相关配置细节。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

网吧管理系统(javafx)

运行截图如下

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

配置文件

折扣、登录密码

<?xml version="1.0"?>
<config>
    <Id>Admin</Id>>
    <Password>admin</Password>>
    <BecomeVip>100</BecomeVip>>
    <VVipComputer>4</VVipComputer>>
    <VNormalComputer>3</VNormalComputer>>
    <NVipComputer>6</NVipComputer>>
    <NNormalComputer>4</NNormalComputer>>
    <VipComputerNumber>100</VipComputerNumber>>
    <NormalComputerNumber>100</NormalComputerNumber>>
    <Vmin>100</Vmin>>
    <Nmin>150</Nmin>>
    <Vpercent>50</Vpercent>>
    <Npercent>20</Npercent>>
    <VVPreferential>60</VVPreferential>>
    <VNPreferential>50</VNPreferential>>
    <NVPreferential>80</NVPreferential>>
    <NNPreferential>60</NNPreferential>>
</config>

上网价格

<?xml version="1.0"?>
<config>
    <hours1>10</hours1>>
    <hours2>10</hours2>>
    <hours3>10</hours3>>
    <hours4>10</hours4>>
    <hours5>10</hours5>>
    <hours6>10</hours6>>
    <hours7>10</hours7>>
    <hours8>10</hours8>>
    <hours9>10</hours9>>
    <hours10>10</hours10>>
    <hours11>10</hours11>>
    <hours12>10</hours12>>
    <hours13>10</hours13>>
    <hours14>10</hours14>>
    <hours15>10</hours15>>
    <hours16>10</hours16>>
    <hours17>10</hours17>>
    <hours18>10</hours18>>
    <hours19>10</hours19>>
    <hours20>10</hours20>>
    <hours21>10</hours21>>
    <hours22>10</hours22>>
    <hours23>10</hours23>>
    <hours24>10</hours24>>
</config>

部分代码

登录代码

package TaskPackage;

import Admin.ReadLogin;
import javafx.concurrent.Service;
import javafx.concurrent.Task;
import javafx.scene.control.Label;

/***
 @author sky
 @date 2020/2/20
 @version 1.0
 */
//管理员登录线程
public class LoginTask extends Service {
    String id;
    String password;
    Label label;

    public LoginTask(String id, String password, Label label){
        this.id=id;
        this.password=password;
        this.label=label;
    }

    public String getPassword(){
        return password;
    }
    @Override
    protected Task createTask() {
        Task task = new Task() {
            @Override
            protected void updateValue(Object value) {
                super.updateValue(value);
                if((Boolean) value==true){
                    label.setText("状态:登陆成功");
                }
                else {
                    label.setText("状态:登陆失败");
                }
            }

            @Override
            protected Object call() throws Exception {
                ReadLogin readLogin = new ReadLogin();
                readLogin.ReadpasswordAndID();
                if(readLogin.getId().equals(id)&&readLogin.getPassword().equals(password)){
                    this.updateMessage("允许");
                    id=readLogin.getId();
                    password=readLogin.getPassword();
                    return true;
                }
                this.updateMessage("拒绝");
                id=readLogin.getId();
                password=readLogin.getPassword();
                return false;
            }
        };
        return task;
    }
}

controller 代码

package sample;

import TaskPackage.*;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;

import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;

/***
 @author sky
 @date 2020/2/20
 @version 1.0
 */
public class AdminLogin implements Initializable {
    @FXML
    AnchorPane pane;
    @FXML
    TextField id;//id框
    @FXML
    PasswordField password;//密码框
    @FXML
    Button login;
    @FXML
    Label state;
    @FXML
    ImageView photo;
    @FXML
    ImageView photo1;
    @Override
    public void initialize(URL url, ResourceBundle resourceBundle) {
        BackgroundTask backgroundTask = new BackgroundTask(pane,"LoginBackground");
        backgroundTask.start();
        SetPng setPng =new SetPng(photo,2,"/res/login");
        setPng.start();
        SetPng setPng1 =new SetPng(photo1,3,"/res/login");
        setPng1.start();
        SetButton setButton = new SetButton("哈哈",login,"LoginBackground");
        setButton.start();
        //登录
        login.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent actionEvent) {
                if(id.getText().length()>0&&password.getLength()>0){
                    LoginTask loginTask = new LoginTask(id.getText(),password.getText(),state);
                    loginTask.start();
                    loginTask.messageProperty().addListener(new ChangeListener<String>() {
                        @Override
                        public void changed(ObservableValue<? extends String> observableValue, String s, String t1) {
                            if(t1.equals("允许")){
                                Parent Operation_Parent = null;
                                try {
                                    Operation_Parent = FXMLLoader.load(getClass().getResource("Menu.fxml"));
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }
                                Scene Operation_Creating_Scene = new Scene(Operation_Parent);
                                Stage CreateOperation_Stage = (Stage) ((Node) actionEvent.getSource()).getScene().getWindow();
                             //   CreateOperation_Stage.hide();
                              //  CreateOperation_Stage.close();
                                SetStage setStage = new SetStage("菜单界面",CreateOperation_Stage,"src/res/icon.gif");//图标
                                setStage.start();
                                CreateOperation_Stage.setScene(Operation_Creating_Scene);
                                CreateOperation_Stage.show();
                            }
                        }
                    });
                }
            }
        });
    }
}

fxml文件

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.image.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.paint.*?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<AnchorPane fx:id="pane" prefHeight="720.0" prefWidth="720.0" style="-fx-backgroundTask-image: url('src/res/background1.jpg');;" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.AdminLogin">
   <children>
      <Label alignment="CENTER" contentDisplay="TOP" layoutX="254.0" layoutY="34.0" opacity="0.73" prefHeight="50.0" prefWidth="196.0" text="Sky网吧管理系统" textFill="#b21c1c" underline="true" wrapText="true" AnchorPane.bottomAnchor="636.0" AnchorPane.leftAnchor="254.0" AnchorPane.rightAnchor="270.0" AnchorPane.topAnchor="34.0">
         <font>
            <Font name="System Bold" size="25.0" />
         </font>
      </Label>
      <Label layoutX="84.0" layoutY="182.0" text="管理员账号:" textFill="#da1313">
         <font>
            <Font size="20.0" />
         </font>
      </Label>
      <Label layoutX="78.0" layoutY="311.0" text="管理员密码:" textFill="#da1313">
         <font>
            <Font size="20.0" />
         </font>
      </Label>
      <TextField fx:id="id" layoutX="207.0" layoutY="181.0" opacity="0.6" prefHeight="30.0" prefWidth="284.0" />
      <PasswordField fx:id="password" layoutX="207.0" layoutY="309.0" opacity="0.6" prefHeight="30.0" prefWidth="284.0" />
      <Button fx:id="login" layoutX="422.0" layoutY="436.0" mnemonicParsing="false" opacity="0.6" prefHeight="30.0" prefWidth="67.0" text="登录" textFill="#d71717">
         <cursor>
            <Cursor fx:constant="DEFAULT" />
         </cursor>
      </Button>
      <Label fx:id="state" layoutX="32.0" layoutY="49.0" text="状态:离线" textFill="#c90c0c" />
      <ImageView fx:id="photo" fitHeight="150.0" fitWidth="200.0" layoutX="512.0" layoutY="96.0" pickOnBounds="true" preserveRatio="true" />
      <ImageView fx:id="photo1" fitHeight="150.0" fitWidth="200.0" layoutX="37.0" layoutY="445.0" pickOnBounds="true" preserveRatio="true" />
   </children>
   <cursor>
      <Cursor fx:constant="HAND" />
   </cursor>
</AnchorPane>

redme文档

    <Id>Admin</Id>>//登录的用户名
    <Password>admin</Password>>//登录初始密码
    <BecomeVip>100</BecomeVip>>//成为vip用户需要花的钱
    /**********************************************************************************/
    <VVipComputer>4</VVipComputer>>//vip用户使用vip电脑一个小时需要缴纳的钱
    <VNormalComputer>3</VNormalComputer>>//vip用户使用普通电脑一个小时需要缴纳的钱
    <NVipComputer>6</NVipComputer>>//普通用户使用vip电脑一个小时需要缴纳的钱
    <NNormalComputer>4</NNormalComputer>>//普通用户使用普通电脑一个小时需要缴纳的钱
     /**********************************************************************************/
    这几个参数废除,无效!!!!!!!价格同一按照hourMoney文件!!!
    针对不同的用户使用不同的电脑,可以通过改变其折扣百分比来实现不同用户使用不同电脑单价不同!!!!
     /**********************************************************************************/
    <VipComputerNumber>100</VipComputerNumber>>//vip电脑的数量
    <NormalComputerNumber>100</NormalComputerNumber>>//普通电脑的数量
    <Vmin>100</Vmin>>//vip用户享受充值活动的最低起充点
    <Nmin>100</Nmin>>//普通用户享受充值活动的最低起充点
    <Vpercent>100</Vpercent>>//vip用户充钱的优惠百分比 赠送费用为充值费用的百分比
    <Npercent>100</Npercent>>//普通用户充钱的优惠百分比 赠送费用为充值费用的百分比
    <VVPreferential>100</VVPreferential>>//vip用户使用vip电脑的折扣  百分比
    <VNPreferential>100</VNPreferential>>//vip用户使用普通电脑的折扣  百分比
    <NVPreferential>100</NVPreferential>>//普通用户使用vip电脑的折扣 百分比
    <NNPreferential>100</NNPreferential>>//普通用户使用普通电脑的折扣 百分比

    /********************************************************************************/
        该计费系统机费到秒!!!!!只有用户到前台进行下线操作才会停止计费!!!!
        <hours1>100</hours1>>//表示0-1时间内的价格为100元1小时
        <hours2>100</hours2>>//表示1-2时间内的价格为100元1小时
        <hours3>100</hours3>>//表示2-3时间内的价格为100元1小时
        <hours4>100</hours4>>//表示3-4时间内的价格为100元1小时
        <hours5>100</hours5>>//表示4-5时间内的价格为100元1小时
        <hours6>100</hours6>>//表示5-6时间内的价格为100元1小时
        <hours7>100</hours7>>//表示6-7时间内的价格为100元1小时
        <hours8>100</hours8>>//表示7-8时间内的价格为100元1小时
        <hours9>100</hours9>>//表示8-9时间内的价格为100元1小时
        <hours10>100</hours10>>//表示9-10时间内的价格为100元1小时
        <hours11>100</hours11>>//表示10-11时间内的价格为100元1小时
        <hours12>100</hours12>>//表示11-12时间内的价格为100元1小时
        <hours13>100</hours13>>//表示12-13时间内的价格为100元1小时
        <hours14>100</hours14>>//表示13-14时间内的价格为100元1小时
        <hours15>100</hours15>>//表示14-15时间内的价格为100元1小时
        <hours16>100</hours16>>//表示15-16时间内的价格为100元1小时
        <hours17>100</hours17>>//表示16-17时间内的价格为100元1小时
        <hours18>100</hours18>>//表示17-18时间内的价格为100元1小时
        <hours19>100</hours19>>//表示18-19时间内的价格为100元1小时
        <hours20>100</hours20>>//表示19-20时间内的价格为100元1小时
        <hours21>100</hours21>>//表示20-21时间内的价格为100元1小时
        <hours22>100</hours22>>//表示21-22时间内的价格为100元1小时
        <hours23>100</hours23>>//表示22-23时间内的价格为100元1小时
        <hours24>100</hours24>>//表示23-24时间内的价格为100元1小时
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值