Results 1 to 3 of 3
Like Tree1Likes
  • 1 Post By pbrockway2

Thread: Swing GUI ERROR?

  1. #1
    dharav is offline Member
    Join Date
    Dec 2011
    Posts
    28
    Rep Power
    0

    Question Swing GUI ERROR?

    I am trying to create gui in swing but i have no idea why is here a error in the program The error is about


    Exception in thread "main" java.lang.Error: Unresolved compilation problems:
    The method add(PopupMenu) in the type Component is not applicable for the arguments (JButton)
    The method add(PopupMenu) in the type Component is not applicable for the arguments (JButton)
    The method add(PopupMenu) in the type Component is not applicable for the arguments (JButton)
    Action cannot be resolved to a type

    at Samurai.Samurai.main(Samurai.java:27)
    is there is some thing wrong with the frame.add(); i think please have a look


    Java code:

    package Samurai;
    import java.util.Scanner;
    import javax.swing.JButton;
    import javax.swing.JPanel;
    import javax.swing.JFrame;

    import java.awt.Component;
    import java.awt.event.*;
    public class Samurai {

    /**
    * @param args
    */
    public static JFrame frame= new JFrame ("Samurai Game By Dharav");
    public static void main(String[] args) {


    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
    frame.setSize(300,300);
    JPanel pane1=new JPanel();
    Component panel;
    frame.add(panel);
    JButton button=new JButton("Start");
    JButton button2=new JButton("Quit");
    JButton button3=new JButton("Instructions");
    panel.add(button);
    panel.add(button2);
    panel.add(button3);
    button.addActionListener(new Action());
    button2.addActionListener(new Action2());
    button3.addActionListener(new Action3());
    }

    static class Action3 implements ActionListener{
    public void actionPerformed(ActionEvent e){
    frame.setVisible(false);

    System.out.println("Follow the instructions on screen.\n When asked for a answer please use Y for yes or N for no. \n Also to explore Press Enter.")

    }
    }
    static class Action2 implements ActionListener{
    public void actionPerformed(ActionEvent e){
    frame.setVisible(false);
    System.exit(0);
    }

    //VARIABLES ONLY SECTION

    String nameofwarrior,cityname,hit,faith;

    int nameofcity,cityexplore,i,k,villan,boss;

    int Mob1[]={1,1},Player[]={0,0},ninjalord[]={24,4};
    String astricks[]= {"*","**","***","****","*****","******","*******", "********","*********","**********","***********", "************","*************","**************","* **************","****************","************** ***"};
    String chooseyourdestiny[]= {"C","H","O","O","S","E"," ","Y","O","U","R"," ","D","E","S","T","I","N","Y"};


    //VARIABLES ONLY SECTION ENDS

    Scanner keyboard = new Scanner (System.in);

    System.out.println("Hey The Ol'e Wise Man Wishes to Know your NAME");

    nameofwarrior=keyboard.nextLine();

    System.out.println("*.**.* YOU ARE THE CHOOSEN ONE "+nameofwarrior+" *.**.* \n DESTINY AWAITS YOU ON YOUR JOURNEY ");
    try
    {
    Thread.sleep(1000); // a simple timer of 1 second (1000 milliseconds)
    }
    catch (InterruptedException e)
    {}
    System.out.println("You are Choosen TO be the one");
    try
    {
    Thread.sleep(3000); // a simple timer of 1 second (1000 milliseconds)
    }
    catch (InterruptedException e)
    {}
    System.out.println("Please Wait Prepare your self Relax You are About to become a Warrior "+nameofwarrior+", in the 15th Century");
    try
    {
    Thread.sleep(7000); // a simple timer of 1 second (1000 milliseconds)
    }
    catch (InterruptedException e)
    {}
    for (i=0;i<=16;i++)
    {

    System.out.println(astricks[i]);

    try
    {
    Thread.sleep(100); // a simple timer of 0.1 second (100 milliseconds)
    }
    catch (InterruptedException e)
    {}

    }
    }}
    Last edited by dharav; 01-18-2012 at 06:46 AM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Swing GUI ERROR?

    That's a héll of a lot of code and no error messages posted that I can see.

    I recommend that you limit the amount of code so that it's a reasonable amount to ask a volunteer to review, preferably an SSCCE (check the link). Also post any error messages you have and indicate which lines are causing the errors.

  3. #3
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Swing GUI ERROR?

    And please contribute to the thread rather than just dumping the code and disappearing. In your earlier thread (if statements Error?) those who replied got no feedback.

    It's a good idea to work one small step at a time so that errors do not build up. And have a small, reasonable goal in mind. That way you can explain what you are trying to do and everyone can address some particular problem. Some explanation of a problem really is necessary. Do your best: people will ask if they don't understand.
    Fubarable likes this.

Similar Threads

  1. Error displayed during run in swing tree pgm
    By Bibin in forum New To Java
    Replies: 3
    Last Post: 12-24-2011, 10:39 PM
  2. Netbeans Swing Error ?
    By sysout in forum NetBeans
    Replies: 1
    Last Post: 08-24-2009, 04:25 AM
  3. Error trace in swing application
    By dnyan123 in forum AWT / Swing
    Replies: 15
    Last Post: 10-21-2008, 02:50 PM
  4. Error using Swing
    By arpitvavadia in forum AWT / Swing
    Replies: 2
    Last Post: 09-08-2008, 06:16 PM
  5. Replies: 1
    Last Post: 08-01-2007, 06:10 AM

Posting Permissions

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