Results 1 to 4 of 4
  1. #1
    knightwriter is offline Member
    Join Date
    Nov 2011
    Posts
    49
    Rep Power
    0

    Default Need help with gui

    I'm trying to create a program. From the main method I'm using constructors to call another class, (IntoScreen Class), that holds a JFrame and JButton. That works fine at runtime, however I want the button to display a message box stating, "Hello, how are you?", I'm getting an error stating that that the HandlerClass, which is inside of the Introscreen Class is not abstract. Here is the code for the Introscreen Class with the JFrame and JButton included. Below that I will show the main method in case I'm doing something wrong there.

    package PaperRPG;

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;


    public class Introscreen {


    public void Intro(){
    JFrame Intro = new JFrame();
    Intro.setSize(900, 800);
    Intro.setVisible(true);
    Intro.setLayout(new FlowLayout());
    Intro.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
    JButton mainButton = new JButton("Introduction");
    Intro.add(mainButton);
    HandlerClass handler = new HandlerClass();
    mainButton.addActionListener(handler);


    }
    public class HandlerClass implements ActionListener{
    public void ActionPerformed(ActionEvent event){
    JOptionPane.showMessageDialog(null,"Hello how are you.");
    }
    }

    }

    Now I will show my main method with the constructor to call the JFrame.

    package PaperRPG;

    import javax.swing.*;
    import java.awt.*;

    public class MainScreen extends JFrame{


    public static void main(String[] args) {
    //Need to call a class constructor and then call the method constructor
    Introscreen Introduction = new Introscreen();
    Introduction.Intro();


    }


    }

    Any help will be appreciated.
    Thanks!!

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    6

    Default Re: Need help with gui

    Please use the code tags...you currently have 28 posts, so I would presume you have been told this already.

    ActionPerformed != actionPerformed
    And for what its worth, using the @Override annotation would have given you a more explicit and informative error message.

  3. #3
    knightwriter is offline Member
    Join Date
    Nov 2011
    Posts
    49
    Rep Power
    0

    Default Re: Need help with gui

    Thanks doWhile. I actually have not been told to use the code tags. I have just found out what those do and will do so from now on.
    I'm still very new to gui coding and Java, so the @Override annotation doesn't mean anything to me yet. I will do some reading on that. I will also try and fix my syntax error in hopes that fixes the problem.

  4. #4
    Sebasnr is offline Member
    Join Date
    Dec 2011
    Posts
    8
    Rep Power
    0

    Default Re: Need help with gui

    If you use an IDE like NetBeans or Eclipse, it'll tell you how to solve this kind of errors, just press on the bulb (in NetBeans is a bulb). The explanation of this is that you were tying to implement an Interface without implement all the methods (as doWhile pointed out, Java is case sensitive)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •