Moving Drawn Shape Around By Dragging And Resizing - Functions Do Not Work

Oct 16, 2014

This class is part of a homework assignment and I have a problem:

package event;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import model.Model;
import shapes.Rectangle;
import shapes.Shape;
import shapes.Line;
public class ShapeMouseHandler extends MouseAdapter {
private Model model;

[Code] .....

I want to be able to move a drawn shape around by dragging and resizing a given shape (I can click that on a panel, the choosing-mechanism works)

I have tried for a week now to get the move-by-dragging and resizing to work, no success. What the code should look like?

View Replies


ADVERTISEMENT

Swing/AWT/SWT :: Deleting Shape Drawn On JPanel

Apr 7, 2015

I want to delete the shape i have drawn on the panel. Here is my code

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.geom.Rectangle2D;

[Code] ....

Why it is not deleting my rectangle.

View Replies View Related

Java 2D Drawing Application - Shape Should Be Drawn As Mouse Is Dragged

Nov 4, 2014

Java 2D Drawing Application. The application will contain the following elements:

a) an Undo button to undo the last shape drawn.

b) a Clear button to clear all shapes from the drawing.

c) a combo box for selecting the shape to draw, a line, oval, or rectangle.

d) a checkbox which specifies if the shape should be filled or unfilled.

e) a checkbox to specify whether to paint using a gradient.

f) two JButtons that each show a JColorChooser dialog to allow the user to choose the first and second color in the gradient.

g) a text field for entering the Stroke width.

h) a text field for entering the Stroke dash length.

I) a checkbox for specifying whether to draw a dashed or solid line.

j) a JPanel on which the shapes are drawn.

k) a status bar JLabel at the bottom of the frame that displays the current location of the mouse on the draw panel.

If the user selects to draw with a gradient, set the Paint on the shape to be a gradient of the two colors chosen by the user. If the user does not chosen to draw with a gradient, the Paint with a solid color of the 1st Color.

Note: When dragging the mouse to create a new shape, the shape should be drawn as the mouse is dragged.

Java Code:

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.Point;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;

[Code] ....

Missing things for the code check boxes for color gradients, line width and dashed.

View Replies View Related

Dragging Mouse To Draw A Line

May 16, 2014

I'm doing a exercise for dragging mouse to draw a line. I found a code to do this, but I don't know something in the code. example array Shape in the code.

import java.awt.AlphaComposite;
import java.awt.BasicStroke;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;

[Code] ....

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

Swing/AWT/SWT :: Dragging Image Beyond JFrame Limits

Jun 26, 2014

How to drag an image beyond the JFrame limits. In Netbeans, when you drag a Java file editor pane out of the main application frame and onto a second monitor, Netbeans provides a semi-transparent image of the pane you're dragging. I would like to reproduce this effect in my own code. I've been able to do this in a test program (code below) using a glass pane, but cannot figure out a good way to get the image to drag beyond the limits of the main application frame. I looked at the DragnGhostDemo from SwingHacks but it has the same limitation. How this could be accomplished?

In the test application below, click on on the button and drag it's image across the application frame.

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Graphics;

[Code] .....

View Replies View Related

Resizing 2D Arrays

Sep 19, 2014

How do i increase the size of a 2D array from 2X2 to 4X4 where only the boundary elements are zeroes and the rest of them remain the same?

View Replies View Related

Hiding User-drawn Graphics

Apr 15, 2014

I'm creating a game called Mouse Trap and I'm having an issue with a graphic drawn using AWT. Basically, when the mouse collides with the cheese, I want the cheese to disappear, or call (cheese[i].hide()). However, the cheese does not appear. hide() works for all other objects that inherit from PFigure, but the cheese will not. It's created a major issue in my game, and basically the only task left to accomplish.I believe my problem lies within Cheese.java, method draw(). For example, if I replace it with an example drawing, this problem goes away!:

public void draw() {
Graphics g = panel.getGraphics();
g.setColor(Color.blue);
g.drawOval(x + width / 4 , y + 1, width / 2, height / 2);

[Code] ....

I have three classes below that most likely involve the problem, feel free to ask if you need the others.PFigure.java (This class cannot be changed as a requirement to my project)

import java.awt.*;
 public abstract class PFigure implements Comparable {
protected int x, y; // Current position of the figure
protected int width, height; // Drawn (displayed) this size
protected int priority; // Can use to determine "winner"
protected Panel panel; // Panel the figure lives on

[code]....

View Replies View Related

Swing/AWT/SWT :: How To Disable Resizing Of Jframe

Feb 7, 2014

I want my jrame should not be resized when clicking on maximize button of window.and for this i have put setResizable(false)in the constructor of class which extends Jframe.

View Replies View Related

Resizing JPanel And JFrame At Same Time

Jan 7, 2015

I am trying to develop a GUI through hard coding. I encountered a challenge:

I created a Jframe and onto this I added a JPanel. I assigned thge flow layout manager of the frame to null(because i want to do the positioning of my components manually)

The program is running perfect except when i click the maximise button of the frame, the JPanel does not change its size.

With Netbeans IDE - i found that the propert is Horizontal Resizable propert. I have tried to look for the method but in vain.

I am trying to develop identical things from hard coding and in drag and drop environment. so with drag and drop its easy but in hard coding how do I work it out?

Here is the code :

public class JPanelDemo {
JFrame frame;
JPanel panel;
JPanelDemo(){
createFrame();

[Code] ....

View Replies View Related

Matching Drawn Card To Its GIF In ArrayList?

May 4, 2015

I'm creating a card game and I'm having trouble getting a card gif to display. A card is drawn from an 52 card deck arraylist, and I then need to match that drawn card with the similarly named gif in an arraylist of card gifs, to display the gif on a card GUI. I have put my game, card, deck and graphical class below:

Card -
public class Card {
public String number;
public String suit;
public Card(String n, String s) {
number = n;
suit = s;

[Code] ....

The arrayList of card gifs (which contains all 52 gifs for the cards) is in the graphical class and my arrayList that contains the deck of cards in textual form (that I've imported from a textfile) is in deck. The names of the gifs in the gif arraylist are the same as the card names in my textual card arraylist (for example, 3h.gif is 3h in my card arraylist), so I believe I can use a .equals statement to match the card that has been drawn to the gif.

Here is what the gifs look like in their folder, which is an arraylist in my graphical class :

Here is what the drawn card looks like after the textual card arraylist has been shuffled:

The brown card in that image isn't the displayed card that has been drawn, it's just a graphical deck that I put in, I can't get the card that has been drawn on the GUI to display on the actual card frame, as you can see.

View Replies View Related

Auto Resizing Bucket Hash Table

Apr 30, 2015

I have to write a resize method so that when my Bucket gets to a certain point, then it resizes the bucket when it is called. What is happening is, I am getting strange results when I run the method. My mean bucket length should be at 2.5 for the last insertion, but I am getting something like 0.1346. Here is my dictionary class

// The "Dictionary" class.
// The Dictionary class implemented using hashing. Hash buckets are used. A dictionary contains a set of data elements with corresponding keys. Each element is inserted into the dictionary with a key. Later the key can be used to look up the element. Using the key, an element can be changed or it can be deleted from the dictionary. There is also an operation for checking to see if the dictionary is empty.

package dictionary;
 public class Dictionary {
protected final static int MAX_BUCKETS = 1000; // number of buckets
protected DictHashEntry[] buckets; // the bucket array
private int collisionCount = 0;

[Code] .....

View Replies View Related

Swing/AWT/SWT :: Automatic Resizing Of JPanel In JFrame?

Jan 29, 2015

I have created a JFrame that contains 3 JPanel.

My problem is, when i clicked in the bouton to expand the Frame,the 3 JPanel are fixed and do not expanded with the Jframe.

View Replies View Related

Swing/AWT/SWT :: Resizing Images In Jbuttons In Grid Layout

Jun 21, 2014

Am trying to dynamically insert buttons (which will be presenting card in a frame) using grid layout.As shown image is getting inserted but its not fit in button.I tried Darryl's Stretch icon as well but of no support.

panel_playerCards.setLayout(new GridLayout(2,10, 0, 0));
for(int i=0;i<9;i++){
StretchIcon icon=new StretchIcon(UnoGui.class.getResource("/UnoColors/green/card10.png"));
btnArr[i].setIcon(icon);
btnArr[i].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
}
});

View Replies View Related

Java Tictactoe Game Images Won't Paint / Be Drawn

Jul 24, 2014

I'm following this tutorial![URL] I've copied over a lot of the code and also copied/pasted other parts! I understand how it works, but I can't figure out why the "X" or "O" won't paint onto the screen when the window is clicked on! Only a button is drawn when I click on the screen.

/*
package tictactoe;
import javax.swing.*;
import java.awt.Image;
import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;
import java.awt.Toolkit;//look into this library

[code]....

View Replies View Related

Is It Possible To Scan Logical Gates From Hand-drawn Image

May 12, 2015

I am thinking of a project for my university the teachers liked it but I am not sure if its even possible.I am trying to make an andriod app. What I want to do is take a picture of a hand drawn logic circuit (having the AND, OR, NOT ... gates) recognize the gates, and make a circuit in the moblie and run it on all possible inputs.

For this I will have to make a simulator on mobile, that I dont think is the hard part. The problem is how could recognize the gates from a picture. Example of logical circuit is attached ( assume its hand drawn )..I found out that theres a edge detection plugin in java but still I dont think its enought to recognize the gates. Please share any algorithm or any technique or tools that I can use to make this thing.

View Replies View Related

JavaFX 2.0 :: How To Set Divider Positions For SplitPane After Window Resizing

Sep 30, 2014

I would like to keep the same values of the positions for dividers (SplitPane) even if the width or the height of the window changes. I want to keep the proportion of the differents dividers. After resizing the window, the values of positions are not the sames ! I use this source without success :

  stage.widthProperty().addListener(new ChangeListener<Number>() {
  @Override public void changed( ObservableValue<? extends Number> observableValue, Number number, Number number2) {
               sp.setDividerPositions(0.40f, 0.02f, 0.54f);

[Code] ....

View Replies View Related

Swing/AWT/SWT :: Keeping Track Of Strings Drawn On JPanel Using Paint

Nov 1, 2014

So, I have this simple program that paints a string on JPanel using g2.drawString("Hello world", 40, 120). Basically, I want to be able to keep track of many strings on the JPanel at once. I'm not sure how to do this. For example, I would want to have an ArrayList of objects that keep track of these strings.

I want to be able to click-and-drag these strings so I will need to know there locations, etc.

Right now, using g2.drawString, it only draws the string. I want something like gw.draw(myStringObject).

import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import javax.swing.JFrame;
import javax.swing.JPanel;

[Code] .....

View Replies View Related

Scrollpane Scrollbars To Entire Jframe When Resizing / Adding Components

Jul 23, 2013

I am trying to add scrollbars to my frame containing many different components and appearing when user resizes the window with the mouse adds pictures and admin of this online application adds labels or other components.

I want scrollbars to appear when the frame  is resized and has components you don't see under so you can scroll down.
 
If I have for example this code, how i add the scrollbars when i make frame smaller ?
 
public class Test extends JFrame {
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
   EventQueue.invokeLater(new Runnable() {

[Code] ....

View Replies View Related

Creating Menu Using Java - Animating Drawn Object On Button Click

Nov 7, 2014

i would like to create a menu like below where if i clicked on "DRAW", a frame to draw will appear and when i clicked on animate, I can animate an object drawn. I tried on using JButton, but I donno how to customize the design n so I would like to know is there other ways so tat my menu will appear as below?

View Replies View Related

Functions Are Not Recognized

Oct 29, 2014

// set up the generator
CMSSignedDataGenerator gen = new CMSSignedDataGenerator();
gen.addSigner(key, cert, CMSSignedDataGenerator.DIGEST_SHA224);
gen.addCertificatesAndCRLs(certsAndCRLs);
addsigner and addCertificatesAndCRLs are not found in netbeans.

Which version of Bouncy Castle and JDK version this supports?

View Replies View Related

Use Of Functions In Java

Feb 4, 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.

For either, what we are looking for is:

1. Clear separation of concerns
2. Well defined objects / interfaces
3. Application of good OO design principles to solve the problem
4. No code duplication
5. Test Driven Development
6. Well refactored code
7. Well tested code

View Replies View Related

Using Modulus To Alternate Between 2 Functions?

Feb 24, 2014

This code is for a game I'm making. I'm new to using modulus, and I've been looking all over the place for a tutorial that I can understand. No luck. :

What I'm trying to do is get the console to print "enemy hits player" as soon as enemyAttacksPlayer() is called.

After one second, "player hits enemy" should be printed, so it alternates between these two lines every second.

The issue is when I call enemyAttacksPlayer(), it takes a few seconds to print any lines, and this delay is kinda annoying.

public int time = 0;
 public void enemyAttacksPlayer() {
time++;
if (time % 120 == 60) {
System.out.println("enemy hits player");
} if (time % 120 == 0) {
System.out.println("player hits enemy");
}
}

I think I may be using % wrong.

View Replies View Related

Ambiguity In Overloaded Functions

Sep 22, 2014

I have an overloaded function 'f' as follows:

1. public void f(int i, long j){System.out.println("1");}
2. public void f(int...i){System.out.println("2");}
3. public void f(long l, long p){System.out.println("3");}
4. public void f(int j, int k){System.out.println("4");}

With the function call: f(1,2), the output is: 4.

My questions are the following:

a. Why is the compiler choosing #4 to execute and not the rest?
b. If I remove 4 and replace it with: 5. public void f(long j, int k){System.out.println("5");}, why does the compiler now give an error complaining of ambiguous function defintions when 'f' is called?

View Replies View Related

Using Same Parameters But Different Functions - Allowed Or Not?

Feb 12, 2014

I have made a class here that has two methods. As you guys can notice, in my two methods that I made, I have listed some arguments in there with parameters. My question is that the variables im using in first method, can they be identical on my second method? Is this ok to do?

public class StudentScore {
private int math;
private int science;
private int calc;
private int history;
private int pe;
 
[Code] .....

View Replies View Related

Basic Calculator Functions

Jul 2, 2014

my task is to add a few functions to an example calculator. I managed to add a divide button but I simply can't figure out how to add a working Pi and reciprocal function.

package newjavaproject;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class CalculateurNC extends Applet {

[code]....

View Replies View Related







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