|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
从一个编程语言的普及程度来将,一个好的IDE是至关中要的,而现在的java的IDE虽然已经很好了,但是和.net网页编程比起来还是稍微差一些的,这是个客观事实。java要想普及的更好。DE是必须加以改进的。
importjava.awt.*;
importjava.awt.event.*;
importjavax.swing.*;
importjavax.swing.event.*;
/**
*<p>Title:滑动杆演示</p>
*<p>Description:利用滑动杆把持准时器,来把持图片的播放速率</p>
*<p>Copyright:Copyright(c)2003</p>
*<p>Filename:SliderDemo.java</p>
*@version1.0
*/
publicclassSliderDemoextendsJPanel
implementsActionListener,
WindowListener,
ChangeListener{
//设置图片的参数
staticfinalintFPS_MIN=0;//设置最小值
staticfinalintFPS_MAX=30;//设置最年夜值
staticfinalintFPS_INIT=15; //初始数值
intframeNumber=0;
intNUM_FRAMES=14;
ImageIcon[]images=newImageIcon[NUM_FRAMES];
intdelay;
Timertimer;
booleanfrozen=false;
//这个标签用来显现这只小狗
JLabelpicture;
publicSliderDemo(){
setLayout(newBoxLayout(this,BoxLayout.PAGE_AXIS));
delay=1000/FPS_INIT;
//信息提醒标签
JLabelsliderLabel=newJLabel("调剂滑动杆,改动播放速率!",JLabel.CENTER);
sliderLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
//创立一个滑动杆,界说了最小值和最年夜值和初始值
JSliderframesPerSecond=newJSlider(JSlider.HORIZONTAL,
FPS_MIN,FPS_MAX,FPS_INIT);
framesPerSecond.addChangeListener(this);
//界说滑动杆参数
framesPerSecond.setMajorTickSpacing(10);//每10刻度标注一次
framesPerSecond.setMinorTickSpacing(1);//最小刻度为1
framesPerSecond.setPaintTicks(true);//绘制滑动杆上的刻度
framesPerSecond.setPaintLabels(true);//在滑动过程当中绘制滑动块
framesPerSecond.setBorder(
BorderFactory.createEmptyBorder(0,0,10,0));
//界说一个用来显现图片的标签
picture=newJLabel();
picture.setHorizontalAlignment(JLabel.CENTER);
picture.setAlignmentX(Component.CENTER_ALIGNMENT);
picture.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createLoweredBevelBorder(),
BorderFactory.createEmptyBorder(10,10,10,10)));
updatePicture(0);//显现第一张图
//将成员增加到面板上
add(sliderLabel);
add(framesPerSecond);
add(picture);
setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
//设置一个准时器来触发这个事务
timer=newTimer(delay,this);
timer.setInitialDelay(delay*7);//在每轮轮回停留工夫
timer.setCoalesce(true);//设置反复轮回
}
/**
*<br>办法申明:增加一个窗体监听
*<br>输出参数:
*<br>前往范例:
*/
voidaddWindowListener(Windoww){
w.addWindowListener(this);
}
publicvoidwindowIconified(WindowEvente){
stopAnimation();
}
publicvoidwindowDeiconified(WindowEvente){
startAnimation();
}
publicvoidwindowOpened(WindowEvente){}
publicvoidwindowClosing(WindowEvente){}
publicvoidwindowClosed(WindowEvente){}
publicvoidwindowActivated(WindowEvente){}
publicvoidwindowDeactivated(WindowEvente){}
/**
*<br>办法申明:对滑动杆举行监听
*<br>输出参数:ChangeEvente滑动杆变化事务
*<br>前往范例:
*/
publicvoidstateChanged(ChangeEvente){
JSlidersource=(JSlider)e.getSource();
if(!source.getValueIsAdjusting()){
intfps=(int)source.getValue();//取得滑动杆的值
if(fps==0){
if(!frozen)stopAnimation();
}else{
delay=1000/fps;
timer.setDelay(delay);
timer.setInitialDelay(delay*10);
if(frozen)startAnimation();
}
}
}
/**
*<br>办法申明:入手下手动画
*<br>输出参数:
*<br>前往范例:
*/
publicvoidstartAnimation(){
timer.start();
frozen=false;
}
/**
*<br>办法申明:中断动画
*<br>输出参数:
*<br>前往范例:
*/
publicvoidstopAnimation(){
timer.stop();
frozen=true;
}
/**
*<br>办法申明:事务监听
*<br>输出参数:
*<br>前往范例:
*/
publicvoidactionPerformed(ActionEvente){
//改动图片帧
if(frameNumber==(NUM_FRAMES-1)){
frameNumber=0;
}else{
frameNumber++;
}
updatePicture(frameNumber);//显现下张图
if(frameNumber==(NUM_FRAMES-1)
||frameNumber==(NUM_FRAMES/2-1)){
timer.restart();
}
}
/**
*<br>办法申明:绘制以后帧
*<br>输出参数:intframeNum图片帧数数
*<br>前往范例:
*/
protectedvoidupdatePicture(intframeNum){
if(images[frameNumber]==null){
images[frameNumber]=createImageIcon("images/doggy/T"
+frameNumber
+".gif");
}
//绘制图片
if(images[frameNumber]!=null){
picture.setIcon(images[frameNumber]);
}else{//假如没有发明图片
picture.setText("image#"+frameNumber+"notfound");
}
}
/**
*<br>办法申明:猎取图片
*<br>输出参数:Stringpath图片路径
*<br>前往范例:ImageIcon图片对象
*/
protectedstaticImageIconcreateImageIcon(Stringpath){
java.net.URLimgURL=SliderDemo.class.getResource(path);
if(imgURL!=null){
returnnewImageIcon(imgURL);
}else{
System.err.println("Couldn |
|