• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.

Archived

This topic is now archived and is closed to further replies.

BMason

[java] Swing doesn't want to work in my browser....

0 posts in this topic

Hi. I was tasked with writing an applet for my programming class. This was basically my first time doing a "real" applet that did more than just a few lines on the screen. I did everything using the AWT components and it ran in the browser fine. Then I switched over to Swing (although there's not much of a difference, just got to add a "J" in front of everything ). Anyway, I rewrote it in Swing and compiled everything and when I loaded it into my browser it said "Class XXX" not found, where XXX was the name of my class that I referred to in the tag and was sitting in the exact same folder. I couldn't get it to work at all. So I tried to load it using the appletviewer and it loaded flawlessly with no problems (I made no changes to the files). I thought maybe for some reason when I installed IE5 it installed the java 1.1.1 runtime files on my system and overrode the 1.2.2 files, so I downloaded the 1.2.2 runtime files and installed them and it still doesn't run. I was hoping that someone might be able to look at my code and tell me what's wrong. Be wary that we're trying to consentrate on making everything as object-orientedly as possible, so there might be more classes than is really necessary here. But the actually program WORKS. It runs in the appletviewer with no problems, just not in my browser. I'm wondering if maybe my applet code is missing something that only the browser would require. Also, for all my applet-related objects I imported all the same stuff (java.awt.*, java.awt.Event.*, javax.swing.*) because this was my first time with a real applet and I wasn't entirely sure what I would need in each file at the time. Ok, here goes: (Oops, the HTML source loaded eventhough I used code... that's strange. I uploaded the html source file to my ftp server here: http://home.earthlink.net/~shaggy999/applet.html) My GuessApplet source (the actual applet):
import java.awt.*;
import java.awt.Event.*;
import javax.swing.*;

public class GuessApplet extends JApplet {

	RandomGame guessTheNumber = new RandomGame();
	appletGUI gui = new appletGUI(this);
	
	public void getNewGuess() {
	
		gui.updateOutput(guessTheNumber.nextGuess(Integer.parseInt(gui.getInput())));
		gui.dispGuesses(guessTheNumber.getGuesses());
	}

	public void startNewGame() {
	
		guessTheNumber.newGame();
		gui.dispGuesses(guessTheNumber.getGuesses());
	}
}
  
My GUI code:
import java.awt.*;
import java.awt.Event.*;
import javax.swing.*;

public class appletGUI {
	
	// JPanels that we add components to.
	private JPanel northPanel;
	private JPanel southPanel;
	private JPanel centerPanel;
	private JPanel eastPanel;
	
	// Components
	
		// Label Component
		private JLabel instructions;
		private JLabel totalGuesses;
		
		// Button Components
		private JButton getInputButton;
		private JButton newGameButton;
		
		// TextField Component
		private JTextField inputField;
		
		// TextArea Component
		private JTextArea outputField;
		
		// ScrollPane Component
		private JScrollPane scrollOutputField;
		
	// Action Listeners
	private ButtonListener buttonInputListener;
		
	
	public appletGUI(GuessApplet applet) {
		// Set up the Panels with a layout.

		initGUI(applet);
	}

	// This initializes the GUI for the applet.
	private void initGUI(GuessApplet applet) {
	
		// Initialize the Panels
		northPanel = new JPanel();
		southPanel = new JPanel();
		centerPanel = new JPanel();
		eastPanel = new JPanel();
		
		northPanel.setLayout (new GridLayout (1,2,3,3));
		southPanel.setLayout (new GridLayout (1,1));
		centerPanel.setLayout (new GridLayout (1,1,20,20));
		eastPanel.setLayout (new GridLayout (2,1,20,10));
		
		
		// Initialize the Label Components.
		instructions = new JLabel ("Guess a number between 1 and 100.");
		totalGuesses = new JLabel ("Total Guesses: 0");
		
		// Initialize the Button Components.
		getInputButton = new JButton ("Guess");
		newGameButton = new JButton ("New Game");
		
		// Initialize the TextField Component
		inputField = new JTextField (10);
		inputField.setEditable (true);
		
		// Initialize the TextArea Component
		outputField = new JTextArea (20, 30);
		outputField.setEditable (false);
		
		// Initialize the Scrollpane Component
		scrollOutputField = new JScrollPane(outputField);
		
		// Initialize the Button Listener and add it to the buttons.
		buttonInputListener = new ButtonListener(applet);
		getInputButton.addActionListener(buttonInputListener);
		newGameButton.addActionListener(buttonInputListener);
				
		// Add the Components to the panels.
		northPanel.add (instructions);
		northPanel.add (inputField);
		
		centerPanel.add (outputField);
		centerPanel.add (scrollOutputField);
		
		southPanel.add (totalGuesses);

		eastPanel.add (getInputButton);
		eastPanel.add (newGameButton);
		
		// Set up the ConentPane.
		Container contentPane = applet.getContentPane();
		contentPane.setLayout (new BorderLayout(10,10));
		contentPane.add (northPanel, BorderLayout.NORTH);
		contentPane.add (southPanel, BorderLayout.SOUTH);
		contentPane.add (centerPanel, BorderLayout.CENTER);
		contentPane.add (eastPanel, BorderLayout.EAST);

		applet.resize(450, 150);
		applet.setVisible(true);
	}
	
	public void updateOutput(String output) {
	
		String oldOutput = outputField.getText();
		outputField.setText(oldOutput + output + "\n");
	}
	
	public String getInput() {
	
		return inputField.getText();
	}
	
	public void dispGuesses(int guesses) {
		totalGuesses.setText("Total Guesses: " + guesses);
	}
}
  
My listener class:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class ButtonListener implements ActionListener {

	private GuessApplet applet;
	
	public ButtonListener (GuessApplet app) {
	
		applet = app;
	}
	
	public void actionPerformed(ActionEvent event) {
	
		if(event.getActionCommand().compareTo("Guess") == 0)
			applet.getNewGuess();
		else
			applet.startNewGame();
	}
}
  
My randomgame class:
import java.util.*;

public class RandomGame {

	Random numberGenerator;
	int theAnswer, totalGuesses;

	public RandomGame () {

		totalGuesses = 0;
		theAnswer = 0;
		numberGenerator = new Random();
		newGame();
	}
	
	public void newGame () {
		totalGuesses = 0;
		theAnswer = (int)(numberGenerator.nextDouble() * 100);
	}

	public String nextGuess (int guess) {
	
		String response;
		totalGuesses++;
		
		if (guess < theAnswer)
			response = "Your guess of " + guess + " was too low.";
		else if (guess > theAnswer)
			response = "Your guess of " + guess + " was too high.";
		else {
			response = "Correct! " + guess + " is the number!\nIt took you "
						+ totalGuesses + " tries!";
			newGame();
		}
		
		return response;
	}
	
	public int getGuesses() {
	
		return totalGuesses;
	}
}
  
Edited by - BMason on 5/4/00 11:40:05 PM
0

Share this post


Link to post
Share on other sites

Important Information

By using GameDev.net, you agree to our Terms of Use and Guidelines.