Java小項目之:小說閱讀器


Java小項目之:小說閱讀器

今天帶來的java項目是一款閱讀器,老少皆宜,適合練手。

 

代碼展示:

package com;

 

import javax.swing.JOptionPane;

 

public class Scroll {

private int n;

private int size;

private Thread t;

private static int def_speed = 1000;

private static int up_speed = -500;

private static int down_speed = 500;

 

public int getN() {

return n;

}

 

public void setN(int n) {

this.n = n;

}

 

public int getSize() {

return size;

}

 

public void setSize(int size) {

this.size = size;

}

 

 

 

public Scroll(){

 

}

 

public Scroll(int n,int size){

this.n = n;

this.size = size;

}

 

public void startScroll(){

t = new Thread(){

public void run(){

for(int j=0;j<size;j++){

Main.jta.setText("");

for(int i=n;i<=n+25;i++){

if(n<size){

Main.jta.append(Main.content.get(i));

}

}

try{

Thread.sleep(1000);

}catch(InterruptedException e){

break;

}

float n1 = (float)n;

float size1 = (float)size;

Main.l2.setText(Math.round(n1/size1*100)+"%");

Main.js.setValue(Math.round(n1/size1*100));

n++;

if(n==size){

t.interrupt();

JOptionPane.showMessageDialog(Main.frame, "to the end");

}

}

}

};

t.start();

}

 

public int stopScroll(){

t.interrupt();

return n;

}

 

public void speedUp(){

t.interrupt();

t = new Thread(){

public void run(){

for(int j=0;j<size;j++){

Main.jta.setText("");

for(int i=n;i<=n+25;i++){

if(n<size){

Main.jta.append(Main.content.get(i));

}

}

try{

Thread.sleep(def_speed+up_speed);

}catch(InterruptedException e){

break;

}

float n1 = (float)n;

float size1 = (float)size;

Main.l2.setText(Math.round(n1/size1*100)+"%");

Main.js.setValue(Math.round(n1/size1*100));

n++;

 

if(n==size-25){

t.interrupt();

JOptionPane.showMessageDialog(Main.frame, "to the end");

}

}

}

};

t.start();

}

 

public void speedDown(){

t.interrupt();

t = new Thread(){

public void run(){

for(int j=0;j<size;j++){

Main.jta.setText("");

for(int i=n;i<=n+25;i++){

if(n<size){

Main.jta.append(Main.content.get(i));

}

}

try{

Thread.sleep(def_speed+down_speed);

}catch(InterruptedException e){

break;

}

float n1 = (float)n;

float size1 = (float)size;

Main.l2.setText(Math.round(n1/size1*100)+"%");

Main.js.setValue(Math.round(n1/size1*100));

n++;

if(n==size-25){

t.interrupt();

JOptionPane.showMessageDialog(Main.frame, "to the end");

}

}

}

};

t.start();

}

 

public void prePage(){

t.interrupt();

Main.jta.setText("");

if(n-25<=0){

n=0;

for(int i=0;i<=25;i++){

Main.jta.append(Main.content.get(i));

}

}else{

for(int i=n-25;i<=n;i++){

Main.jta.append(Main.content.get(i));

}

n=n-25;

}

t = new Thread(){

public void run(){

for(int j=0;j<size;j++){

Main.jta.setText("");

for(int i=n;i<=n+25;i++){

if(n<size){

Main.jta.append(Main.content.get(i));

}

}

try{

Thread.sleep(1000);

}catch(InterruptedException e){

break;

}

float n1 = (float)n;

float size1 = (float)size;

Main.l2.setText(Math.round(n1/size1*100)+"%");

Main.js.setValue(Math.round(n1/size1*100));

n++;

if(n==size){

t.interrupt();

JOptionPane.showMessageDialog(Main.frame, "to the end");

}

}

}

};

t.start();

}

 

public void nextPage(){

t.interrupt();

Main.jta.setText("");

if(n+25>=size){

n=size-25;

for(int i=n;i<size;i++){

Main.jta.append(Main.content.get(i));

}

}else{

for(int i=n;i<=n+25;i++){

Main.jta.append(Main.content.get(i));

}

n=n+25;

}

t = new Thread(){

public void run(){

for(int j=0;j<size;j++){

Main.jta.setText("");

for(int i=n;i<=n+25;i++){

if(n<size){

Main.jta.append(Main.content.get(i));

}

}

try{

Thread.sleep(1000);

}catch(InterruptedException e){

break;

}

float n1 = (float)n;

float size1 = (float)size;

Main.l2.setText(Math.round(n1/size1*100)+"%");

Main.js.setValue(Math.round(n1/size1*100));

n++;

if(n==size){

t.interrupt();

JOptionPane.showMessageDialog(Main.frame, "to the end");

}

}

}

};

t.start();

}

 

public void sliScroll(int slipage){

t.interrupt();

if(slipage+25<=Main.content.size()){

for(int i = slipage;i<=slipage+25;i++){

Main.jta.append(Main.content.get(i));

}

}else{

for(int i = slipage;i<Main.content.size();i++){

Main.jta.append(Main.content.get(i));

}

}

n=slipage+25;

t = new Thread(){

public void run(){

for(int j=0;j<size;j++){

Main.jta.setText("");

for(int i=n;i<=n+25;i++){

if(n<size){

Main.jta.append(Main.content.get(i));

}

}

try{

Thread.sleep(1000);

}catch(InterruptedException e){

break;

}

float n1 = (float)n;

float size1 = (float)size;

Main.l2.setText(Math.round(n1/size1*100)+"%");

Main.js.setValue(Math.round(n1/size1*100));

n++;

if(n==size){

t.interrupt();

JOptionPane.showMessageDialog(Main.frame, "to the end");

}

}

}

};

t.start();

}

}

喜歡這樣文章的可以關注我,我會持續更新,你們的關注是我更新的動力!需要更多java學習資料的也可以私信我!

祝關注我的人都:身體健康,財源廣進,福如東海,壽比南山,早生貴子,從不掉發!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM