Generic RPG Game - Java Applet When Adding Subroutine

Jul 11, 2014

I am trying to design a generic RPG game. The issue I am having right now is in my Class I have a subroutine (think that is the correct term) that is basically set up to hold a series of Print Statements. I am really just trying to get some Values that are stored within the Applet, have them assigned to their correct variables and then returned in the print statement. Yet, when I run the applet it just pops up the Applet blank and gives me a long list of errors and I really don't understand when they mean.

Here is the code:

The Class

public class CharacterSheet {
final String NL = System.getProperty("line.separator");
public String characterName;
int playerStr;
int playerCha;

[Code] ....

And the error messages:

Exception in thread "AWT-EventQueue-1" java.lang.NullPointerException: String is null
at sun.java2d.SunGraphics2D.drawString(Unknown Source)
at TFApplet.paint(TFApplet.java:15)
at javax.swing.RepaintManager$3.run(Unknown Source)
at javax.swing.RepaintManager$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)

[Code] .....

View Replies


ADVERTISEMENT

Adding Highscore To Txt File In Applet Game

May 13, 2014

I am making a breakout like game in an applet for fun. i have the game working but for the last part of the game i want to make it so each time the game is played it adds the score the player. however, the code that i wrote does not work at all. Here is the code for the game.

import java.applet.Applet;
import java.awt.Color;
import java.awt.Event;
import java.awt.Graphics;
import java.awt.Rectangle;

[Code] ......

View Replies View Related

Adding Any Type Of Data To A Generic List?

Aug 28, 2014

Is this the proper way to add to a generic list? My code works just fine, but I got this feeling that there might be some kind of flaw in it or something. Is this pretty much the basic way to add any type of data to a generic list?

import java.util.LinkedList;
public class ListOfGeneric<E> {
private LinkedList<E> myList;

ListOfGeneric(){
myList = new LinkedList<E>();

[Code] ....

View Replies View Related

Java Text Adventure Game - Adding Characters

Apr 14, 2014

I am making a java text adventure and i am trying to add characters to it. I wrote it exactly the same as i wrote the items class (which works fine) but for some reason the character class keeps getting a null pointer exception when it gets to line 140 in the room class

characters.add(c);
game class
import java.util.ArrayList;
import java.util.HashMap;
/**
* Game class for Free Willy Five: an exciting text based adventure game.
*

[Code] ....

View Replies View Related

Adding Applet To A JFrame?

Mar 29, 2015

How do i add my applet to a JFrame? (Ex. When i click on a Menu Item on my frame, i need the applet to be displayed.

The code of my Frame:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

[Code].....

View Replies View Related

Adding Applet Intro A Frame

Mar 17, 2015

Is there a way to add an applet intro a JFrame ? more exactly I have a frame and when a button is pressed it should add to the frame the applet . Here is some sample code for better understanding :

public class principal implements ActionListener{
 public static void main(String[] args) {
// code
JButton b1=new JButton("Start");
b1.setLocation(0,height-60);
b1.setSize(width,20);

[Code] ....

View Replies View Related

Printing Number In Reverse With Subroutine

Feb 21, 2015

The code below is running, but when I enter the numbers it shows up with what is just below.

----jGRASP exec: java ReverseOrder
 
Please enter 5 integers with no spaces in between: 12345
 
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 5
at java.lang.String.charAt(String.java:646)
at ReverseOrder.reverseDigits(ReverseOrder.java:30)
at ReverseOrder.main(ReverseOrder.java:15)

[code]....

View Replies View Related

Generic Method In Generic Class

Jul 23, 2014

1 import java.util.ArrayList;
2 import java.util.List;
3
4 public class MyList<E> {
5
6 public List<E> list;
7 public int length;

[code]...

I am trying to define a class MyList, which i just a wrapper around an ArrayList, no real purpose, just for the sake of learning Generics. Idea here is that I create a parameterized class, MyList<E>, which holds a parameterized instance var of type List<E>. I have an add method which adds an element of type E to the List<E>. If I create an instance of MyList, call it 'm', for some reason when I try to call a method on that instance the compiler complains that 'm' cannot be found.

View Replies View Related

Adding Items To The Game

Jan 4, 2015

I made my items class and I am storing my item as a String array to list them all and what I want to be able to do is type pickup, have the game read my location and display the items that are avaible to pickup at current location then type the item and store it in my playerInventory. Then, have it check the slot if it is doesn't equal null go to next.

Use a boolean value of 0 = false and 1 = true. then, have it check if the inv array = 1 or 0. if 1 go to next inv. If all are full then, ask player if they would like to replace an item. Use a 2d array for storage for slots and true or false value.

Here is my code

Player.java
package com.PenguinGaming;
import java.util.Random;
import java.util.Scanner;
public class Player {
public void User(){
Commands commands = new Commands();
Map map = new Map();

[Code] .....

View Replies View Related

Generic Types In Java

Apr 1, 2014

I am trying to understand the concept of Generics in java. In the introduction to Generic Types, this example is given:

Java Code: public class Box {
private Object object;
public void set(Object object) { this.object = object; }
public Object get() { return object; }
} mh_sh_highlight_all('java'); "Since

Since its methods accept or return an Object, you are free to pass in whatever you want, provided that it is not one of the primitive types." - I understand this.But then it has been changed to a generic class:

Java Code: /**
* Generic version of the Box class.
* @param <T> the type of the value being boxed
*/
public class Box<T> {
// T stands for "Type"
private T t;

public void set(T t) { this.t = t; }
public T get() { return t; }
} mh_sh_highlight_all('java'); "

As you can see, all occurrences of Object are replaced by T. A type variable can be any non-primitive type you specify: any class type, any interface type, any array type, or even another type variable."We can use any type in place of an Object, because Object is a superclass of all classes. But T (or any other class) is not a superclass of all classes. So how do we justify any class being used in place of a random T or any other class?

View Replies View Related

Tic Tac Toe - Adding Draw System / Game Over

Jul 31, 2014

I have been trying to add a draw system to my code so far once all the boxes have been taken it does not tell the player its a draw game over. I have tried and deleted some code but I have commented some stuff that did'nt work at the bottom and also the X's and O's can be replaced in the same spaces?

import java.util.*;
//import for scanner
public class NoughtsAndCrosses {
public static int row,col; //integer for rows and columns
public static Scanner scan = new Scanner(System.in); //Scans the program
public static char[][] board = new char [4][4]; //Characters for the board set out 4/4

[Code] .....

View Replies View Related

Adding A Tick Rate To Game To Unlock FPS?

Nov 25, 2014

I need to add a tick rate so i can unlock the FPS. Here's the main render class/update class/game loop class.

Added back the formatting

Java Code:

package com.educodes.Main;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.image.BufferedImage;

[Code] ....

View Replies View Related

Text Based Game Adding Items

Apr 11, 2014

I am trying to make a text based game. the game has been working perfectly setting up the rooms, first couple of commands, and running it. I am now trying to add items to it but every time it try to run the game it returns :

java.lang.NullPointerException
at Room.addItem(Room.java:107)
at Game.createRooms(Game.java:133)
at Game.<init>(Game.java:28)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

[Code] .....

Here are the classes that matter for this particular situation

import java.util.HashMap;
public class Item
{
private HashMap<String, Item> itemList;
private String name;
private String itemDescription;

[Code] ....

I know that it is the line

itemList.put(item.getItemName(), new Item(item.getItemName(), item.getItemDescription()));

In the game class that is causing the nullpointer exception i just really cant figure out why that keeps happening and how to add the values correctly....

View Replies View Related

Breakout Game - Adding Background Picture

Nov 16, 2014

I've been trying to post background picture for a long time in java. I've just finished writing breakout game and I want it to be more special and full of interesting things. I want to upload picture in java. I write

GImage image= new GImage("LEONARDO.JPG");
image.setSize(50,50)
add(image,200,400)

The size of the whole screen is 400,600.

View Replies View Related

TicTacToe Game - Adding Crosses And Naughts To Empty String

Jul 5, 2014

I have an empty string and I want to add to it crosses and naughts. I want to simulate a board of TicTacToe game. My goal is print out 5 strings like this : "xox xxx oxo". There are 3 groups of symbols separated with a space. The crosses and naughts are filled randomly.

Random rand = new Random();
char[] characters = new char[] { 'x', 'o' };
int numOfTimes = 0;
while (numOfTimes < 5)
{
String board = "";
String space = " ";
for (int group = 0; group < 3 ; group++)

[Code] .....

Why my code doesn't output the desired result ?

View Replies View Related

Swing/AWT/SWT :: BorderLayout - Adding Multiple Video Game Oriented Objects Such As Sprites To JFrame?

May 24, 2014

I decided to write a small Java program to experiment around with BorderLayout, because I'm developing a Java game and I need to have 2 objects placed in a single JFrame at the same time, and everyone I asked said I need BorderLayout to do that.Before you answer: Also, is using BorderLayout the best option for adding multiple video game oriented objects such a sprites to a JFrame?

So the Java program I wrote is supposed to place a JButton on the JFrame and ALSO place a graphic component (a rectangle in this case). The problem is, only the button shows up, as can be seen in the image link below: URL....

Here is the code:

**main.java** --> The main method class + JFrame/JPanel/JButton constructor
import java.awt.BorderLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class main {

[code]....

View Replies View Related

Java Applet Error

May 26, 2012

I'm using jdk7 and I get this error when I compile Exception in thread "main" java.lang.Error: Unresolved compilation problem: at First.main(First.java:16)

Java Code:

import javax.io.*;
import javax.awt.*;
import javax.lang.*;
import javax.applet.*;
import javax.net.*;
import javax.util.*;
import javax.swing.JApplet;
import javax.swing.JFrame;

public class First extends JApplet {

public void init() {
getContentPane().add(new JLabel("Applet!"));

[code]....

View Replies View Related

Java Online Applet For Survey

Nov 2, 2014

For a project I have to create an online survey, I cannot use a per-made online survey system because I have really specific needs that no pre-made system can satisfy, so my idea would be to create it in java and store the data in some simple text file, which are fairly easy to work with in java. My question is, is it possible, and if yes how difficult is it, to put the entire thing online? What worries me isn't putting the applet itself online, but the text files that should collect the data, I already have the website to host it.

View Replies View Related

HTML Parameters To Java Applet

Nov 22, 2014

I am trying to pass parameters from he following HTML file to an applet. the applet is not initializing and the iam getting the following error on the console. I also have both the html file and and the java applet under the same source file in eclipse.

java.lang.NumberFormatException: null
at java.lang.Integer.parseInt(Integer.java:542)
at java.lang.Integer.parseInt(Integer.java:615)
at applet.DisplayMessage.init(DisplayMessage.java:16)
at sun.applet.AppletPanel.run(AppletPanel.java:434)
at java.lang.Thread.run(Thread.java:745)

Here is the html file

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>

[Code] ....

View Replies View Related

Root Function In Java Applet

May 12, 2014

I like to know how to write root function in java applet. I know it in java function. Ex:

import java.lang.*;
public class Maths {
public static void main(String[] args) {
// get two double numbers numbers
double x = 9;
double y = 25;
// print the square root of these doubles
System.out.println("Math.sqrt(" + x + ")=" + Math.sqrt(x));
System.out.println("Math.sqrt(" + y + ")=" + Math.sqrt(y));
}
}

working fine. but If I tried in applet it's not working. Ex:

evap_trans = 0.0135 * SRAD * ( TMEAN + 17.78) * Math.sqrt(TMAX - TMIN);

If I execute above said formulae with out "Math.sqrt" results are ok. If I used then results shows ZERO.

View Replies View Related

Cropping Image In Java Applet

Apr 30, 2012

I have an applet coded to recieve an image and upon mouse press i wish it to be cropped. For some reason its not implementing, I just think my brain is no longer doing what i think it should be or something, along those lines.

Code below

import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.image.CropImageFilter;
import java.awt.image.FilteredImageSource;
import java.awt.image.ImageFilter;
import java.awt.image.ImageProducer;
public class CropImg extends Applet implements MouseListener

[Code] .....

View Replies View Related

Java Applet - Background Color Is Not Being Set

Nov 23, 2014

I am trying to go about making this applet a bit different then normal. The issue I am having is it is drawing an applet but, not the right dimensions, it's able to be resized, lastly the background color is not being set. I mean, I suppose I could call paint() and just draw it out but, I read that I could make the applet pop out to the dimensions I would like. None of this is working sadly.

package com.powder.game;
import javax.swing.*;
import java.applet.*;
import java.awt.*;
import java.util.*;
import java.io.IOException;
import java.lang.Math;

[code]...

my exact question is can I rewrite the applet to make a pop out window and should I just call paint()?

View Replies View Related

Embed Java Applet In HTML

May 8, 2013

When I embed java applet in html the "ClassNotFoundException" message appear to me, how to overcome this ....

View Replies View Related

Java Applet - Sharing Variables With Another Class

Mar 29, 2015

I have An Issue With My Java Applet. Im Trying To Share My Variables With Another Class, But Its Not Working.

Class 1

package com.Tobysmith10.game.main;
import java.applet.Applet;
import java.awt.Graphics;
public class Game extends Applet{
public void init(){
 setSize(850,480);
 public void paint(Graphics g){
 g.fillOval(x,y,20,20);
}
}

Class 2

package com.Tobysmith10.game.main;
import java.applet.Applet;
public class gameLoop extends Applet implements Runnable{
public int x, y;
public void run(){
while(true){
x = 100;
y = 100; 
}
}
}

So im sharing the x and y variables with the Class 1 , but I get yellow lines under it and when i run the program, it crashes, how do I get class 1 to recognize the variables from class 2 ?

View Replies View Related

Java Applet - Open / Zoom In / Out Of Image

Jul 29, 2014

Working on an assignment for a class: Create a DESKTOP application that allows you to open an image file and enables you to zoom in on or out from an image. I believe all I need is too create an open button to open the actual image file, instead of the html link, this code is an example that the teacher provided.My current code:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.net.URL;
import java.io.*;
import javax.imageio.*;

[code]....

how to add an open file button so I can search for the file and then open it into my program.

View Replies View Related

How To Create Sports Tables Java Applet

Jun 1, 2014

I've been using a Java applet for sports tables.It has been very useful for me. However, the recent developments from the people at Oracle have made this program impossible to use. The point is that I need this program and I need it fast.I've been in touch with the person who once created this applet and he has no intentions at all to upgrade it or do anything to make it function. How to make the program works with their new updates.

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved