-
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)
{}
}
}}
-
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.
-
Re: Swing GUI ERROR?
And please contribute to the thread rather than just dumping the code and disappearing. In your earlier thread (http://www.java-forums.org/new-java/...nts-error.html) 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.