Flip Bottom Half And Copy It To Produce Upper Half Of Shape
Jun 15, 2014
So my goal is to use the graphics class to draw this shape: [URL] ....
so far I've managed to draw the bottom half, but now I want to utilize the copyArea() method to flip the bottom half and copy it to produce the upper half of the shape: [URL] ....
and this is what I wrote to produce the bottom half:
import java.awt.Graphics;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
public class MyFrame extends javax.swing.JFrame {
/**
* Creates new form MyFrame
*/
public MyFrame() {
initComponents();
[Code] .....
View Replies
ADVERTISEMENT
Aug 26, 2014
I am only able to print upper half of the hourglass.
public static void printHourglass(int size, char symbol) {
int count = 0;
int count2 = 0;
boolean lower = false;
for(int lines = 0; lines < size; lines++)
{
//upper half
[code]....
View Replies
View Related
Feb 11, 2014
Write a method named secondHalfLetters that accepts a string as its parameter and returns an integer representing how many of letters in the string come from the second half of the alphabet (that is, have values of 'n' through 'z' inclusive). Compare case-insensitively, such that uppercase values of 'N' through 'Z' also count. For example, the call secondHalfLetters("ruminates") should return 5 because the 'r', 'u', 'n', 't', and 's' come from the second half of the alphabet. You may assume that every character in the string is a letter.
View Replies
View Related
Feb 7, 2014
What's a simple way to flip an Image along the vertical or horizontal? I've searched high and low and surprised to find that I can't find something short and compact.
View Replies
View Related
Apr 9, 2014
I cannot get this crappy looking pacman to horizontally flip as he hits the right wall.
Here is my JFrame
package MyPacman;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
[Code] ....
I do not understand how I can alter my paintComponent. Is it possible to set my paintComponent to an Image variable, and then flip the image with Math.Radius?
View Replies
View Related
Mar 30, 2014
why this switch code does not work for the 'Q'. Everything works fine for the other cases, i.e. 1,2,3, and 'q', but when I type in 'Q', I get the default case. Please note all the values have been defined in an earlier part of the code but for simplicity's sake I have removed them below
do {
switch (choix) {
//demande le nombre de patons a achete
case '1':
[Code].....
View Replies
View Related
Apr 22, 2015
I am supposed to write a static method that simulates a flip of a weighted coin by returning either heads or tails each time it is called. The coin is twice as likely to turn up heads as tails. My idea was to of course use a random class
Random flip = new random
and somehow initialize it so 3 numbers are called and create if statements so that when 0 and 1 are called heads returns and when 3 is called tails is.How do I put all this together?
View Replies
View Related
Nov 19, 2014
I cannot figure out why my buttons don't work. I believe my problem is in the flip function. I am very new to programming and I am about as good at code logic as I am at real logic lol. Also I am lost on how to go about making the coin stop on a random heads or tails.
Coin cF;
void setup() {
size (600, 600);
cF = new Coin(0,0,0);
}
void draw() {
background(100,100,100);
//Coin(int lX,int lY, int cSize)
//location(int l_x, int l_y)
//flip()
[Code] ....
View Replies
View Related
Mar 31, 2015
Here is the snippet of code that is causing the problem
Java Code:
addWindowListener(new WindowAdapter()
{
@Override
public void windowClosing(WindowEvent e)
{
int confirm = JOptionPane.showOptionDialog(
VendorMachineSimulation.this,
"Are You Sure you want to close this application?",
"Exit Confirmation", JOptionPane.YES_NO_OPTION,
[Code] ....
My question is why does the snippet code at the top works in the class processAction but when I add to the main class that extends JFrame, it exits regardless if I click yes, no or the x button.
View Replies
View Related
Feb 15, 2015
I'm not sure why, but my program does not produce an output. It is supposed to output total charges.
/*This program provides the user with the price of their monthly internet service based on two inputs.The program asks users which subscription they have. The options are A, B, or C. This is the first input.
The program then will ask the user how many hours they used the internet for. This is the second input.Then, based on the package number, the program will compute their monthly bill. This is the output.
The program calculates the price based on the following prices:
Package A: For $9.95 per month, 10 hours of access are provided. Additional hours are $2.00 per hour.
Package B: For $13.95 per month, 20 hours of access are provided. Additional hours are $1.00 per hour.
Package C: For $19.95 per month, access is unlimited.*/
import java.util.Scanner;
public class Lab03SV
[code]...
View Replies
View Related
Nov 29, 2014
How to find a set of number that will do this? I need it to test a program I am writing.
View Replies
View Related
Sep 13, 2014
I'm trying to produce a random number between 1 and 54 . I think this is correct
int i= (int)(Math.random()*54)+1;
View Replies
View Related
Apr 15, 2015
I decided to code this quiz I took in class about asking the user to input a string and the code is suppose to check for upper case letters. If a upper case letter is found, it should increase a count by one. Once the check is done, it should display the number of uppercase letters. For some reason I am getting this weird compile error stating that symbols can't be found...
Java Code:
import java.util.*;
import java.lang.*;
public class StringCheck{
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.println("please enter a string: " );
String s = input.nextLine();
[Code] ......
View Replies
View Related
Feb 18, 2014
Write a function (or functions) that given a collection of files will produce a sum of integers from each line of each file. Each file can have any number of lines from 1 to N. Each line can contain only one integer and no other alphanumeric characters. All of the numbers from all of the files should be added to the final result. The result is just one number.
View Replies
View Related
Apr 25, 2014
1.Write a program to produce a similar output for n characters, where n is a odd number. The below output is for n=7.
Java Code:
A B C D E F G F E D C B A
A B C D E F F E D C B A
A B C D E E D C B A
A B C D D C B A
A B C C B A
A B B A
A A
mh_sh_highlight_all('java');
View Replies
View Related
May 20, 2014
import java.awt.GridLayout;
import javax.swing.*;
public class Screen
{
JButton start;
JButton reset;
JButton box[][] = new JButton[20][20];
Screen()
[Code] ....
I am trying to place the buttons on the bottom. I tried a few different things but the grid layout keeps grabbing it and making them a part of the grid at the button.
View Replies
View Related
May 26, 2014
I 'm trying to draw a button by resizing a simple button background image to fit the size of the text. Everything works well except for the actual drawing of the string. The y value that I give the Graphics object designates the baseline, however I would like to draw the the string above the y. So that the image below doesn't happen.
I gave the graphics object the y of the bottom of the "P" and would instead like to give it the value of the bottom of the "y". Is there a way to do that by reading the String's bounds or something, or is there a way to get the Graphics object to use the passed y value as the definite bottom of the String?
View Replies
View Related
Apr 20, 2015
I have a 2D array that is of type int[][]. it is populated with 1's and 0's. I need to create a method that allows me to search from the top row finding a possible path to the bottom--the path is a path of connecting cells containing 1. I need to create an array that stores the cells that are needed to be searched. When the search carries out, for each cell stored it needs to check the cells to the left, right, below and above the current cell.
I also need to create a variable to store the current cell. I thought initially it would be an int but it can't be because it needs to hold the the index of the current cell. and any of the cells searched that are an immediate neighbour of the current cell are added to the storage array.
I have these instructions but I am having trouble converting into code
Finding a path through vegetation from the top row to the bottom row: The idea is we will start from a cell in the top row and advance below for as long as we can. Since we are still not done exploring a cell until we have explored ALL it’s vegetation neighbors, we will add the cell to an array of cellsToExplore and only come back to it if the current cell we are examining is fully explored. Here is pseudo-code of the algorithm !
• Create array cellsToExplore (what size should this array be?)!
• Create an integer count that stores the number of cells in cellsToExplore!
• Go through the top row and add ALL vegetation cells to cellsToExplore!
• Create a variable to store currentCell we are exploring and set it to null.!
• while count > 0 do!
- set currentCell to the last cell in cellsToExplore (last cell added to the array).!
- label currentCell as burning vegetation!
- If the currentCell is on the bottom row then we return true (we found the path).!
- if the cell below currentCell is vegetation then add the cell below to the cellsToExplore array.!
- else if cell to the right of currentCell is vegetation then add the cell to the right to cellsToExplore!
- else if cell to the left of currentCell is vegetation then add the cell to the left to cellsToExplore!
- else if cell above the currentCell is vegetation then add the cell above to cellsToExplore.!
- else remove the currentCell from the cellsToExplore (we are done with this cell). !
• Return false!
View Replies
View Related
Mar 17, 2014
I am having issues with drawing shapes from bottom right to top left.
Issue:
- g.drawRect() will show like I am calling g.fillRect()
- other shapes will not even show the shape in that area
Needs:
- g.drawSHAPE needs to show and not be filled unless I have my fill checkbox selected
The Program:
- Create a JFrame with a draw panel and a component panel
- have a combobox with shapes that, when selected, will draw that shape in the draw panel
- have a button that, when clicked, will launch JColorChooser to change the color of the drawn shape (draw panel is set to black)
- have a checkbox that, when checked, fills the shape
- have mouse listeners to adjust X and Y and will instantly update the shapes size to where you drag/click/press/release
Code for my drawRect():
Java Code:
// if statement to check if mouse drag X is less than starting X
if(x2 <= x){
if(emptyORfill.isSelected()) // emptyORfill is my JCheckBox
g.fillRect(x2, y, x-x2, y2-y); // x-x2 is the same as Math.abs(x2-x)
else
g.drawRect(x2, y, x-x2, y2-y);
[Code] .....
This is just for my Rectangle. This will show a filled rectangle when both mouse drag X and Y are less then the starting X and Y. If I take this fully functional code and adapt it to drawRoundRect(), the round rectangle wont even show the shape when mouse drag X and Y are less than the starting X and Y but will be fine if one or the other is less than the starting X or Y. NOTE: This same exact code worked on my classmates laptop in her program, but in my program on her laptop it did not. She took out the "else" in the else if's and just made them if statements all the way down and it worked on her laptop in my program, but the same "fix" did not work on my pc.
My mouse listener just sets X and Y values in my Shape class that updates my shape methods. I have an item listener for my comboBox that sets default values when a new selection is made and enables/disables editable on my fill checkbox for certain shapes. My action listener looks for the button click and the checkBox click.
View Replies
View Related
Aug 25, 2014
I'm having some trouble with getting this program to read an input of morse code and then produce an output of English. When typing in morse code for the phrase 'the string', the output looks something like this:
- .... .
t
h
... - .-. .. -. --.
s
t
r
i
n
The English-->Morse works just fine.
import java.util.Scanner;
public class project1
{
static final String[] alpha = {
"a", "b", "c", "d", "e", "f", "g", "h", "i",
"j", "k", "l", "m", "n", "o", "p", "q", "r",
"s", "t", "u", "v", "w", "x", "y", "z", " "
[Code] .....
View Replies
View Related
Feb 26, 2014
I have a question: I have a Java/JSP/JavaScript project that access back end Oracle database, and provide interaction through tomcat. After we deployed our project, I found one button does not generate necessary warning message from server, but when I deployed and tested our project on local PC, it does generate correct warning message. I am using the same IE, same tomcat version, and I am sure my container is pointing to the same database, and I am sure I using same version of project code by checking with GIT.
Here is the button that I click:
<a target="frmMain" href="RealignServlet?button=REALIGNMENT" title="Procedure Alignment">Align</a><br>
And here is part of the code of RealignServlet:
public class RealignServlet extends SiapBaseServlet {
private static final long serialVersionUID = 1L;
private static final Logger logger = AppLogger.getLogger(RealignServlet.class.getName());
private static final String PROC_QUERY_JSP = "ProcQuery.jsp";
private static final String REALIGN = "REALIGNMENT";
[Code] .....
Our problem is server could not generate alignMsg. But we can get it on local deployed project.
View Replies
View Related
Feb 20, 2014
I created this simple vector java program where ball falling and when collide with the bar below, the ball stops.
I need to make the ball falling randomly from different direction and also need to make the bar move left right using keyboard arrow.
Code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
//using timer to increase the counter
[code].....
View Replies
View Related
Nov 18, 2014
I am working on program and have been struggling to get around step 5 and 6 given below.
I have got on with the first couple of points. Where to begin with steps 5 and 6.
Java Code:
class Hourglass {
int height;
int bottomHalf;
public Hourglass (int h) {
height =h;
}
public Hourglass (){
height=3;
}
/*Write a method dropGrain that simulates one grain of sand falling into the bottom half of the Hourglass. If all the sand is already at the bottom before a grain is dropped, this method should cause the hourglass to be flipped, meaning that all the sand will be in the top again. Then, one grain of sand should fall. */
//Hint: this method can be quite short. All you need to do is update one attribute.
public void dropGrain(){
}
/*Write a method getHeapHeight() which returns the height of the heap of sand in the bottom of the hourglass.
Hint: a triangle of height h contains h*h grains (=1+3+5+...+h).
So determining the height when the amount of sand in the bottom half is a square (1,4,9,16,...) is easy. Think about what happens if the amount of sand is not exactly a square.*/
public int getHeapHeight() {
} mh_sh_highlight_all('java');
View Replies
View Related
Sep 30, 2014
PaintWindow pw = new PaintWindow();
Random rand = new Random();
ImageIcon image = new ImageIcon("C:/Users/Ghostkilla/Desktop/gubbe.jpg");
setWidth(pw.getBackgroundWidth());
int height = pw.getBackgroundHeight();
[Code] ....
If you run this code it will move a picture from right to left and hit the left wall and then go to right again leaving the window (It stops there). I want to make so it hits left and then right wall continuously till someones close the window. So basically I am using a for loop to make it go left right all the time.
How to make so the picture moves from bottomleftcorner to toprightcorner diagonally without leaving the window.
View Replies
View Related
Dec 5, 2014
java program that will determine if the matrix is a lower or upper triangular matrix. I only need to use java.util.Scanner;.
View Replies
View Related
Nov 27, 2014
I am building a little application for personal use where I can track my finance. Now, what I would like to get is an always visible JTable "footer" OR horizontal space field attached to the bottom of the window. The idea is that scrolling down/up wouldn't affect it's visibility(like JTable header). Might a picture tell a thousand words: see attachment.
I am wondering, maybe JTable OR TableModel class has a property to solve this problem(I haven't found any)? Or shall I make another ScrollPane/JPanel? Which path of search shall I pursue?
View Replies
View Related