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.
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)
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);
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();
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
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....
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)
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. *
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++)
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 {
So this is probably pretty simple but I can't seem to figure it out. My teacher wants us to write a code that scans a text file, then outputs some text based information AND displays an applet bar graph of the data sorta like this for the text:
and then an applet thats the same info just a little more graphic. My code interprets the input well, but when i try to make an applet output, the code basically forgets all of my variables and starts anew (when i just state the public static graphic (paint) class after everything) OR it refuses to scan the input file (if i switch the public class from main.....throw ExceptionIO to just public class graphic(paint))
Also, as a side note, any way to have java automatically determine how many separate lines there are in a text file without me having to manually count them.
import java.util.Scanner; import javax.swing.JApplet; import java.awt.*; import java.io.*; public class Project2 extends JApplet {
I compiled the applet, then put the applet in an HTML file using notepad and saved the html file in the right place for it to run correctly. The HTML file runs smoothly, but then it only shows the scrollbar part of my applet, and not the images or any text...
Why is This?????
Java Code:
import java.awt.*; import java.applet.Applet; import java.awt.event.*; import javax.swing.ImageIcon; public class Temperature_Convert extends Applet implements AdjustmentListener { private Image temp; private Scrollbar bar; private int old, newtemp = 0;
I have devised a simple program that reads a file and then adds up al the integers in the file and print the result, for example if the file had the numbers 1 2 3 4 5 6 7 8 9 10 then the program would print 55
However i have trouble when non integers are put into the file for example if it was 1 2 3 string 4 5 6 test 7 8 9 10
then i get:
Exception in thread "main" java.util.InputMismatchException at java.util.Scanner.throwFor(Scanner.java:840) at java.util.Scanner.next(Scanner.java:1461) at java.util.Scanner.nextInt(Scanner.java:2091) at java.util.Scanner.nextInt(Scanner.java:2050) at Week7.Task3.filereader(Task3.java:25) at Week7.Task3.main(Task3.java:14)
my code is as follows
package testing;
import java.util.*; import java.io.File; import java.io.IOException; public class summingInts { public static void main(String[] args) throws IOException { Scanner textfile = new Scanner(new File("intSum.txt"));
i'm trying to add new value (string type) in an existent file.say that we have a .txt file which contain "mario"...i ask to the user a new name, and he write for expample "tony", now i want append the word "tony" in the existent file in this way: Iwrote this code:
first is saved next to the value existing. why? maybe because the program does not check if there is a string in the file?but I do not think. because otherwise it would happen with any name that is not entered in an odd position.
Every time i try and add a new word to personalDictionary, it only replaces the first index. In my personalAdd method i had tried to add a running count to advance the position it would be saving in but it doesn't seem to be working correctly...
Java Code:
import java.util.Arrays; import java.util.Scanner; import java.io.File; import java.io.PrintWriter; import java.io.FileNotFoundException; public class SpellingChecker
I need to write a program that will let a user input name, age, email, and cell phone number, and commit the input to a text file. They need to add multiple entries. I figured out how to create the file and write to it, but when the user enters a second set of information, the first is overwritten. How can I make the file be added to instead of overwritten? The following is my code:
try { FileWriter writer = new FileWriter("ContactInformation.txt"); BufferedWriter bw = new BufferedWriter(writer); nameTextField.write(bw); bw.newLine();
I've added a small program that reads from a .txt file to the windows 8 startup folder using a .bat file ... The problem I have Is I've used relative paths for text files In the program and It doesn't work unless I change them to absolute paths.
The .bat file Is basically java -cp[absolute path to program directory] ReadAFileApp . Is there something (most likely yes!) I'm missing here ?
I'm supposed to add characters to a stack and pop them once the adjacent delimiter is read in from a text file. Moreover, program is supposed to print out the incoming text from the file, but stop when the applicable delimiter is not on top of the stack. As in, a '[' doesn't have a ']'.
I've got the program so it can pop and add to the stack correctly, and stops adding at the correct time, but I cant seem to get it to stop printing. I know a switch statement method in another class seems obvious, but I was trying to practice nested loops.
This is the main program:
import java.io.*; import java.util.Scanner; import java.io.IOException; import java.util.Stack; public class DelimiterChecker { public static void main(String [] args) throws IOException {
I am having some trouble with a Java program. I have a txt data file, which I will display, that I need to add into two separate arrays. The text file is 8 lines long that is supposed to go into two separate 4x4 matrices. A little background info on this program, reads in two arrays, compares them and outputs the largest elements of the same index and outputs them in a separate array. I somehow cannot seem to figure out how to do this. My code is below:
I am having trouble adding numbers read from a file with BufferedReader, using Tokenizer to split the numbers up by " " - space and adding them to an adjacency matrix.Below is the text file and my code, that I have at the moment.
I trying to make a file browser but when i try to add item to a FlowPane through me an error at runtime, look at this code if i add label with imageView when there are more than x ítem the error appear.
But if i add the label and the imageView alone the error didn't show. Ihave folder in my pc with more than 1200 file and the error always appear. Is there a way to make a flowpane or tilepane hold enough items?