Я создал java-программу с использованием Eclipse и пытаюсь запустить ее в Интернете (это простая игра). У меня есть файл .class, работающий над ним, и программа работает без проблем. У меня проблемы, когда я пытаюсь запустить его на веб-сайте. Я использовал следующий код, чтобы попытаться запустить его как апплет не повезло:java class на сайте
<html>
<body>
<applet
code="Handler.class"
codebase="AlamoAdventure/"
name="Alamo Battle Adventure"
width="680"
height="509"
archive="Handler.jar"
id="Alamo Battle Adventure" >
</applet>
</body>
</html>
Когда я Гото на сайте он говорит мне нажать на апплет для деталей. Когда я это делаю, я получаю всплывающее окно, которое дает мне RuntimeException: java.lang.reflect.InvocationTargetException
Каковы шаги, которые мне не хватает, чтобы запустить это? И Handler.class, и Handler.jar находятся в одном месте.
Основной код меню Java выглядит следующим образом:
/*
* Main Menu is the start up window that is displayed when the program starts. It has one button, "Start Game", and a randomly
* selected picture from a batch of 6.
* 0->23
*/
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.image.BufferedImage;
import java.awt.image.ImageObserver;
import java.util.Random;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
public class MainMenu extends JFrame
{
private JButton sGame; //The "Start Game" Button
private FlowLayout layout; //Layout of the window
private ImageIcon image; //The images
public MainMenu()
{
super("ABA:Main Menu"); // Title of Window
JPanel right = new JPanel();
JPanel left = new JPanel();
left.setLayout(new BoxLayout(left, BoxLayout.LINE_AXIS));
add(left);
right.setLayout(new BoxLayout(right, BoxLayout.PAGE_AXIS));
add(right);
sGame = new JButton("Start Game");
left.add(sGame);
left.add(Box.createRigidArea(new Dimension(10,0)));
right.add(left);
Images image = new Images();
right.add(image);
ButtonHandle handle = new ButtonHandle();
sGame.addActionListener(handle);
} // end Button const.
/*
* When the button is pressed it will call the functions to start the new windows and storyline
*/
private class ButtonHandle implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
if (event.getActionCommand().contentEquals("Start Game"))
{
int[] i;
int n, ch, c;
i = new int[3];
Text story = new Text();
int k = 10;
i = Options.Option1(k);
n = i[0];
ch = i[2];
c = i[1];
/*
* Debugging technique to allow proper pathing for map and story line
*/
System.out.print(n);
System.out.print(c);
String option1;
String option2;
String option3;
String storyMode;
String[] a;
a = new String[2];
a = Choices.getChoice(n);
storyMode = story.getText(ch,n);
option1 = a[0];
option2 = a[1];
option3 = a[2];
Button call = new Button(option1, option2, option3, storyMode, n);
call.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
call.setSize(680,509);
call.setVisible(true);
MainMenu.this.dispose();
}
}
}
/*
* Class to render the 6 random pictures on the Main Menu under the "Start Game"
*/
class Images extends JPanel
{
private ImageIcon picture;
private Random generator = new Random(); // Generator for random numbers
private String[] images = {"1.JPG", "2.JPG", "3.JPG",
"4.JPG", "5.JPG", "6.JPG"}; // These are the paths to the 6 pictures that will be randomly called
public Images()
{
int randomN = generator.nextInt(images.length); // Random number between 0 and 5
picture = new ImageIcon(getClass().getResource(images[randomN])); // initializes the picture and selects the path from the randomN
}
protected void paintComponent(Graphics g)
{
super.paintComponents(g);
Dimension d = getSize();
g.drawImage(picture.getImage(),0,0,d.width, d.height, null);
}
public Dimension getPreferredSize()
{
return new Dimension(picture.getIconWidth(), picture.getIconHeight());
}
}
}
Вы уверены, что класс, который вы написали, не входит в комплект поставки? – aksappy
И где это URL снова? BTW - Что такое объявление класса в коде? –
http://www.kluckhohndesign.com/test –