r/learnjava • u/patt2169 • Nov 22 '19
Help why doesn't this work
package dungeon.game.pkg2;
import java.awt.Color;
import java.awt.Container;
import java.awt.Font;
import java.awt.event.ActionListener;
import javafx.event.ActionEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
public class DungeonGame21 {
JFrame window;
Container con;
JPanel titelnamepanel, titelstartpanel, gamemaintextpanel;
JLabel titelnamelabel;
JButton titelstartbutton;
Font titelnamefont = new Font("Times New Roman", Font.PLAIN, 80);
Font normal = new Font("Times New Roman", Font.PLAIN, 30);
JTextArea gamemaintext;
TitleScreenHandler tsHandler = new TitleScreenHandler();
public static void main(String[] args)
{
DungeonGame21 DungeonGame2 = new DungeonGame21();
}
public DungeonGame21()
{
window = new JFrame ();
window.setSize(800, 600);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.getContentPane().setBackground(Color.BLACK);
window.setLayout(null);
window.setVisible(true);
con = window.getContentPane();
titelnamepanel = new JPanel();
titelnamepanel.setBounds(100, 100, 600, 100);
titelnamepanel.setBackground(Color.BLACK);
titelnamelabel = new JLabel("Dungeon Game 2");
titelnamelabel.setForeground(Color.WHITE);
titelnamepanel.add(titelnamelabel);
titelstartpanel = new JPanel();
titelstartpanel.setBounds(250, 400, 300, 50);
titelstartpanel.setBackground(Color.BLACK);
titelstartbutton = new JButton("Start");
titelstartbutton.setBackground(Color.BLACK);
titelstartbutton.setForeground(Color.BLACK);
titelstartpanel.add(titelstartbutton);
titelstartbutton.addActionListener(tsHandler);
titelstartbutton.setFont(normal);
titelnamelabel.setFont(titelnamefont);
con.add(titelnamepanel);
con.add(titelstartpanel);
}
public void gamescreen()
{
con.remove(titelnamepanel);
con.remove(titelstartpanel);
gamemaintextpanel = new JPanel();
gamemaintextpanel.setBounds(100, 100, 600, 250);
gamemaintextpanel.setBackground(Color.BLACK);
con.add (gamemaintextpanel);
gamemaintext = new JTextArea();
gamemaintext.setBounds(100, 100, 600, 250);
gamemaintext.setBackground (Color.BLACK);
gamemaintext.setForeground (Color.WHITE);
gamemaintext.setFont(normal);
gamemaintext.setLineWrap(true);
gamemaintextpanel.add(gamemaintext);
}
public class TitleScreenHandler implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
gamescreen();
}
}
}
This is a game I am making but so far I haven't gotten past the title screen because my start button doesn't work.
so I think it should work but it gives an error at the "public class TitleScreenHandler implements ActionListener" the error says "DungeonGame21.TitleScreenHandler is not abstract and does not override abstract method actionPerformed(ActionEvent) in ActionListener.
If anyone can say what is wrong please do help me hope this is the right subreddit to post this on.
Thank you!
4
u/PriorProfile Nov 22 '19
You're importing the wrong
ActionEvent.You're importing
javafx.event.ActionEventbut you really wantjava.awt.event.ActionEvent