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


ADVERTISEMENT

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 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

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

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

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

Embed HTML File Into Applet Java File

Jan 18, 2014

I want to know can we put the data of html file example

<html>
<body><applet code="classname" width="100" height="100">
</applet>
</body>
</html>

into my Applet's java file it can be done i have read it somewhere and have also implemented it ..... but now unable to memorize it

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

Scanning Input File Then Running Applet

Oct 14, 2014

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:

Sample Bar Graph

1-10 |*****
11-20 |******
21-30 |**
31-40 |*
41-50 |***********
51-60 |******
61-70 |********
71-80 |***
81-90 |****
91-100 |****

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 {

[Code] ....

View Replies View Related

Applet Doesn't Run Complete In HTML File

Aug 7, 2014

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;

[code]....

View Replies View Related

Program For Adding One Text File Into Zip File Without Extracting

Apr 9, 2015

java code for adding one text file into the zipped file without extracting It is possible in java code ?

View Replies View Related

Adding Integers From File But Not Letters

Dec 4, 2014

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"));

[code]....

View Replies View Related

Adding String Line To Existent TXT File

Feb 7, 2015

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:

Java Code:

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

[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.

View Replies View Related

Adding Strings To Array And Writing To File

Apr 10, 2015

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

[Code] ....

View Replies View Related

Adding User Input To File - Information Overwritten?

Dec 8, 2014

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();

[Code] ....

View Replies View Related

Adding Java Program To Windows Startup Using Bat File

Jan 19, 2015

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 ?

View Replies View Related

Loop That Stops Printing A File And Adding To Stack

May 6, 2015

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 {

[Code] ......

Moreover, the file I'm reading for is simply:

{
System.out.println(1)
System.out.println(2)
System.out.println(6 <-------------missing delimiter
System.out.println(7)
}

View Replies View Related

Adding Data File Into Two Separate 2D Arrays In Java

Apr 27, 2014

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:

Data File:

2 7 6 4
6 1 2 4
9 7 2 6
8 3 2 1
4 1 3 7
6 2 3 8
7 2 2 4
4 2 3 1

Code:

public class prog465a {
public static void main(String[] args) {
Scanner inFile = null;
try {
inFile = new Scanner(new File("prog465a.dat.txt"));

[Code] .....

View Replies View Related

Unable To Read Input File When Adding Pictures To A JFrame

Aug 25, 2014

i've tried changing the path 10000 times. idk if its wrong in the code.

Java Code: import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

[Code]...

View Replies View Related

Reading In A File With BufferedReader / Using Tokenizer For Adding Into Adjacency Matrix

Mar 6, 2015

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.

0 1 0 0 1 1 0 0
1 0 0 0 0 1 1 0
0 0 0 1 0 0 1 0
0 0 1 0 0 0 0 1
1 0 0 0 0 1 0 0
1 1 0 0 1 0 0 0
0 1 1 0 0 0 0 1
0 0 0 1 0 0 1 0

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.StringTokenizer;
public class Foo
{
@SuppressWarnings("null")
public static void main(String[] args) throws Exception
{
String line, token = null, delimiter = " ";

[code]....

View Replies View Related

JavaFX 2.0 :: File Browser - Adding Node To FlowPane Or TilePane

Jul 13, 2014

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.

package first.sample; 
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.image.ImageView;
import javafx.scene.layout.FlowPane;
import javafx.stage.Stage;
 
[Code] .....

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?

View Replies View Related







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