Specify How To Delete Only Certain Amount Of Objects On Screen In Graphics Window

Oct 10, 2014

I have a question about how to delete only a certain amount of objects on screen in a graphics window. I have a method that will enable me to get rid of every object of the same type off screen, for example this method:

Java Code:

public void deleteTrees() {
//clears all tree trunks and leaves
for (Iterator<GRect> it = historyT.iterator(); it.hasNext();) {
GObject gobj = it.next();
this.remove(gobj);

[Code] ....

That Will delete all trees.

Now In my main method I populate the screen with trees by doing this

Java Code:

for (int xpos = 10; xpos < getWidth() - 40; xpos += getWidth() / 8) {
drawTree(150, 200, xpos, getHeight() / 2.0 - 50);
historyT.add(trunk);
historyL.add(leave);

} mh_sh_highlight_all('java');

My question is how to specify only deleting x amount of trees instead of the whole thing. I pretty sure I need to use something like history.remove(trunk) and to iterate through the amount of trees specified, but not sure how to implement that.

View Replies


ADVERTISEMENT

Drawing Rectangle Onto Screen - Window Pops Up But No Graphics

Jan 7, 2014

I run this code and a window will pop up, but no graphics :(

I tried to draw a rectangle onto the screen, but it will not show up. I was told to extend JComponent, and I did, but it still does not work.

Java Code:

import javax.swing.*;
import java.awt.Graphics;
import javax.swing.SwingUtilities;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.BorderFactory;
import java.awt.Color;

[Code] .....

View Replies View Related

ACM Graphics Program - How To Set Location Of Entire Window

Jun 15, 2014

I have one quick question. If you are extending the acm graphics program, how can you set the location of the entire window? All the set location methods within the graphics program only seem to set the location of graphical objects. I know with JFrames I can use the setLocationRelativeTo(null) to position the JFrame in the center. How to set the location of a graphics window.

View Replies View Related

How To Put Console On JFrame Or Graphics Program Window

Sep 8, 2014

how to put a console on a JFrame or on graphics window. I thought about simply using a JtextField however I don't have access to the readline command since it appears to me that it is only found in a Console Program. So basically I was wondering how to put up a console on JFrame so I can issue commands on it and watch graphical stuff happen on the same screen(minus where the console box is of course).

View Replies View Related

Swing/AWT/SWT :: Dragging Window Downwards - Screen Alignment?

Oct 29, 2014

I am trying to drag the window down wards and screen has alignment issues. I tried to use WindowListeners, Component Listeners, MouseListeners ect…

But still this problem persists as only I release the mouse after drag down it appears fine that we have handled ComponentResized() method. So how to restrict component size while keep dragging down?

View Replies View Related

How To Remove Objects In Graphics Program

Jul 9, 2014

How to remove multiple objects that are onscreen in a java graphics program(specifically the one from the acm library). The clearAll works fine but I would like to keep the background in my frame. I just want to be able to do something like removing all the trees by typing in a phase into a console program. Here is a small snippet of code with details of what I am trying to achieve.

Java Code:

public void command(){
Dictionary dic=new Dictionary();
//dic list of all phases that will either make animations or remove things in a graphical window
String line = readLine("Type here: ");
if (line.equals(dic.clearActions[i])) {
cleared=true;

[Code] ....

View Replies View Related

Simple Cannon Game - How To Delete Objects

Oct 22, 2014

I am using libgdx and box2d to try to make a simple cannon game.

When I have the cannonball collide with another object I want to delete that object and have it stop calling all of it's functions. It doesn't seem like I can have it delete itself, and the contactListener has a reference to the cannonball and other object, but if I set either to null, it seems the original reference still exists and the object isn't deleted.

View Replies View Related

Making Bunch Of Tree Trunks - How To Delete Entire Array Of Objects

Jul 30, 2014

I am trying to delete entire set of objects from my graphics program. Specifically I am trying to make a bunch of tree trunks, 10 in total, and then delete them all by pressing a button. I can manage to make the trunks but I can only delete one of them.

Below I can walk you through some of my code step by step to show you what I am trying to do:

Java Code:

public void drawTrunk(double width, double height, double xpos, double ypos) {
trunks = new ArrayList(10);
trunk = new GRect(width / 15.0, height / 3.0);
trunk.setFilled(true);
trunk.setFillColor(Color.orange);

[Code] .....

So basically I just would like to know how to make this work?

View Replies View Related

How To Position 8 Objects Across Middle Of Screen

Oct 18, 2014

I am trying to draw add flowers on a graphics window. I can do this just fine, however the position starts from the far left and goes to the far right. I would like to position the 8 flowers in the center of the screen but can't seem to get the right formula to do so. Here is what I have so far to draw the flower, which is simply a GOval nothing complex:

Java Code:

box.flowers=8;
for (int xpos1 = 10; xpos1 < getWidth() - 40; xpos1 += getWidth() / box.flowers) {
box.drawFlowers(xpos1, 400);
} mh_sh_highlight_all('java');

The box size of the window is 800 by 600. Ideally I would like to place x amount of flowers spread across the middle of the screen. How might I do this???

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

JavaFX 2.0 :: Manipulating Several Windows (Window Inside Window)

Apr 6, 2015

I am new to javafx I start using it instead of swing i used the scene builder for my forms the problem i faced i don't know how to have main screen with menu bar at top and depending the select from the menu it will open other windows and those window must be inside my window just like for example netbeans.

I don't need to open new window in separate i need all windows inside my main window and controlling over them minimize maximize perhaps.

View Replies View Related

How To Return Value (amount) In 10 Years

Mar 14, 2014

Here's the small project... but how can I return the value (amount) in 10 years ? The way I did, the program just doesnt return anything...

import java.util.Scanner;
public class FutureValue
{
public static void main (String []args) {
double amount = 0;
double apr = 0;
System.out.println("How much money would you like to invest?");

[Code] ....

View Replies View Related

Copying Data Objects To Serializable Objects

Jul 27, 2014

I am currently working on a project where I need to return data from a database over RMI to a client who requests it. Some of the fields in the Data Object can not be seen by the client so I need to create another object to send over the network instead. The method I use is this...

public static SerializableObject createSerializableObjectFromDataObject(DataObject dataObject){
SerializableObject serializableObject = new SerializableObject();
serializableObject.setField(dataObject.getField());
serializableObject.setAnotherField(dataObject.getAnotherField());
return serializableObject;
}

Is there a better way of doing this? I am creating many subclasses DataObject which all require this static method to be implemented and I can't push it into the superclass because each one needs custom behaviour.

View Replies View Related

JSP :: How To Display Amount In Indian Format

Apr 30, 2014

i want to display a amount in indian currency format,

i.e=10000000=this iwant show is=1,00,00,000 rather than 10,000,000

View Replies View Related

Show Amount Of Number According To Its Interval

Jul 4, 2014

I am trying to make a program that get input value 1-200 from user. However I would like to make the program to show warning if the input number is not within the range of 1-200. In the end I would like to show the amount of number according to its interval (i.e less 50, 51-100 and so on) ....

import java.util.Scanner;
class test {
public static void main (String[] args) {
int number[]= new int[5];
int number2[]= new int[5];
int a=0,b=0,c=0,d=0,i=0;

[Code] .....

View Replies View Related

Making A Loop Go A Certain Amount Of Times?

Jun 14, 2014

I am having is not being able to print out the diamond the amount of times the user enters (for example, when it asks how many diamonds, I enter a 2 and only one diamond comes out.)

import java.util.Scanner;
public class Pattern5
{
public static void main(String[] args)
{
// For this pattern program, ask the user how many diamonds
// she would like to print to the screen. The following pattern is one diamond.

[code]...

View Replies View Related

How To Delete A Thread

Nov 19, 2014

Doesn't matter now, I solved it but I don't know how to delete a thread...

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

Delete From ArrayList

Dec 7, 2014

I've this "program" that shall manage to register a dog, show a list of all registerd dogs and delete dogs from the list.. And I'm stuck at the latter one. So I've to classes, one for the dog and one for register/program. This is my main program

package hundRegister;
import java.util.Scanner;
import java.util.ArrayList;
public class HundProgram {
private static Scanner tangentbord = new Scanner (System.in);
private static ArrayList<Hund> hundlista = new ArrayList<>();

[Code] ......

So, when I enter a name on a dog that exist on my list, it just jumps down to } else { and write that dog can't be found even if I write the exact name on the dog.

I can't see what I'm doing wrong, been trying out different methods now.

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

Calculate Quantity / Price And Total Amount

Apr 10, 2015

How to calculate the qty and price and total of the amount in total column.

View Replies View Related

How To Get A Program To Repeat X Amount Of Times Automatically

Oct 27, 2014

Ii am trying run a do while loop on java a specific amount of times for example if i were to type in "Enter number of years" and enter 4. i need the loop to execute 4 times or if i said 6 times then i would be 6. the program i have repeats it and takes it back to reentering "Enter number of years" i need it to execute by its self x amount of times. here is what i have so far

System.out.println("Enter the number of years: ");
years = keyboard.nextInt();
rainfall = generator.nextInt(10) + 1;
System.out.println("Year " + "rainfall amounts were");;
for (int months = 1; months <= 12; months++)

[Code]...

View Replies View Related

JSF :: When Submit Html Form / Value Of Amount Does Not Appear In Second Page

Mar 24, 2014

i have this code
////////////////////////////////////////////
<form name="myform" action="http://localhost:8080/EASYPAY.COM/faces/newxhtml.xhtml"method="post">
amount
<input type="text" name="amount"value="">
<input type="submit" >
</form>

[code]...

when i submit the html form the value of amount does not appear in the second jsf page new.xhtml what might be the problem

View Replies View Related

Perform Action Only If Certain Amount Of Time Has Passed

Sep 18, 2014

public static void main(String[] args) {
boolean t=false;
long cuTime = System.currentTimeMillis()
while(t==false) {
System.out.println(cuTime);
long g=cuTime+2000;

[Code] ....

I tried this and it includes a while loop as the whole program has to wait until this while loop executes. So the entire program slows down. Is there any way to do this without a while loop

View Replies View Related

How To Perform Action Only If Certain Amount Of Time Passed

Sep 18, 2014

public static void main(String[] args) {
boolean t=false; 
long cuTime = System.currentTimeMillis();
while(t==false) {
System.out.println(cuTime);
long g=cuTime+2000;

[Code] ....

I tried this and it includes a while loop. therefor the whole program has to wait until this while loop executes. So the entire program slows down. Is there any way to do this without a while loop...

View Replies View Related







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