GCanvas In ACM Graphics Not Working Correctly

Mar 25, 2014

I am trying to implement a game using the ACM graphics. For the game, I am trying to make the main frame a Grid of Cells.I made a Grid class which extends GCanvas:

import acm.graphics.GCanvas;
public class Grid extends GCanvas{
private final static int WIDTH = 300;
private final static int HEIGHT = 300;
private final int DIMENSION = 5;
Cell[][] grid;

[code]....

View Replies


ADVERTISEMENT

Why If Statement Isn't Working Correctly

Apr 23, 2015

I am building a program that when you enter 1. it allows you to setup an item. However running my code my second if statement runs through.

import java.util.Scanner;
public class InventorySystem {
public static void main(String [] args) {
Scanner input = new Scanner(System.in);
int count=0;
int inputEntered=0;
int numberOfItems=0;
double cost=0.00;
String item;
String description;
 
[code]...

View Replies View Related

Console SQL Query App Not Working Correctly

Nov 6, 2014

My console SQL Query app is not giving me the desired output.I am sure its might have something to do with my SQL Query.Its missing the description of the stock items and it prints a new line for each user as per number of stocks an repeats the user details and then prints the stock listed by that user(only want the user listed once with all its stocks). I will add my files and current output and desired out put below.

MakeDB.java:

import java.sql.*;
import java.io.*;
public class MakeDB
{
public static void main(String[]args) throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url="jdbc:odbc:StockTracker";

[Code] .....

View Replies View Related

JSP :: Java Server Sent Events Not Working Correctly

Oct 10, 2014

Code structure :

Server : Java Servlet
Client : Simple JSP
Communication : Server Sent Events every 1 second
Here is the problem.

My code needed the server to send updates every one second to the client as stated above. Hence, I added a while loop with a sleep of 1000 milliseconds in the servlet code as shown below. The following strange behavior is observed:

- While the server is sending updates to the client, and the client window closes by mistake, the server does not stop sending updates It continues sending the data.
- When the client is re-opened, it sends data much faster (almost double). For example, the server sends 60 seconds worth of updates (60 updates) in just 25-30 seconds. The server sends faster updates not only for this round of updates, but also for any subsequent updates.

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse res)
throws IOException, ServletException {
PrintWriter writer = null;
try{

[Code]......

This server behavior is much unexpected. Am I writing the server side code wrong? I have looked around a lot and only found while loop method for modifying the server update interval. Is there any other method which I am missing?

View Replies View Related

Counting Repeated Instances - Parallel Array Is Not Working Correctly

Sep 6, 2014

So in my parallel array i read from a textfile of strings and if i enter the string into the string array and if strings are repeated i store it in a parallel array that counts repeated instances. I'm supposed to get 27 15 21 23 20 but instead i get 106 0 0 0 0....

Scanner sc=new Scanner(new File("Cat.txt"));
String category=sc.nextLine();
int total=sc.nextInt();
int[]totcat=new int[total];
String[]names=new String[total];
while(sc.hasNextLine()){

[Code] .....

View Replies View Related

Project Is Working On JFrame - But Not Working On JApplet

Apr 10, 2014

I am developing an application to share my client screen with server, it is working well on swing. But i want to develop as web application, i am trying to using applet. But i am facing the fallowing problem..,

1) The Applet screen also open and project also running well on server mechine. But unable to see the client screen on the server.

2) The problem may be to display the JDesktopPane or JInternalFrame.

My working Server Code extends withe JFrame..Java Code:

package remoteserver;
import java.awt.BorderLayout;
import java.awt.Container;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import javax.swing.JApplet;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

[code]....

View Replies View Related

How To Read A File Correctly

Feb 13, 2014

So i am creating a File object which has a text file passed to it. I then try to do logic with it using a BufferedReader. However, I get a FileNotFoundException on the using my code below. The Error is on the BufferedReader line. I

Java Code: System.out.println("--Reading text file--");
File file = getFile(c,fileName) // Returns a File object.
System.out.println(file); // Shows me the file is looking correct. Displays contents to console.
BufferedReader br = new BufferedReader(new FileReader(file));
System.out.println("BUFFERED");
while((line = br.readLine()) != null) {
try {
// Do Logic
}
catch(Exception ex){
ex.printStackTrace();
}
br.close(); mh_sh_highlight_all('java');

View Replies View Related

If Else / Switch Not Outputting Correctly

Jan 27, 2014

Trying to learn switch statements. Can't figure out what I am doing wrong.

java Code:

import java.util.Scanner;
public class Ok1 {
public static void main(String args[]) {
Scanner input = new Scanner(System.in);

[code]...
When I run, it makes me enter letter = null and it wont output correctly.

View Replies View Related

Write Correctly Border And Gravity

Sep 27, 2014

I want to write simple game. Why if I press button UP and RIGHT it not move diogonally, may be it have special code. And how I need to write correctly border and gravity?

public class Main {
public static void main(String args[]) {
JFrame frame = new JFrame("Stickman");
Ground ground = new Ground();
frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
frame.setSize(710, 480);

[code]....

View Replies View Related

Game Over Method Not Updating Correctly

Sep 4, 2014

If I run this code. I can manipulate it so that X wins. When the third X button is pressed, there is no display saying that X has won and that the game is over. I have read over this code for days and still have not figured it out.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
 public class TicTacToe extends JFrame implements ActionListener, WindowListener{
 public JFrame window = new JFrame("window");

[Code] ....

View Replies View Related

How To Drag JLabel Correctly Across JFrame

May 26, 2014

I am currently trying to make a method that will enable a jLabel to be dragged across the screen. I want to be able to drag the object pretty much anywhere on the screen(I hope to eventually make a destination for it where it can be dropped but I will get to that later). I have looked on various places on the internet on how to achieve this and the most simple solution does something like this:

Java Code:

jLabel6.setText("jLabel6");
jLabel6.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
public void mouseDragged(java.awt.event.MouseEvent evt) {
jLabel6MouseMoved(evt);
}
});
private void jLabel6MouseDragged(java.awt.event.MouseEvent evt) {
x = evt.getX();

[Code]...

This actually works somewhat but it is very faulty. For example the jLabel keeps appearing and reappearing as I drag it. Furthermore when I drag it I can see a duplicate Jlabel being dragged as well in the top left hand screen. So how might I fix this?

View Replies View Related

Cannot Get Numerical Date To Display Correctly

Nov 29, 2014

I am trying to write a date program. I have it written and running correctly, except one issue. I cannot get the numerical date to display correctly. I know it is an issue with printf. I don't know anything about printf. Here is my method to return the day

public int getDay() {
return day;
}

When it returns, it is literally returning just the numeric date. I need it to show up as 02 or 03 instead of 2 or 3, respectively.

View Replies View Related

Date Order Not Printing Correctly

Sep 8, 2014

the dates are printing out of order. It should appear MM/DD/YYYY however with my code its printing DD/YYYY/MM.Here is my code.

public class DateTest {
public static void main(String args[]){
Date date1 = new Date( 7, 4, 2004 );
System.out.print( "The initial date is: " );
date1.displayDate();

[code]....

View Replies View Related

How To Apply Casting Correctly For HeightProgram

Mar 17, 2014

how to calculate the child's height in float value fixing value where if you choose male the accurate value, but if you choose female the value will be accurate too.

int heightMother, heightFather;
int heightMaleChild, heightFemaleChild;
String gender;

[code]....

View Replies View Related

AverageDriver Won't Pull Data Correctly

Dec 12, 2014

I'm unable to get the output for "AverageDriver" to print correctly(5 scores in descending order and average). The output displays the scores the same way they are entered and the average is always zero. The output for the Average program works fine and with the correct output.

import java.util.Scanner;
//This class keeps 5 scores entered by the user
public class Average
{
private int[] data;
private double mean;
public Average()

[Code] ....

View Replies View Related

Cannot Get Data File To Print Out Correctly

May 7, 2014

I cannot get the data file to print out correctly when I go to the display case. It only prints one name three times.
 
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.*;
import java.util.Scanner;
import java.io.*;
import java.text.*;
import java.math.*;
import java.util.StringTokenizer;
 
[Code] ....

Output when I choose Case 1:

Minia
Minia Jane
Minia Jane

View Replies View Related

Making Graph Work Correctly

Nov 9, 2014

I'm working on a homeowork assignment here URL... and I can't get the graph to work correctly. I'm not really sure how to print the string of names, gender and rank at the point on the graph. Also I'm just wondering if I set up the scanner to find names right.

import java.util.*;
import java.io.*;
import java.awt.*;
public class Names {
public static final int year = 1880;
public static final int decades = 14;
public static final int decadeWidth = 70;

[code]....

View Replies View Related

Reading ASCII Data Correctly

Jan 21, 2015

I have two programs that talk to each other over a TCP connection. When I write the data "STX+1234" where STX is the Ascii character STX or Ctrl B and I expect the written String length to be 6 which it is. On the other side of the socket I create the ServerSocket and use the client socket's InputStream to create a BufferedReader. When I receive the string it now has 12 characters where each original character has been replaced by NUL and the character.  How do I read the string as it is originally specified without the conversion? And is the problem on the reader side or the writer side?

View Replies View Related

JavaFX 2.0 :: Extending SplitPane Correctly

May 26, 2014

I'm having a problem with SplitPane (horizontal Flow). What I'm looking for is to find a way to maintain  the left pane in the same position when the main window maximizes. I do not want the left pane to grow on its width. If I go into the AnchorPain Constraint in the Scene Builder and remove the right and left constraints, when I run the application, the left pane keeps its position, but it appears a gap between the two panes (the left pane and the right one).
 
I need to find the way to expand the right pane to the position where the left pane is.
 
The link shows an image that illustrates the problem. [URL]

View Replies View Related

How To Build Graphics

Jan 5, 2014

He said that if you need something that Swing can't provide, like a bar graph, you build it. Now, being used to just writing a method that will open up a JFrame, how you would actually build graphics on your own. How in the world would that work? How would one write their own methods to make a window or to build a graph?

View Replies View Related

Graphics Are Flickering

Feb 2, 2014

I attempted to make my square move in the screen and i set up collision with another object, however the graphics are flickering, really flickering, here's the code:

Java Code:

import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
public class NewEmpty extends JFrame {
double p1speed =5, p2speed =5;

[code]....

View Replies View Related

How To Easily Use Graphics

Dec 31, 2014

I am attempting to create a n-body simulation using orbital dynamics and Java in school.

I am only in high-school, but I have some programming experience. The logic of this program comes quite easily. My problem is the graphical part, so I was just looking for quick methods to implement graphics.

What I am looking to do, is display objects onto the screen and manipulate their respective x and y coordinates as time pass. I have tried to use BufferedImages and an array of every pixel on the screen, but it quickly becomes extremely hard to draw circles etc. I have also tried the Graphics class and using g.fillOval() etc, but this can also get tedious.

Are there any more efficient methods, libraries etc? And also, how should I use the time variable, a variable that updates everytime the program updates?

View Replies View Related

I/O / Streams :: How To Read In A Binary File Correctly

Nov 8, 2014

I have a binary file that has identifiers for the start of each record

You can see here that the record starts with 00 00 and the next record starts with 00 00 etc...

How do I read between these two points throughout the file?

RandomAccessFile database = new RandomAccessFile(databasePath, "r");
int start = 0;
int end = 0;
database.setLength(start);
database.seek(end);

The first start would be the start of the file, the next start would be the end of the first start and so on..

I'm just not sure how to put that into a loop.

View Replies View Related

Singly Linked List Not Printing Correctly

Sep 30, 2014

Its a program that creates a singly linked list that stores names and high scores and prints them. For some reason it is printing an entry extra times. Also my remove function is not working properly.

package project;
public class GameEntry implements Comparable<GameEntry> {
private String name;
private int score;
public GameEntry(String n, int s) {
name = n;
score = s;

[code]...

View Replies View Related

Servlets :: Website Loads Correctly Only After A Refresh?

Jan 16, 2015

find out why when I access the site for the first time, it loads a blank white page, but when I reload it, it forwards me to the home page as it should.

I doubt that the reason is nothing else than the code below (in the doGet method):

String email = (String) request.getSession().getAttribute("email");
String cookieValue = null;
System.out.println(email);
// first, checking the session
if (email != null) {
request.getRequestDispatcher("/homelogged").forward(request, response);

[code].....

I suppose it's something with the session... because after I reload it, it works. But! When I close the browser and start all over again, the main page is white-blank again... And after a reload it works.

The exception:

SEVERE: Servlet.service() for servlet [first] in context with path [/MYSITE] threw exception
java.lang.NullPointerException
at controller.Controller.doGet(Controller.java:42)
Line 42 of the Controller is "for (int i = 0; i < cookies.length; i++) {"

P.S. I cleared all the cookies, but the problem persists.Also, the first it loads, it prints in console:

"null
been here 4!"

But, if I reload further, it prints:

"null
been here 4!
been here 2!
No Email! Literally, doGet!"

View Replies View Related

Format Output Correctly Using Printf Function

Nov 6, 2014

I have an output of three columns, Total Income | Tax Payable | Net Income... however to output this I have the following code:

System.out.println(" Total Income | Tax Payable | Net Income");
int i = 0;
 for (i=0; i <=18; i++){
if(incomes[i] < 0){
break;

[Code] ....

And the format of it comes out as: Screen Shot 2014-11-06 at 22.50.25.jpg

I'm getting very OCD about the format and I know there is a printf function which would solve this, however I don't really know how to use this correctly and it just messes up when I try to use it.

View Replies View Related







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