我正在为一门课程编写程序,我需要让美国国旗将旗杆缩放到国歌。我有代码,但得到一个错误,即即使它在那里也找不到小程序。我正在使用日食。任何人都可以帮助我解决我所缺少的吗?
提前致谢...
代码:
@SuppressWarnings("serial")
public class Lab5b extends JApplet {
private AudioClip audioClip;
public Lab5b() {
add(new ImagePanel());
URL urlForAudio = getClass().getResource("audio/us.mid");
audioClip = Applet.newAudioClip(urlForAudio);
audioClip.loop();
}
public void start() {
if (audioClip != null) audioClip.loop();
}
public void stop() {
if (audioClip != null) audioClip.stop();
}
/** Main method */
public static void main(String[] args) {
// Create a frame
JFrame frame = new JFrame("Lab 5");
// Create an instance of the applet
Lab5b applet = new Lab5b();
applet.init();
// Add the applet instance to the frame
frame.add(applet, java.awt.BorderLayout.CENTER);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Display the frame
frame.setSize(200, 660);
frame.setVisible(true);
}
}
@SuppressWarnings("serial")
class ImagePanel extends JPanel {
private ImageIcon imageIcon = new ImageIcon("image/us.gif");
private Image image = imageIcon.getImage();
private int y = 550;
public ImagePanel() {
Timer timer = new Timer(120, new TimerListener());
timer.start();
}
class TimerListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
increaseY();
}
}
public void increaseY() {
if (y > 0) {
y--;
repaint();
}
}
/** Draw image on the panel */
protected void paintComponent(Graphics g) {
super.paintComponent(g);
if (image != null) {
g.fillRect(0, 0, 10, 660);
g.drawImage(image, 11, y, 160, 84, this);
}
}
}
在此处输入代码