I am using JOptionPane
to make a menu that calls and executes program separately (the applet and menu are not required, i'm just doing it to make it better). I tried to call the init()
method but it says "non-static method init() cannot be referenced from a static statement." The applet is used to play a song
Code:
First Program: *
import javax.swing.JOptionPane;
public class MexicoProject
{
public static void main(String[] args)
{
String[] choice = {"History", "Trivia", "Intro", "Anthem", "Quit"};
String Menu;
do
{
Menu = (String)JOptionPane.showInputDialog(null, "Welcome, this program will teach you about the history of Mexico.\nPick one of the options below.",
"Mexico History", JOptionPane.QUESTION_MESSAGE, null, choice, choice[0]);
if (Menu == null)
JOptionPane.showMessageDialog(null, "Pick something!");
else
{
switch (Menu)
{
case "History":
MexicoHistory.History();
break;
case "Trivia":
Quiz();
break;
case "Intro":
FrenchIntro.Intro();
break;
case "Anthem":
MexicoAnthem.Init();
break;
case "Quit":
JOptionPane.showMessageDialog(null, "Goodbye!");
break;
default:
JOptionPane.showMessageDialog(null, "Something went wrong! Try again!");
}
}
} while (Menu != "Quit");
}
public static void History()
{
}
public static void Quiz()
{
}
}*
Second Program:
import java.applet.*;
import java.net.*;
public class MexicoAnthem extends Applet
{
Button button;
public void Init()
{
BorderLayout layout = new BorderLayout();
setLayout(layout);
Font font = new Font("TimesRoman", Font.BOLD, 32);
setFont(font);
button = new Button("Play Sound");
add("Center", button);
resize(250, 250);
}
public boolean action(Event evt, Object arg)
{
if (evt.target instanceof Button)
{
URL codeBase = getCodeBase();
play(codeBase, "MexicanNationalAnthem.wav");
}
return true;
}
}