this is a part of the levelselector class. However, when i tried to launch it from the start class, which's the class next, it just get stuck there doing nothing and don't reporting any errors. My tutor also took a look of it and he just said it's weird and can't immediately solve the question... So could someone help? This is the levelselecter class.
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class LevelSelectortest implements ActionListener{
private JButton[] S = new JButton[40];
private JButton back = new JButton("Back to menu");
private JPanel levelSelectPanel = new JPanel();
private GridLayout levelSelectLayout = new GridLayout(6, 7);
private Hoppertest h;
public LevelSelectortest(Hoppertest h)
{
this.h = h;
levelSelectPanel.setLayout(levelSelectLayout);
h.getFrame().setContentPane(levelSelectPanel);
}
public void selecting()
{
for (int i = 0; i <= 39; i++)
{
S[i] = new JButton("Level " + i);
levelSelectPanel.add(S[i]);
S[i].addActionListener(this);
}
levelSelectPanel.add(back);
back.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
for (int a = 0; a <= 39; a++)
{
if (e.getSource() == S[a])
{
h.setLevel(a);
}
}
if (e.getSource() == back)
{
h.setStart();
}
}
}
//this is the start class
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
public class Starttest implements ActionListener{
private JPanel startPanel = new JPanel();
private JPanel totalPanel = new JPanel();
private BorderLayout totalLayout = new BorderLayout();
private GridLayout startLayout = new GridLayout(1, 3);
private JButton frogKing = new JButton();
private JButton startButton = new JButton("Start!");
private JButton levelSelection = new JButton("Choose a level to play");
private JButton help = new JButton("How to play the game?");
private ImageIcon theFrog = new ImageIcon("The Frog King.png");
private static boolean readable = true;
private Hoppertest h;
public Starttest(Hoppertest h)
{
this.h = h;
h.getFrame().setContentPane(totalPanel);
totalPanel.setLayout(totalLayout);
totalPanel.add("North", frogKing);
totalPanel.add("South", startPanel);
startPanel.setLayout(startLayout);
frogKing.setPreferredSize(new Dimension(750, 650));
startPanel.setPreferredSize(new Dimension(750, 50));
startPanel.add(startButton);
startPanel.add(levelSelection);
startPanel.add(help);
frogKing.setIcon(theFrog);
startButton.addActionListener(this);
levelSelection.addActionListener(this);
help.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == startButton)
{
//h.setLevel(1);
}
else if (e.getSource() == levelSelection)
{
h.setLevelSelector();
}
else if (e.getSource() == help && readable == true)
{
//do something
}
}
}
//this is the main class
import javax.swing.JFrame;
public class Hoppertest {
private JFrame frame = new JFrame();
public Hoppertest()
{
frame.setTitle("HOOOOOOOOOOOOOOOOOOOOOpers");
frame.setSize(750, 800);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setStart();
}
public void setStart()
{
Starttest start = new Starttest(this);
}
public void setLevelSelector()
{
LevelSelectortest l = new LevelSelectortest(this);
l.selecting();
}
public void setLevel(int a)
{
//Board b = new Board(content[a - 1], this);
//b.levelContent();
}
public JFrame getFrame()
{
return frame;
}
public static void main(String[] args)
{
Hoppertest hopper = new Hoppertest();
}
}