Flipping Ruler Upside Down - It Prints Across The Screen

Sep 22, 2014

public class Ruler {
private static void drawMinorTicks(int line, int ticks) {
if (ticks > 1) {
drawMinorTicks(line, ticks - 1);
}
if (line <= ticks) {
System.out.print('|');

[Code] ....

Here is the out put for this code

|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | |
| | | | | |
0 1 2 3 4 5

View Replies


ADVERTISEMENT

Flipping Image Horizontally

Jul 1, 2014

I'm trying to flip an image horizontally. However because when I flip the images they're offset by a bit, I added "-height" to offset the change in position. Unfortunately, it doesn't seem to be working 100% of the time; some images are adjusted to their correct position but some are not.I'm using this line to flip an image: Java Code: g.drawImage(castle, x, y - height, -width, height, null); mh_sh_highlight_all('java');

View Replies View Related

Page Flipping Graphics

May 25, 2014

Page flipping is used in full screen games which entails drawing an imagine off screen then swap with on screen image after drawing has completed.

Is it possible to write a block of code to actually see this happen? Like use this technique on a window that is in windowed mode. Would it draw an image off somewhere by the desktop or would it have to be on the window?

View Replies View Related

Array JavaKara - Inverting And Flipping Horizontally A Grid

Nov 8, 2014

I'm using JavaKara (a graphic Java software to learn coding) on my classes at the moment and we're asked to transform something like this:

In the inverse, where you can see clovers there must not be any and where there aren't you must plant them. PLUS YOU MUST SWITCH THE FIGURE HORIZONTALLY.

This is the result i should obtain:

public class InvertiECapovolgi extends JavaKaraProgram {
public void myProgram() {
boolean arrayquadrifogli[][] = new boolean[world.getSizeY()][world.getSizeX()]; //[rows][clumns]-->[Y axis][X axis] in kara
for (int y = 0; y < arrayquadrifogli.length; y++){ // My Ladybug starts to run through the whole grid

[Code] ....

How to switch everything horizontally!

This is my result:

My ultimate question is, how do i have to edit the second loop, and why, to obtain the horizontally reversed result i'm supposed to obtain?

View Replies View Related

Cardlayout Format - Change Main Menu Screen Into Game Screen On Button Click

Mar 16, 2015

I'm making a game of checkers for my A2 Computing coursework which is due in within a week. I have completely finished the game, and only thing I have left to do is connect the two JPanels together via a CardLayout that I have made. However I am unsure how to do so

Here is the code from my CardLayout:

import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.JButton;

[Code] ....

I have kept the code I am displaying to a minimal, hence I have removed all the action listeners for my buttons, anyway the problem I have is that, I would like it so that when the user clicks on the 'Multiplayer' button which is the array button ourButtons[1], it will then transition into my main game screen so that the user can then play a game of checkers.

Here is the main important GUI from my CheckerBoard class:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
  public class CheckerBoard extends JPanel implements ActionListener, MouseListener {
// Main routine that opens an Applet that shows a CheckerBoard
public static void main(String[] args) {
new CLayout();
 
[Code] ....

Once again kept to a minimal.

View Replies View Related

Add To List With ID Makes List Upside Down

Feb 14, 2015

I saved the content of an ArrayList<SomeClass> to a file

I write each serialised object to the file by adding to each an id that is created with list.indexOf(object) (and saved before each object)

So I can repopulated the list with SomeClass objects in the same order as they were and once I reload the file, I do list.add(id,object)...

Well my list is populated upside down, I mean the first object is the last and the other way around, If i remove the id when I do the add(object)...

View Replies View Related

Prints Every Minimum In Array

Jan 20, 2015

The second message dialog result is always 0 ... i want to find the minimum grade...

import javax.swing.*;
import java.util.Arrays;
public class Parrarrapapa{
public static void main (String[]args){
String length = JOptionPane.showInputDialog("Number of students");

[code]....

View Replies View Related

Array Prints Out Zeros?

Nov 16, 2014

Ok, so let's say I am having a user input scores and at the end I want to print out the results so I do something like:

int[] Scores = new int[1000];
//code to ask user for input and store into array //

The user only inputs lets say 5 scores out of possible 1000. I then try to print it out by doing something like this:

for(int counter = 0; counter < Scores.length; ++counter) {
System.out.println(Scores[counter])
}

How would I go about printing out only the index's that were input, because right now it prints out the scores and then 995 0's after.

View Replies View Related

PrintWriter Only Prints Last Line?

Dec 6, 2014

I'm tyring to print the same output in console to a text file, but I can only get the last line of the console output in the text file, not sure what is wrong with my code:

while (in.hasNextLine()) {
PrintWriter writer = new PrintWriter("output5.txt");
tempS = in.nextLine().toLowerCase();
System.out.println(wp.bestPages(tempS));

[code]....

What's causing only the last time to be printed in text file? Are there better ways to print console outputs into a text file than PrintWriter?

View Replies View Related

Program Prints 2 Values Instead Of One

Feb 4, 2015

When I run this code, it is supposed to get one value from turnTimer(); and return it, just as a test. This works when I enter a valid pit. For example. If I were to input "A" when it's player one's turn, it will return 1, like it should. However, if I were to type "H" when it's player one's turn, it returns "Not a valid pit!"(like it should) but then it also returns 12. It shouldn't know that H is 12 because it's in a separate method. I'm confused as to why it's printing both values.

import java.util.*;
public class Mancala {
static Scanner input = new Scanner(System.in);
public static int pit;
public static void main(String[]args) {
Mancala mancala = new Mancala();
int[] board = {0,3,3,3,3,3,3,0,3,3,3,3,3,3};

[Code] .....

View Replies View Related

Deleting From ArrayList / Goes Through Both If And Else And Prints

Dec 8, 2014

I've a ArrayList with dogs on, and I've a function that should allow me to delete a dog from the register and if the dog was found it prints "The dog was deleted" and if the dog doesn't exist in the arraylist it should print "the dog couldn't be found".

Everything works perfect until I shall delete a dog that is not first on the list. Then the program shows first "dog was not found" and on the row after "the dog was deleted" if the dog was second on the list. If it was third I will get 2 messages that the dog wasn't found and then that the dog was deleted. I've no clue why it prints both else and if!

public static void taBortHund(){
//Har tar vi bort hund fran listan
//System.out.println(hundlista);
System.out.print("Vilken hund vill du ta bort? ");
String hunden = tangentbord.nextLine();
for (int taBort = 0; taBort<hundlista.size(); taBort++){

[code]....

View Replies View Related

How To Make A Table That Prints Out Sin / Cos / Tan For Angles

Sep 30, 2014

I am stuck and having a problem trying to find what i believe is a simple fix but can't wrap my head around it. For class I needed to make a table that prints out Sin,Cos,Tan for angles in steps of 5 to 180. The problem is in my output with the first couple lines of the table. for angle 5.0 the Sin(.0872) Cos(.9962) and Tan (.0875) are being displayed on the angle line 10.0

public class TrigTable {
public static void main(String[] args) {
double angle = 0;
double sin =0;
double cos = 0;
double tan = 0;
 
System.out.println("Angle Sin Cos Tan"); // Table header for the values

[Code] ....

Here is the first couple lines of output:

Angle Sin Cos Tan
----- --- --- ---
0.0 0.0 1.0 0.0
5.0 0.0 1.0 0.0
10.0 0.0872 0.9962 0.0875
15.0 0.1736 0.9848 0.1763
20.0 0.2588 0.9659 0.2679

View Replies View Related

How To Use Logger And Prints Time And Date

Feb 5, 2015

I need to add Logger function in the catch block that prints time, date and description of the what had happened.

public class InputUtil {
public static final String[] SPECIAL_CHARACTERS = { "!", "#","%", "^", "=",
"+", ";", "[", "]", "|", "<", ">", "?", "~", "`", "-", "" };
public static String deleteSpecialCharacters(String inputString) {
String outputString = inputString;

[Code] ....

View Replies View Related

Program Prints 2 Values When It Should Only Print 1

Feb 4, 2015

When I run this code, it is supposed to get one value from turnTimer(); and return it, just as a test. This works when I enter a valid pit. For example. If I were to input "A" when it's player one's turn, it will return 1, like it should. However, if I were to type "H" when it's player one's turn, it returns "Not a valid pit!"(like it should) but then it also returns 12. It shouldn't know that H is 12 because it's in a separate method. I'm confused as to why it's printing both values.

import java.util.*;
public class Mancala
{
static Scanner input = new Scanner(System.in);
public static int pit;
public static void main(String[]args)
{
Mancala mancala = new Mancala();
int[] board = {0,3,3,3,3,3,3,0,3,3,3,3,3,3};

[code]....

View Replies View Related

Create Program That Prints Time Between 00:00 (0:00 Am) And 23:45 (11:45 Pm)

Feb 8, 2014

I was told to create a program that prints the time between 00:00 (0:00 a.m.) and 23:45 (11:45 p.m.) in the 24-hour clock and 12-hour clock format like this:

24-hour Clock 12-hour Clock
-----------------------------
00:00 0:00 a.m.
00:15 0:15 a.m.
00:30 0:30 a.m.
00:45 0:45 a.m.
01:00 1:00 a.m.
01:15 1:15 a.m.
01:30 1:30 a.m.
01:45 1:45 a.m.
02:00 2:00 a.m.

ect...

but cant seem to create the program and my program doesnt seem to run.

View Replies View Related

Write A Method That Prints Characters

May 7, 2014

Write a method that prints characters using the following: public static void printChars(char ch1, char ch2, int numberPerLine). This method prints the characters between ch1 and ch2 with specific numbers per line. Characters are separated by exactly one space.Test your method with the following main method:

public static void main(String[] args)
{
printChars(‘A’,’z’,10);
printChars(‘0’,’9’,5);
}

View Replies View Related

Program That Prints Repeated Integer In Array

Apr 8, 2015

So I'm trying to write a program that prints out the "most-repeated integer" in an Array.

For example: if an array contains {1,2,2,3} It would print out 2 as the result.This is what I got so far and according to my knowledge I think I'm correct but for some reason it doesn't work.. Please give me some inputs.

public class MostInt{
public MostInt (){
int[] array = {0};
for(int i = 0;i>array.length;i++){
if(i==i++){
System.out.println(i);

[Code]...

View Replies View Related

System Prints Final Statistics Many Times

May 25, 2014

I made a heads or tails game but I'm getting a bug when the user says he doesn't want to play anymore. The statistics are printed as many times as the games played. If you want to test the code, write" cap" " pajura" and when the program says "Vrei sa mai joci?" that means "do you wanna play another one?" and you can answer with "da"(yes) or "nu"(nu) Here is the code:

import java.util.Scanner;
public class cap_sau_pajura{
private static int user;
private static int pc;
private static String converted;
static int usermove;
private static int castiguri = 0;
private static int pierderi = 0;

[code]....

View Replies View Related

How To Write A Dot File That Prints Graph In Java

Dec 6, 2014

Let's say if I want to create a dot file that print this graph in Java, how do i go about it?

I'm starting with this:

PrintWriter writer = new PrintWriter("graph.dot");

View Replies View Related

How To Do Util Timer With A Button That Prints A Message

Aug 22, 2014

I don't want a tutorial that shows me how to do a util timer with a button, or that prints a message, or that does anything. I want the simplest possible snippet that makes the timer, lets me have it do something, and can be stopped. No bells and whistles, no strings, no sparkles and explosions. Just a timer.

View Replies View Related

Java Method Overloading Ask For Two Names And Prints Three Different Greetings

Feb 24, 2014

The class Overloading below asks for two names and prints three different greetings. Your task is to write the class methods missing from the class declaration. Methods print the greetings as shown in the example print.

Hint:The names and parameter types of the needed methods can be checked from the main method because all methods are called there. This exercise also does not require you to copy the source code below to the return field.

The method declarations will suffice.

Example output
Type in the first name: John
Type in the second name: Doe

**********
Hi!
**********
Hi, John
**********
Hi, John and Doe
**********

import java.util.Scanner;
public class Overloading {
public static void main(String[] args) {
String firstName, secondName;

[Code] ....

View Replies View Related

Java Program That Prints Specific Numbers In Pattern

Dec 30, 2014

Write a java program that prints 0..........121..........23432..........3456543............456787654............56789098765 in this pattern?

My code:

public class Number {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int k=0;
for(int n=0; n<=10; n=n+2)

[code]....

View Replies View Related

Fraction Calculator Prints Correct Answer But Not In Decimal

Feb 23, 2015

package FracCalc;
import java.util.Scanner;
public class FracCalc {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
 
int n1 = 0; //n1 = first numerator user have to enter
int d1 = 0; //d1 = first denominator user have to enter
int n2 = 0; //n2 = second numerator user have to enter
int d2 = 0; //d2 = second denominator user have to enter
int numeratorAnswer = 0; //calculates numerator of an equation
int denominatorAnswer = 0; //calculates denominator of an equation
 
[code]...

I mean its not that important but i figure it will be better if I could print out the answer both in fraction format and decimal format. while my answer prints in fraction just fine how do i show it in decimal?

System.out.println("");
 
System.out.print("And ");
System.out.print("answer in Decimal is: ");
 
decimalAnswer = ((double)numeratorAnswer/denominatorAnswer);
System.out.println((float)decimalAnswer);

View Replies View Related

Creating Java Program That Prints The Smallest Number

May 9, 2015

Here is my code :

import java.util.Scanner; 
public class smallestnumber
{
public static void main(String args[])
{
Scanner input=new Scanner(System.in); 
int smallest =0;
int number;

[Code]...

here is the output of my code:

Enter the number
88
Enter the number
8
Enter the number
6
Enter the number
55

[Code]...

Why is it printing 0 instead of 1?

View Replies View Related

Java Program That Prints Out Taylor Series For Mathematical Constant E

May 10, 2015

I am trying to write a java program that prints out the number that is the mathematical constant e. As you input a number, the larger it gets , the closer it comes to 2.71828 . Here is my code:

//taylor series that prints out e^1=1+1/1!+1/2!+1/3!+.....
import java.util.Scanner;
public class taylor_1
{
public static void main(String args[]) {
 Scanner input=new Scanner(System.in);
int factorial =1;

[Code] .....

Here is the output of my code:

enter n
9
Taylor series is 9.0

View Replies View Related

Create Circular Array Which Prints Out 8 Numbers That Increase By One And Don't Exceed 9

Jan 31, 2015

I'm trying to create a circular array which prints out 8 numbers that increase by one and don't exceed 9. If they do, the remaining numbers are printed from 0 on-wards. I have code below which does this job, but it doesn't really use an array to loop back.

Java Code:

package Practice;

public class Practice
{
public static void main(String[] test)
{
number(7);
number(9);

[code]...

View Replies View Related







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