代码与问题如下

一个昵称而已T 2015-09-07 10:59:45
源代码的作用是为了定时轮流显示不同国家的国旗和国歌,不过还有一个组合框可以选择国家,还有两个按键暂停和启动国歌,但是每次自动换国歌或者选择组合框里的国家时,只有相应的国歌会变,国旗不会变,可是在国歌改变后改变窗口大小时国旗又会变成相应的,想请大神解决一下。

public class ImageAudioAnimation extends JApplet {
private final static int NUMBER_OF_NATIONS=7;
private final static String[] nations={"China","Denmark","Germany","India","Norway","UK","US"};
private int current=0;
private AudioClip[] audioClips=new AudioClip[NUMBER_OF_NATIONS];
private AudioClip currentAudioClip;
private ImagePanel imagePanel;
private ImagePanel[] imagePanels=new ImagePanel[NUMBER_OF_NATIONS];

private int[] delays={4800,54000,59000,54000,59000,31000,68000};//根据不同国歌的时间长短
private Timer timer=new Timer(delays[0],new ActionListener() {
public void actionPerformed(ActionEvent e) {
current=(current+1)%NUMBER_OF_NATIONS;
presentNation(current);
}
});

private JButton jbtResume=new JButton("Resume");
private JButton jbtSuspend=new JButton("Suspend");
private JComboBox<String> jcboNations=new JComboBox<String>(nations);

public ImageAudioAnimation() {
for(int i=0;i<NUMBER_OF_NATIONS;i++) {
imagePanels[i]=new ImagePanel(new ImageIcon(getClass().getResource(nations[i]+".gif")));
audioClips[i]=Applet.newAudioClip(this.getClass().getResource(nations[i]+".mid"));
}

JPanel panel=new JPanel();
panel.add(jbtResume);
panel.add(jbtSuspend);
panel.add(new JLabel("Select"));
panel.add(jcboNations);

add(panel,BorderLayout.SOUTH);
imagePanel=imagePanels[0];
add(imagePanel);

jbtResume.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
start();
}
});
jbtSuspend.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
stop();
}
});
jcboNations.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
stop();
current=jcboNations.getSelectedIndex();
presentNation(current);
timer.start();
}
});

timer.start();
currentAudioClip=audioClips[0];
currentAudioClip.play();
}

private void presentNation(int index) {
this.remove(imagePanel);
this.imagePanel=imagePanels[index];
this.add(imagePanel);
jcboNations.setSelectedIndex(index);
currentAudioClip=audioClips[index];
currentAudioClip.play();
timer.setDelay(delays[index]);
}

public void start() {
timer.start();
currentAudioClip.play();
}

public void stop() {
timer.stop();
currentAudioClip.stop();
}

protected class ImagePanel extends JPanel {
private Image image;

public ImagePanel(ImageIcon imageIcon) {
image=imageIcon.getImage();
}

protected void paintComponent(Graphics g) {
super.paintComponent(g);

if(image!=null) {
g.drawImage(image, 0, 0, getWidth(),getHeight(),this);
}
}
}
}
...全文
143 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复
内容概要:本文研究了基于二阶线性自抗扰控制器(LADRC)的表贴式永磁同步电机(PMSM)双闭环矢量调速系统,重点在于通过Simulink搭建仿真模型,实现对PMSM的速度和电流双环控制。文中系统阐述了LADRC的核心原理及其在估计并补偿系统内部动态与外部扰动方面的优越性,相较于传统PI控制,LADRC显著提升了系统的动态响应速度、抗干扰能力和鲁棒性。研究构建了完整的矢量控制体系,涵盖了Park与Clarke坐标变换、空间矢量脉宽调制(SVPWM)技术、转速环与电流环的协同设计,并通过大量仿真实验,全面验证了所提出控制策略在启动过程、突加/突卸负载以及电机参数摄动等多种工况下的卓越性能表现。; 适合人群:自动化、电气工程、控制科学与工程及相关专业的研究生、高校科研人员及从事高性能电机驱动与控制算法开发的工程师。; 使用场景及目标:①深入理解自抗扰控制(ADRC)理论在高精度电机驱动系统中的具体应用与实现方法;②掌握基于Simulink/MATLAB的PMSM矢量控制系统从理论建模到仿真实现的全流程技术;③学习并掌握LADRC控制器的参数整定规律与优化技巧,提升解决实际工程中强扰动、非线性问题的能力;④为研发具有更高鲁棒性和控制精度的工业级电机控制系统提供先进的技术方案与理论依据。; 阅读建议:建议读者结合所提供的Simulink仿真模型进行同步学习与实践,重点关注扩张状态观测器(ESO)的带宽配置、控制器参数与系统性能之间的内在关系,并可通过修改负载条件和电机参数来测试系统的鲁棒性,为进一步研究非线性ADRC或将其应用于其他复杂机电系统奠定坚实基础。

23,404

社区成员

发帖
与我相关
我的任务
社区描述
Java 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧