所以我一直在编写关于JPizza.java
的代码,我已经到了这个错误的地步:
JPizza.java:38: error: cannot find symbol
music = getAudioClip(getCodeBase(),"katy_perry-roar.mid");
^
symbol: method getCodeBase()
location: class JPizza
1 error
我一直想弄清楚为什么它会给我这些错误,但是
我在这里找不到主要问题?是因为我忘了定义
一个方法?对于getCodeBase()和CodeBase(),我尝试将其定义为CodeBase() = getCodeBase()
,然后将错误转移到getAudioClip
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class JPizza extends JFrame implements ItemListener, ActionListener
{
FlowLayout flow = new FlowLayout();
JLabel companyName = new JLabel("PizzaPalooza");
JComboBox<String> sizeBox = new JComboBox<String>();
JLabel sizeList = new JLabel("Size List");
JComboBox<String> toppingBox = new JComboBox<String>();
JLabel toppingList = new JLabel("Topping List");
JTextField totPrice = new JTextField(10);
JLabel orderName = new JLabel("Name of Order");
JTextField oName = new JTextField(15);
JLabel listenLabel = new JLabel("Listen to our theme!");
JButton playButton = new JButton("Play");
JButton stopButton = new JButton("Stop");
JLabel headLabel = new JLabel ();
AudioClip music;
int totalPrice = 0;
int sizeNum, toppingNum;
int sPrice, tPrice, sumPrice;
int[] sizePrice = {0,7,9,11,14};
int[] toppingPrice = {0,0,1,1,1,1};
String output;
public void init()
{
Container con = getContentPane();
con.setLayout (new FlowLayout());
con.add(headLabel);
con.add(listenLabel);
con.add(playButton);
con.add(stopButton);
playButton.addActionListener(this);
stopButton.addActionListener(this);
music = getAudioClip(getCodeBase(),"katy_perry-roar.mid");
}
public void actionPerformed(ActionEvent e)
{
Object source = e.getSource();
if(source == playButton)
music.loop();
else
music.stop();
}
为此,但我不明白这意味着什么?
答案 0 :(得分:2)
编译问题在于上面的行。您在
行中缺少JLabel构造函数括号和分号 JLabel headLabel = new JLabel
应该是:
JLabel headLabel = new JLabel();