Fleet Of Ships - Drawing Squares In Graphic Context
Feb 20, 2014
Square:
package assignment1;
import java.awt.*;
public class Square
{
private double x,y; // Current position of the square.
private Color color; // The color of the square.
private int side; // The side of the square
public Square() // constructor
[Code] .....
This is the square class, it draws an orange square that moves around in the applet viewer, works fine and as it supposed to do.
Ship:
package assignment1;
import java.awt.*;
public class Ship
{
private Square[] fleetMembers; // declare fleetMembers as an array of Square
private int total = 5; // Max number of squares in fleet
private double x,y;
Ship() // Constructor
[Code] ....
This is my FleetOfShips code. It is supposed to be a set of ships moving around together, but for unknown to me reasons it doesn't work. It does compile without any problems but when I run the applet it doesn't do anything.
This is a lab for one of my CS classes, and the assignment is to create a randomly filled array (values 10-100) and use these values as the height of an array of rectangles (essentially a bar graph)that will be drawn on a page. After that's done, the code should use the selection sort method to sort the bars least to greatest, being repainted as it's sorted.
I'm receiving no errors, the original draws just fine, and the code sorts the first position and then...it just hangs. Like it's in an infinite loop but I have all of the modifiers in place (I think. I've been staring at this code for three days straight and I don't think I really see it anymore). I've tried talking to my professor and I get that her private life is really busy right now, but she just keeps blowing me off and I don't know what to do. Anyway, done with back story and whining so here's the code.
Rectangle class: import java.awt.*; import javax.swing.*; import java.awt.event.*; public class Rectangle
For the assignment, we are supposed to make a checkerboard with alternating colors, then put images on top of certain spaces to act like "pieces." I did the checkerboard, but whenever I go to try and put an image the checkerboard, it doesn't appear! I put the image in the same directory as my other code as well. I did some experimenting and discovered that the image is appearing, but behind the checkerboard.
Here is the code:
import java.awt.*; import javax.swing.*; public class CheckerBoard extends JApplet{ public void paint(Graphics g){ super.paint(g); Image img1= getImage(getCodeBase(),"arrow1_nw.png"); g.drawImage(img1,500,500,this);
I have created a small program with methods of the Graphics class. I want to resize the frame and make it fit the screen, but after trying various layout managers, have come to the conclusion that by setting the sizes of the various shapes specifically in the paintComponent method, I can't resize. Is it possible to resize a frame with its paintComponent methods? Maybe I'm just not using the layout managers correctly but the Graphics just wont resize. I have tried setting the weights when I used GridBagLayout.. not working. I thought maybe there is a way to set the frame or panel to take the Graphics and then resize the panel. That doesn't work either.
I am trying to draw a binary node tree to a text file.
public class BinaryTreeExample { public static void main(String[] args) { new BinaryTreeExample().run(); } static class Node { Node left; Node right; int value; public Node(int value) {
[Code] .....
This will output:
Building tree with rootvalue25 ================================= Inserted 11 to left of node 25 Inserted 15to right of node 11 Inserted 16to right of node 15 Inserted 23to right of node 16 Inserted 79to right of node 25 Traversing tree in order ================================= Traversed 11 Traversed 15 Traversed 16 Traversed 23 Traversed 25 Traversed 79
I need to print this information in the form of a graphic to a text file. so for example:
so for my computer science class, we have the following problem:
In your documentation be sure to say which loop you thought was easier to implement for this program and why Write a program that produces the following outputs. The first line of output must be written using a For-Loop. The second, using a While-Loop and the third using a Do-Loop.
You look at the program and smile because you see that the series is just the numbers 1-10 squared...just one line is in reverse order. No problem! As you start typing you discover that the number 8 key on your keyboard is not working. For this program you are unable to use the multiplication key
So, back to the drawing board. By staring at the sequence a light comes on and you are able to quickly finish this program WITHOUT using mulitiplication (or the Math class/ solve with arithmetic operators +, - or / ) .
Sample output:
For Loop 1 4 9 16 25 36 49 64 81 100
While Loop 100 81 64 49 36 25 16 9 4 1
Do While Loop 1 4 9 16 25 36 49 64 81 100
I have the "for" done, but I did it with a "for" in the beginning but then had a multitude of nested "if" loops so that I could do 7*7=7+7+7+7+7+7+7
I am teaching myself Java and am trying to write a function that will determine all of the perfect squares between 1 and 100 but am running into a problem...
Here's my code:
package sqrroot;
public class SqrRoot { /** * @param args the command line arguments */ public static void main(String[] args) { double sroot, rerr; int count = 0; for(double num = 1.0; num <= 100.0; num++){
[Code] ....
and here is the output:
run: 0.0 1.0 is a perfect square. 0.0 4.0 is a perfect square.
[Code] ....
There are 49 perfect squares between 1 and 100. BUILD SUCCESSFUL (total time: 6 seconds)
Which is clearly wrong. Is there something wrong with my code or is this due to inherent imprecision in the double type or the Math.sqrt function?
So I need to create a 10x10 grid for a snakes and ladders board, the board loads but i cant figure out how to add numbers to the squares. Here is my code :
import java.awt.*; import javax.swing.*; public class Board { //Creating the array int[][] numbers=new int[10][10]; public static int rows = 10; public static int columns = 10; public static Color col1 = Color.green;
I know I can calculate the sum of squares as such:
// SumSquares.java: calculate the sum of two squares class SumSquares { static int sumSquares(int a, int B)/>/> { int asquare; int bsquare;
[Code] ....
But how can I modify the code so that it inputs a list of integer values in the range of -100 to 100 from the keyboard and computes the sum of the squares input values. And how would I go about using exception handling to ensure that the input values are in range and are legal integers.
I'm having trouble filling in the blank squares on a Minesweeper game. What I am trying to is, if a user clicks a square and that square(s) does not have a bomb in it, or adjacent to it, should be set to an empty square.
Here's my recursive method below:
public void revealZeros(){ for(int x = -1; x <= 1; x++) for (int y = -1; y <= 1; y++){ Square zeroSquare = (Square)board.getSquareAt(xLocation+x, yLocation+y); if (!(zeroSquare.SquareHasBomb)){ setImage("images/empty.jpg"); } } revealZeros(); }
I am traversing around the square that the user clicks on with the use of two for-loops. Getting the square at that location and then applying an empty square image. On that square.
The function should then recurse itself and go onto the next square, if the next square does not have a bomb or does not have an adjacent bomb.
I know I can calculate the sum of squares as such:
// SumSquares.java: calculate the sum of two squares class SumSquares { static int sumSquares(int a, int B)/>/> { int asquare; int bsquare;
[Code] .....
But how can I modify the code so that it inputs a list of integer values in the range of -100 to 100 from the keyboard and computes the sum of the squares input values. And how would I go about using exception handling to ensure that the input values are in range and are legal integers.
How to access session from different context? I have created a session in one jsp, in one context and trying to access it from different context. But, I was unable to access the same. How to achieve it?
And this works fine: URL....The war file is deployed under the context root /bankconnect/ I want to make a servlet mapping, before the context root "i still want the context root bankconnect". URL....
Now if I am in the admin 1 environment, I would initialize my servlet with request parameter admin=1 and the servlet should load email address of admin 1 and similarly when in the environment 2, should load the servlet with admin 2.
I could do the same by putting the email address of the respective admin as request param value, but i don't want to the email address to appear in the url.
I had to change context path name of my web application due to some organizational shuffle. I have successfully changed it and it has been working fine.
But what is happening is we have used old context path name in reminder and notification emails. so When users hit links from old emails, they are getting 404 Error.
Is there any way to redirect the old request which has old context path to new one?
I am working on netbeans IDE , but I understand how the application know the parametres for the connections. I understand what is a Context , specifically i understand this code about the init method
Main screen leftsecond screen rightswing portal application is visible on two screens. If you open a context menu (right mouse) on the right screen, the context menu open on the left (Main) screen instead of the right.
I am trying to call an actionListener which is shown below in my PSVM :
class testMenuItemListener implements ActionListener { public void actionPerformed(ActionEvent arg0) { getContentPane().removeAll(); createPanel(); getContentPane().add(panel1); //Adding to content pane, not to Frame repaint(); printAll(getGraphics()); //Extort print all content
[Code] .....
I get the following error :
Frame.java:409: error: non-static variable this cannot be referenced from a static context menuItem1.addActionListener(new testMenuItemListener());
I am trying to add a field (called special) to a hibernate table. I am copying existing code (related to the NAME field) so I don't have to figure this out from scratch. I am getting the error
"[ERROR] C:VOXvoxware-1.1.13voxwarevoxware-implsrcmainjavacomvoxwareimplflowVoxFlowConfiguration.java:[213,38] error: non-static variable special cannot be referenced from a static context".
Line 213 is in public void mergeFrom, the actual line is "special = VoxFlowConfiguration.special;" I don't understand why Java thinks special is a "non-static" variable but it doesn't have a problem with the other variables (such as name, orderShow)
I'm working on a banking program that is supposed to use 3 classes (Account-base class, CheckingAccount, and SavingsAccount) and several methods to display the banking information (ID, balance after a withdrawal and deposit, and the annual interest rate). This should be a pretty simple program, but I'm getting hung up on one portion of it. I'm getting some compiler errors, all of which deal with non-static variables being called from a static context (I'll also post these errors following the code). Up until the middle of last week, we just declared everything as static, but that's changed and I'm having trouble figuring out when to and when not to use static when declaring my methods, hence the compiler errors.
import java.util.Date; public class Account { private int id = 0; private double balance = 0; private double annualInterestRate = 0; private Date dateCreated = new Date();
[Code] ....
Here are the compiler errors I am receiving:
Compilation completed. The following files were not compiled: 6 errors found: File: C:UsersHiTechRedneckDesktopSummer II 2014Computer Programming PrincipleProgram 5CheckingAccount.java [line: 7] Error: non-static method getId() cannot be referenced from a static context
I am trying to call an actionListener which is shown below in my PSVM :
class testMenuItemListener implements ActionListener { public void actionPerformed(ActionEvent arg0) { getContentPane().removeAll(); createPanel(); getContentPane().add(panel1); //Adding to content pane, not to Frame repaint();
[Code] .....
I get the following error :
Frame.java:409: error: non-static variable this cannot be referenced from a static context menuItem1.addActionListener(new testMenuItemListener());