志在指尖
用双手敲打未来

javajre怎么安装(进度条不动解决办法)

javajre怎么安装

JavaRuntimeEnvironment是运行java程序所必需的最小装置包,是java的中心运行环境。那么我们要怎样装置JavaRuntimeEnvironment,今天小编就为大家供给JavaRuntimeEnvironment装置教程。
软件名称:JavaRuntimeEnvironment(JRE7)V7Update67官方最新版软件巨细:25.7MB更新时间:2014-08-06当即下载
软件名称:JavaRuntimeEnvironment(JRE7)jre-7u51-windows-i586.exe多国言语32位装置版软件巨细:123MB更新时间:2012-09-04当即下载
首要进入oracle网站(java现在是归属于Orcle的),挑选downloads->JavaSE。
进入javaSE的下载页面,挑选如图所示的jre下载按钮
留意:JDK是用来做Java开发的(JavaDevelopmentKit)
JRE只是Java的最新运行环境(JavaRuntimeEnvironment)
然后,根据自己的电脑挑选合适的版别下载,对于windows系统,一般挑选如图所示的exe装置包,下载到电脑就可以直接运行装置导游
留意,在点击下载之前选中“AcceptLicenseagreement”
下载到本地后就可以装置了
等待装置结束
装置成功之后在系统盘programefile会有java的目录(目录对应装置的版别)java

javajre进度条不动解决办法

在编写完进展条后,咱们有时候会遇到它彻底不动的状况,小伙伴们知道是什么原因吗?下面听小编为你们解说解说。
进展条不动或许是因为这个原因,“当应用程序在事情线程中履行长时间的操作时,会堵塞正常的AWT事情处理,因此阻挠了重绘操作的产生”,即API自身便是线程不安全的。形成这个错误的原因,便是在run办法内直接写:
progressBar.setValue(jd);
终究修正示例:importjava.awt.Color;
importjava.awt.Dimension;
importjava.awt.GridLayout;
importjava.awt.Rectangle;
importjava.awt.event.ActionEvent;
importjava.awt.event.ActionListener;
importjava.io.BufferedInputStream;
importjava.io.BufferedOutputStream;
importjava.io.File;
importjava.io.FileInputStream;
importjava.io.FileOutputStream;
importjava.io.IOException;
importjavax.swing.JButton;
importjavax.swing.JFileChooser;
importjavax.swing.JFrame;
importjavax.swing.JLabel;
importjavax.swing.JPanel;
importjavax.swing.JProgressBar;
importjavax.swing.JTextField;
publicclassExp10_3extendsJFrameimplementsRunnable
{
booleanb=false;//线程履行的标志
intjd=0;//当时进展
longsum=0;//当时共仿制的长度
JButtonbutton1=newJButton(“被仿制”);
JTextFieldbeCyFile=newJTextField(30);
JButtonbutton2=newJButton(“仿制到”);
JTextFieldCyToDir=newJTextField(30);
JButtonStart=newJButton(“开端仿制”);
JLabellabel=newJLabel(“进展”);
JProgressBarprogressBar=newJProgressBar();
voidinitUI()
{
JPaneltop1=newJPanel();
JPaneltop2=newJPanel();
JPanelend=newJPanel();
top1.add(button1);
top1.add(beCyFile);
top2.add(button2);
top2.add(CyToDir);
setLayout(newGridLayout(4,1));
add(top1);
add(top2);
add(Start);
progressBar.setStringPainted(true);//设置进展条上字符串可显现
progressBar.setBackground(Color.GREEN);//设置进展条颜色
end.add(label);
end.add(progressBar);
add(end);
button1.addActionListener(newActionListener()
{
//将选择文件的绝对路径显现到被仿制后的文本框内
@Override
publicvoidactionPerformed(ActionEvente)
{
JFileChooserfc=newJFileChooser();
fc.setFileHidingEnabled(false);//显现躲藏文件
fc.setMultiSelectionEnabled(false);//答应多选
fc.setDialogTitle(“请选择要仿制的文件”);
if(fc.showOpenDialog(Exp10_3.this)==JFileChooser.APPROVE_OPTION)
{
beCyFile.setText(fc.getSelectedFile()
.getAbsolutePath());
CyToDir.setText(fc.getSelectedFile()
.getParent());//获取file文件的父目录(强壮的API)自我设定:默认仿制到同一目录
}
}
});
button2.addActionListener(newActionListener()
{
@Override
publicvoidactionPerformed(ActionEvente)
{
JFileChooserfc=newJFileChooser();
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);//仅仅能选择目录
fc.setDialogTitle(“请选择要仿制到的路径”);
if(fc.showOpenDialog(Exp10_3.this)==JFileChooser.APPROVE_OPTION)
{
CyToDir.setText(fc.getSelectedFile()
.getAbsolutePath());
}
}
});
Start.addActionListener(newActionListener()
{
@Override
publicvoidactionPerformed(ActionEvente)
{
jd=0;
b=true;
try
{
Stringfile1Path=beCyFile.getText();
Filefile1=newFile(beCyFile.getText());//被仿制的文件
Stringfile2Path=CyToDir.getText()+”\\copy”+file1.getName();//仿制完后新文件路径名
Filefile2=newFile(file2Path);//新建仿制文件
BufferedInputStreambis=newBufferedInputStream(newFileInputStream(file1Path));
BufferedOutputStreambos=newBufferedOutputStream(newFileOutputStream(file2Path));
byte[]be=newbyte[1024*1024];//之前定义为b和boolean重复了屏蔽了全局标志b
intlen=bis.read(be);
longsum=0;
longfile1len=file1.length();
while(-1!=len)
{
bos.write(be,0,len);//一次读一个字节数组换行也会读不用主动换行了
bos.flush();
sum+=len;
jd=(int)(sum*1.0/file1len*100);//之前没有乘1.0且多写了一个(int)导致jd一向是0最终一次骤变100
len=bis.read(be);
}
最终再绘一次
Dimensiond=progressBar.getSize();
Rectanglerect=newRectangle(0,0,d.width,d.height);
progressBar.setValue(jd);
progressBar.paintImmediately(rect);
b=false;
System.out.println(“b=”+b);
}
catch(IOExceptione1)
{
e1.printStackTrace();
}
}
});
Threadt=newThread(this);
t.start();
pack();
setLocationRelativeTo(null);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
publicstaticvoidmain(String[]args)
{
Exp10_3t=newExp10_3();
t.initUI();
}
@Override
publicvoidrun()
{
while(true)
{
if(b)
{
//progressBar.setValue(jd);//之前run内就这一行,进展条一向不改写
Dimensiond=progressBar.getSize();
Rectanglerect=newRectangle(0,0,d.width,d.height);
progressBar.setValue(jd);
progressBar.paintImmediately(rect);
if(jd==100)
{
b=false;
//System.out.println(“run内b=”+b);//不能写return此进程不能结束一向开着
}
}
//System.out.println(“我没有结束”);//删了此行进展条就又不改写了
//第一次改善上面一行换成下面5行即输出操作改成停顿1ms
try
{
Thread.sleep(1);
}
catch(InterruptedExceptione)
{
e.printStackTrace();
}
}
}
}
以上便是本篇文章的所有内容,关于一些java常见问题及解决办法还有不明白的话就来咱们网站看看吧。

未经允许不得转载:IT技术网站 » javajre怎么安装(进度条不动解决办法)
分享到: 更多 (0)

评论 抢沙发

评论前必须登录!

 

志在指尖 用双手敲打未来

登录/注册IT技术大全

热门IT技术

C#基础入门   SQL server数据库   系统SEO学习教程   WordPress小技巧   WordPress插件   脚本与源码下载