博客
关于我
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/

你可能感兴趣的文章
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
NO 157 去掉禅道访问地址中的zentao
查看>>
no available service ‘default‘ found, please make sure registry config corre seata
查看>>
no connection could be made because the target machine actively refused it.问题解决
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>
No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
查看>>
No mapping found for HTTP request with URI [/logout.do] in DispatcherServlet with name 'springmvc'
查看>>
No module named 'crispy_forms'等使用pycharm开发
查看>>
No module named cv2
查看>>
No module named tensorboard.main在安装tensorboardX的时候遇到的问题
查看>>
No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
查看>>
No new migrations found. Your system is up-to-date.
查看>>
No qualifying bean of type XXX found for dependency XXX.
查看>>
No resource identifier found for attribute 'srcCompat' in package的解决办法
查看>>
no session found for current thread
查看>>
No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android
查看>>
NO.23 ZenTaoPHP目录结构
查看>>
NO32 网络层次及OSI7层模型--TCP三次握手四次断开--子网划分
查看>>