I have staired and staired at this but I can't see why it's throwing an error regarding static in the main method.
At this point }
public static void main(String[]args) {
new Bourreau();
}
java.lang.NoSuchMethodError: main
Exception in thread "main"
The method main cannot be declared static; static methods can only be declared in a static or top level type
Could anyone please show me where i'm going wrong before I throw myself and my pc out of a window!
import java.awt.*;
import java.awt.event.*;
import java.util.Random;
import javax.swing.*;
public class Bourreau extends JFrame implements ActionListener {
public static final long serialVersionUID = 1L;
// Variables
JFrame window = null;
JTextField Box = new JTextField(20);
// JButton Clic = new JButton("Clic");
JLabel labelGuess;
JPanel panelGuess;
JPanel panelIn;
Bourreau2 theBourreau;
String[] words = { "cheese", "onion", "beach", "ball", "sun" }; // Array of
// words to
// guess
String word;
static StringBuffer guess = new StringBuffer();
int random;
static boolean found = false;
static int Counter = 0; // Counts the turns taken
// Word and string length loop
public Bourreau() {
Random r = new Random(); // Assigns integer r to random
random = r.nextInt(words.length); // Assigns the value of random
word = words[random]; // String word chooses words at random
// System.out.println(word);
for (int i = word.length(); i > 0; i--) { // For loop that checks string
// word length add the
// correct number of dashes
guess.append('-');
}
// Clic.addActionListener(this);
theBourreau = new Bourreau2();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setTitle("Bourreau");
labelGuess = new JLabel("", JLabel.CENTER);
panelGuess = new JPanel();
panelIn = new JPanel();
panelGuess.add(labelGuess);
labelGuess.setText(guess.toString());
panelIn.add(Box);
add(theBourreau, BorderLayout.NORTH);
// add(Clic, BorderLayout.SOUTH);
// add(panelGuess, BorderLayout.CENTER);
add(panelIn, BorderLayout.SOUTH);
pack();
setVisible(true);
/*
* JOptionPane .showMessageDialog( window,(
* "Please enter a letter and press enter, continue until you solve the word.\n\nIf the letter is in the word a position on the line will be taken.\n\n"
* )); window.setVisible(false);
*/
KeyListener tap = new KeyListener() { // Allows keyboard input
public void keyPressed(KeyEvent e) { // Listens to the keyboard
// input
if (e.getKeyCode() == 10) {
actionPerformed(null);
// theBourreau.draw();
}
}
public void keyReleased(KeyEvent e) {
// TODO Auto-generated method stub
}
public void keyTyped(KeyEvent e) {
// TODO Auto-generated method stub
}
public static void main(String[]args) {
new Bourreau();
}
public void actionPerformed(ActionEvent e) {
if (e == null) {
// if (e.getSource() == Clic)
}
char s = Box.getText().charAt(0); // Text field box to get
// character from the first
// letter charAt(0)is the
// first place
for (int i = 0; i < word.length(); i++) {
if (word.indexOf(s, i) >= 0) {
guess.setCharAt(word.indexOf(s, i), s);
}
}
if (!(word.indexOf(s) >= 0)) // If the guess is not in the index
Counter++;
if (word.compareTo(guess.toString()) == 0)
; // Compares the guess to the string words
// panelGuess.repaint();
theBourreau.draw();
}
};
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
}
}

New Topic/Question
Reply



MultiQuote








|