-1

I've made an alarm clock class and part of the code is to pick music that plays. I created a button that when clicked opens a dialog to pick the buttons for music. But, I'm having trouble with the super in this class, a problem that my other windows haven't given me. Bear with me, I'm very bad at all of this. Here is the music dialog class (tell me if you need my other classes to answer)

import java.awt.*;
import java.io.*;
public class SetMusicDialog extends Dialog
{
    public static String sng;
    public SetMusicDialog()
    {
        super ( "Set Music");
        Panel mpanel;
        Font l = new Font("Helvetica", Font.ITALIC, 12);
        setFont(l);//sets font
        setBackground(Color.cyan);

        Panel f = new Panel();
        f.add("West", new Button("Death Grips"));
        f.add("East", new Button("Siren"));
        add("South",f);
        pack();                           // make it just fit
        resize(preferredSize());
        move(200,200);
    }

    public boolean handleEvent1 (Event evt)
    {
        switch (evt.id)
        {
            case Event.ACTION_EVENT:
                if("Death Grips".equals(evt.arg))
                {
                    sng= "breakmirrors.wav";
                }
                else if("Siren".equals(evt.arg))
                {
                    sng= "bip.wav";
                }
        }
    }
}

This is the error I keep getting:

Error: no suitable constructor found for Dialog(java.lang.String)
constructor java.awt.Dialog.Dialog(java.awt.Frame) is not applicable
  (argument mismatch; java.lang.String cannot be converted to java.awt.Frame)
constructor java.awt.Dialog.Dialog(java.awt.Dialog) is not applicable
  (argument mismatch; java.lang.String cannot be converted to java.awt.Dialog)
constructor java.awt.Dialog.Dialog(java.awt.Window) is not applicable
  (argument mismatch; java.lang.String cannot be converted to java.awt.Window)
Mage Xy
  • 1,803
  • 30
  • 36

1 Answers1

0

In your constructor, you're trying to call super with a string parameter. Since you're inheriting from the Dialog class. As you can see from the linked javadocs, Dialog does not have a constructor that takes only a string - you have to pass other parameters first (either another Dialog, Frame, Window, or null).

As a temporary workaround, you can call super using null as the first parameter - this means that the Dialog you're creating does not have a parent window.

super((Dialog)null, "Set Music");
Mage Xy
  • 1,803
  • 30
  • 36
  • I'm so thick when it comes to this, I'm sorry. How do I do that? Sorry for being a hassle, I just need these things really spelled out for me. I've already looked at that page, I just couldn't understand what I needed to put there. – Celeste Joyce Jan 20 '16 at 21:02
  • now it's giving me this error: File: C:\Users\16tacheronc\SetMusicDialog.java [line: 10] Error: reference to Dialog is ambiguous both constructor Dialog(java.awt.Frame,java.lang.String) in java.awt.Dialog and constructor Dialog(java.awt.Dialog,java.lang.String) in java.awt.Dialog match – Celeste Joyce Jan 20 '16 at 21:23
  • Ah, that's because the compiler doesn't know what type the null is standing in for. It doesn't matter in the end, so just cast it to one of those three classes (for example, `super((Dialog)null, "Set Music");`) – Mage Xy Jan 20 '16 at 21:27
  • thanks so much! now it's giving me another error but that doesn't have to do with this. Thanks! – Celeste Joyce Jan 20 '16 at 21:30