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学习资料的也可以私信我!
祝关注我的人都:身体健康,财源广进,福如东海,寿比南山,早生贵子,从不掉发!