问题描述
在做一个播放器,要用到进度条,不知道jslider能不能实现该功能,如果不能,应该用什么?希望高手指教
解决方案
解决方案二:
可以实现此功能的importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjavax.swing.JFrame;importjavax.swing.JPanel;importjavax.swing.JSlider;importjavax.swing.SwingUtilities;importjavax.swing.Timer;@SuppressWarnings("serial")publicclassTestextendsJPanel{privateJSliderslider=newJSlider(0,100,0);privateTimertimer;publicTest(){add(slider);timer=newTimer(300,newActionListener(){@OverridepublicvoidactionPerformed(ActionEvente){slider.setValue(slider.getValue()+1);if(slider.getValue()==slider.getMaximum()){timer.stop();System.out.println("Stop");}}});timer.start();}privatestaticvoidcreateGuiAndShow(){JFrameframe=newJFrame("");frame.getContentPane().add(newTest());frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.setSize(400,400);frame.setAlwaysOnTop(true);frame.setLocationRelativeTo(null);frame.setVisible(true);}publicstaticvoidmain(String[]args){SwingUtilities.invokeLater(newRunnable(){@Overridepublicvoidrun(){createGuiAndShow();}});}}