Note that there are some explanatory texts on larger screens.

plurals
  1. POerror: method addActionListener in class AbstractButton cannot be applied to given types
    primarykey
    data
    text
    <p>I'm trying to add music to my program as to make it sound like a commercial so to say, lol it's in regards to a Pizza company called PizzaPalooza but I am getting a few errors such as </p> <p><code>error: method addActionListener in class AbstractButton cannot be applied to given types</code></p> <p><code>JPizza.java:77: error: incompatible types if(source = playButton) ^ required: boolean found: Object</code></p> <p><code>JPizza.java:69: error: method addActionListener in class AbstractButton cannot be applied to given types; playButton.addActionListener(this); ^ required: ActionListener found: JPizza</code></p> <p>just a few examples, for these I have tried to create a new object of <code>source</code></p> <p>But I do not understand what it means by <code>method addActionListener in class AbstractButton cannot be applied to given types</code></p> <p>For these would I have to redo the entire thing and <code>extend</code> the <code>ActionListener</code>? or can I do it another way? I'm having a difficult time understanding the <code>JApplets</code>.</p> <p>Thanks in Advance!</p> <p>this is the part of the code that is throwing the problems:</p> <pre><code>public void init() { Container Con = getContentPane(); con.setLayout (new FlowLayout()); con.add(listenLabel); con.add(playButton); con.add(stopButton); playButton.addActionListener(this); stopButton.addActionListener(this); music = getAudioClip(getCodeBase(),"business.mid"); } public void actionPerformed(ActionEvent e) { Object source = e.getSource(); if(source = playButton) music.loop(); else music.stop(); } </code></pre> <p>and this is the rest of my code:</p> <pre><code>import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.applet.*; public class JPizza extends JFrame implements ItemListener { FlowLayout flow = new FlowLayout(); JLabel companyName = new JLabel("PizzaPalooza"); JComboBox&lt;String&gt; sizeBox = new JComboBox&lt;String&gt;(); JLabel sizeList = new JLabel("Size List"); JComboBox&lt;String&gt; toppingBox = new JComboBox&lt;String&gt;(); 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"); 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 JPizza() { super("PizzaPalooza"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLayout(flow); add(companyName); companyName.setFont(new Font("Ariel", Font.BOLD, 20)); sizeBox.addItem("None"); sizeBox.addItem("Small"); sizeBox.addItem("Medium"); sizeBox.addItem("Large"); sizeBox.addItem("Extra large"); toppingBox.addItem("None"); toppingBox.addItem("Cheese"); toppingBox.addItem("Sausage"); toppingBox.addItem("Pepperoni"); toppingBox.addItem("Green pepper"); toppingBox.addItem("Onion"); add(sizeList); add(sizeBox); sizeBox.addItemListener(this); add(toppingList); add(toppingBox); toppingBox.addItemListener(this); add(totPrice); add(oName); add(orderName); } public static void main(String[] arguments) { JPizza pframe = new JPizza(); pframe.setSize(380,200); pframe.setVisible(true); } public void init() { Container Con = getContentPane(); con.setLayout (new FlowLayout()); con.add(listenLabel); con.add(playButton); con.add(stopButton); playButton.addActionListener(this); stopButton.addActionListener(this); music = getAudioClip(getCodeBase(),"business.mid"); } public void actionPerformed(ActionEvent e) { Object source = e.getSource(); if(source = playButton) music.loop(); else music.stop(); } public void itemStateChanged(ItemEvent list) { Object source = list.getSource(); if (source == sizeBox) { sizeNum = sizeBox.getSelectedIndex(); sPrice = sizePrice[sizeNum]; sumPrice = sPrice + tPrice; output = "Total Price $" + sumPrice; totPrice.setText(output); } else if (source == toppingBox) { toppingNum = toppingBox.getSelectedIndex(); tPrice = toppingPrice[toppingNum]; sumPrice = sPrice + tPrice; output = "Total Price $" + sumPrice; totPrice.setText(output); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload