博客
关于我
java程序启动界面的实现
阅读量:581 次
发布时间:2019-03-11

本文共 3222 字,大约阅读时间需要 10 分钟。

两种不同的程序启动界面案例分析

作为一名开发人员,你可能已经多次遇到了程序启动界面的设计任务。以下两种程序启动界面案例可以为你的项目提供灵感。

案例说明

当程序启动时,展示简洁直观的界面能为用户带来良好的使用体验。通过设置适当的图片和进度条等元素,可以让用户感受到程序启动的专业性和美观度。

案例过程

以下两种程序启动界面展示了不同的风格和功能实现。哪种更适合你的项目取决于你的个人喜好和需求。

第一种程序启动界面

代码如下:

package com.student.frame;/*** 系统启动类* @author Administrator*/// 导入包import javax.swing.*;import java.awt.*;import java.util.Timer;import java.util.TimerTask;// 启动主类继承窗体父类并实现线程接口public class Index extends JWindow implements Runnable {    private static final long serialVersionUID = 1L;    private JProgressBar jpb;    private JLabel jl;    // 构造方法    public Index() {        init();    }    // 初始化方法    public void init() {        jl = new JLabel(new ImageIcon("image/0.png"));        jpb = new JProgressBar();        jpb.setStringPainted(true);        jpb.setIndeterminate(false);        jpb.setBorderPainted(false);        jpb.setBackground(Color.pink);        setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));        this.add(jl, BorderLayout.NORTH);        this.add(jpb, BorderLayout.SOUTH);        this.setSize(384, 292);        this.setLocationRelativeTo(null);        this.pack();        this.setVisible(true);    }    // 设置线程方法    public void run() {        int[] progressValue = { 0, 1, 5, 8, 14, 17, 26, 35, 38, 43, 49, 56, 65, 71, 75, 78, 86, 94, 98, 99, 100 };        for (int i = 0; i < progressValue.length; i++) {            try {                Thread.sleep(1000);            } catch (InterruptedException e) {                e.printStackTrace();            }            jpb.setValue(progressValue[i]);        }    }    // 启动类主方法    public static void main(String[] args) {        Index i = new Index();        Thread t = new Thread(i);        t.start();    }}第二种程序启动界面代码如下:

// 注意:本代码仅为说明用例,实际项目请根据需求调整设置import javax.swing.;import java.awt.;import java.net.*;

// 程序启动界面类public class JWindowDemo extends JWindow implements Runnable {Thread splashThread;JProgressBar progress;

// 构造方法public JWindowDemo() {    Container container = getContentPane();    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));    // 加载图片    URL url = getClass().getResource("login.jpg");    if (url != null) {        container.add(new JLabel(new ImageIcon(url)), BorderLayout.CENTER);    }    // 初始化进度条    progress = new JProgressBar(1, 100);    progress.setStringPainted(true);    progress.setString("加载程序中,请稍候...");    progress.setBackground(Color.white);    container.add(progress, BorderLayout.SOUTH);    // 设置窗口位置    Dimension screen = getToolkit().getScreenSize();    setLocation((screen.width - getSize().width) / 2, (screen.height - getSize().height) / 2);    pack();}// 启动线程public void start() {    this.toFront();    splashThread = new Thread(this);    splashThread.start();}// 线程执行方法public void run() {    setVisible(true);        try {        for (int i = 0; i < 100; i++) {            Thread.sleep(100);            progress.setValue(progress.getValue() + 1);        }    } catch (Exception ex) {        ex.printStackTrace();    }    dispose();}// 启动类主方法public static void main(String[] args) {    JWindowDemosplash = new JWindowDemo();    splash.start();}

}

案例总结两种启动界面的区别主要体现在视觉风格和功能实现上。第一种界面采用了纯文字的进度条设计,搭配一张图片,整体风格相对简洁;第二种则使用了图片合成的方式,共同营造出更丰富的视觉效果。你可以根据自己的项目需求选择合适的启动界面,同时结合不同风格进行定制化设计。

转载地址:http://rbytz.baihongyu.com/

你可能感兴趣的文章
npm install digital envelope routines::unsupported解决方法
查看>>
npm install 卡着不动的解决方法
查看>>
npm install 报错 ERR_SOCKET_TIMEOUT 的解决方法
查看>>
npm install 报错 fatal: unable to connect to github.com 的解决方法
查看>>
npm install 报错 no such file or directory 的解决方法
查看>>
npm install报错,证书验证失败unable to get local issuer certificate
查看>>
npm install无法生成node_modules的解决方法
查看>>
npm install的--save和--save-dev使用说明
查看>>
npm node pm2相关问题
查看>>
npm run build 失败Compiler server unexpectedly exited with code: null and signal: SIGBUS
查看>>
npm run build报Cannot find module错误的解决方法
查看>>
npm run build部署到云服务器中的Nginx(图文配置)
查看>>
npm run dev 报错PS ‘vite‘ 不是内部或外部命令,也不是可运行的程序或批处理文件。
查看>>
npm scripts 使用指南
查看>>
npm should be run outside of the node repl, in your normal shell
查看>>
npm start运行了什么
查看>>
npm WARN deprecated core-js@2.6.12 core-js@<3.3 is no longer maintained and not recommended for usa
查看>>
npm 下载依赖慢的解决方案(亲测有效)
查看>>
npm 安装依赖过程中报错:Error: Can‘t find Python executable “python“, you can set the PYTHON env variable
查看>>
npm.taobao.org 淘宝 npm 镜像证书过期?这样解决!
查看>>