Rotating A Shape - Graphics2D Rotate (theta) Method

Jun 14, 2014

I am having a problem rotating a shape I am using the transformation rotation matrix and don't seem to be getting the results I expected. Now I know a lot of programmers will just tell me to use the Graphics2D rotate(theta) Method.But I would like to create this ability through writing the code.

package com.trigonometry;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.Timer;

[Code] ....

View Replies


ADVERTISEMENT

Time Complexity (theta) For Loops With Special Case?

Sep 9, 2014

I can't able to find the theta for some type of code like.

for(i=1;i<=n;i++){
for(j=i;j>=1;j=j/3){
....
}
}

How to find the theta for the above code.

for(i=1;i<=n;i++){
for(j=i;j>=1;j=j/K){
....
}
}

and How to find number of steps or time complexity for inner loop if k=3 (odd)

View Replies View Related

Java - Polygon Shrinks Before Rotating

Dec 22, 2014

I have a java program which rotates a rectangular polygon. My program is having a problem. As soon as it starts rotating, it shrinks. The polygon is rotating perfectly though. I am trying but unable to figure out the cause.Main class which has an infinite loop (game loop) to rotate polygon continuously :-Java Code:

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

[code]....

View Replies View Related

Printing A Functioning JTextField On Graphics2D

Sep 10, 2014

I recently started making some Java games, and now I'm having some troubles,

It seems like I can't place a functioning JTextField on my Graphics2D object, I can place images, even the image of the component itself:

Java Code: Graphics2D g2d = (Graphics2D) this.getGraphics();
JTextField jtf = new JTextField();
jtf.setSize(150, 70);
jtf.setLocation(220, 220);
jtf.print(g2d); mh_sh_highlight_all('java');

How can I make it work? I really need it for character name creation, chat, etc... so making a JDialog isn't an option for me.

View Replies View Related

How To Set Size For Panel With Graphics2D Object

Oct 1, 2014

I am writing a program to solve Sudoku puzzles. I create the user interface using AWT/Swing.One panel of the main window (JFrame object) contains a Graphics2D component only (a grid for the sudoku puzzle). The problem is that this panel is too small for its contents when it is created. I have tried many things to make it bigger (like the setSize method of the panel), but to no avail. Who can tell me how I can make the panel with a single Graphics2D object larger?

Below is the code for the main window, which is a JFrame object. I set its size to 400 x 400 to have ample room for all panels. I then create two panels: a sudoku panel that contains the sudoku grid and a button panel that contains two buttons. The button panel has a flow layout.

I then create the main panel. This has a vertical BoxLayout. Finally I add the sudoku panel and the button panel to the main panel and the main panel to the frame.

public class ViewController_Graphics extends JFrame {
JButton solveButton = new JButton("Solve");
JButton nakedSinglesButton = new JButton("Naked Singles");

public ViewController_Graphics(SudokuModel model) {
super("Sudoku");
setSize(400,400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLookAndFeel();
// create sudoku panel

[code]....

When I run the program, the following Window shows up:the button panel is exactly in the middle (and it remains in the middle, no matter how I resize the window). And there is not enough room for the sudoku panel. How can I make enough room for the sudoku panel when the window is created?

View Replies View Related

Swing/AWT/SWT :: Rotating Buffered Image And Then Return It

Mar 7, 2010

I wanted to write a method which gets a buffered image as parameter, rotates it 90 degrees clockwise around its top left corner, and then returns it. This method will be call from another method which then draws the rotated image on a rather large background which consists of many other images.

Here is the code I have so far:

public static BufferedImage rotate(BufferedImage img) {
int w = img.getWidth();
int h = img.getHeight();
BufferedImage newImage = new BufferedImage(width, height, img.getType());
Graphics2D g2 = newImage.createGraphics();
g2.rotate(Math.toRadians(90), w/2, h/2);
g2.drawImage(img,null,0,0);
return newImage;
}

This method does rotate an image 90 degrees, but when the calling method recieves this image and displays it on the bigger frame, parts of the rotated image is cut. I think because the frame holding the returned image is not big enough. I've tried playing around with the code a lot, chaging the sizes of different images, and trying AffineTransform features, but I have had no luck.

View Replies View Related

How To Make Line To Follow Rectangle When Moving Or Rotating

Oct 18, 2014

After i draw line between 2 fixed points on two different rectangles i need to rotate them. The problem is that my line is not updated, it stays on the same x1,y1 x2,y2. How to make line to follow rectangle when they are moving or rotating? I wrote some example code to demonstrate this.

Object that i want to draw:

[public class Object {
private int xPos;
private int yPos;
private int width;
private int height;
float xDistance = 0f;
float yDistance = 0f;
double angleToTurn = 0.0;

[Code] ....

View Replies View Related

Swing/AWT/SWT :: Graphics2D / Drawing Double Rounded Corners Border?

Mar 26, 2014

I am struggling to make a double border which has rounded corners. The border should be 2 parallel lines.

I made something which looks almost good, but if you look closer there are a few wrong things.To achieve this, I made 2 paths, then painted them in 2 different colours.

The main problem is painting with AA, because the colours overlap and are affected.

I think it would be smoother to paint a single path using 2 colours.

For the first problem, I think some kind of a stroke would be enough. But, if I build a stroke, it's almost same thing like drawing the path twice, like I did before. Anyway i think that would fix AA problem. But still, maybe I can achieve a smoother effect for the corners.

Question:Maybe something with a 2x1 Texture ? It's possible to achieve this ? I know I tried this before and when a curve was encountered the direction of the texture was wrong and looked messy.

PS: Ignore the blueish thing, it's a dragged component to activate the highlight border.

View Replies View Related

Rotate Through JTabbedPanels At 5 Second Intervals

Apr 5, 2014

I have a list of Tabs which are dynamic depending on how many cars are in a database. If there are 10 cars there will be 10 tabs called car 1, car 2, car 3, etc. Each tab simply displays a photo and details of the car.

I have a JMenuItem that says start SlideShow and end SlideShow

What i would like to do is automatically slide through tabs when the start Slideshow is clicked.

View Replies View Related

Way To Rotate JPanel In Java

Jul 28, 2014

Is there any way to Rotate jPanel in java (without using Paint Function).

View Replies View Related

Swing/AWT/SWT :: How To Rotate Arrow

Mar 11, 2015

i want to rotate this shape using AffineTransform without changing its position and its size. i want the arrow to be in a straight line. how can i proceed??

I have use this but the place of the arrow is changing.

AffineTransform at = new AffineTransform();
at.rotate(Math.toRadians(45));
c.transform(at);

here is my code for arrow

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

[Code]....

View Replies View Related

Rotate Image In Java?

May 23, 2014

I have been trying to rotate an image on a certain degree, and still remain on the same position. I have tried g.rotate, but it just rotate around a center, and it does not keep the same position as before.

View Replies View Related

Swing/AWT/SWT :: How To Rotate JLabel

Jul 21, 2014

I have written a code to rotate a Jlabel but i am facing some problems.

import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.MouseInfo;
import javax.imageio.ImageIO;

[Code] ....

View Replies View Related

BufferedImage Auto Rotate JPG

Apr 11, 2015

I need my Java program (I'm working in Eclipse if it matters) to detect if an image is a portrait or a landscape, but since i am directly downloading them from my camera they only have it written somewhere in metadata, the image width and height is the same for landscape and portrait. I have the rotation code and the rest of the program working, but I need to somehow get a variable (for example integer one) to tell me if it is a portrait or a landscape image. I tried getting to the metadata but my Eclipse decided that import com.drew.metadata.Metadata; cannot be resolved.

BufferedImage image = ImageIO.read(new File(imagePath, imageName)); and after I get the variable "orientation" it looks like this

int orientation = ???;
BufferedImage newImage = oldImage;
if (orientation>1){
newImage = rotate(oldImage);
}

View Replies View Related

Rotate Left Bitwise Shift?

May 13, 2014

I'm trying to replicate the rol(rotate left) instruction in assembly though can only get as far as shifting the bits with '<<' or doing Long.rotateLeft(var, 5). Both of these method don't wrap around the bits as the rol instruction does.

View Replies View Related

How To Rotate Object And Give Colour Inside

Mar 13, 2014

package id.ac.ub.ptiik.computergraphics;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.util.glu.GLU.*;
public class CG04_3DTransformation extends CGApplication {
protected boolean wireframe = true;

[Code] .....

View Replies View Related

Swing/AWT/SWT :: How To Rotate 2D Square Using Maths Equations Through OpenGL

Feb 23, 2015

So I need to create a square and make it rotate when the letter R is pressed and then make it stop when the letter R is pressed again. I need make it rotate using a maths equation that I can't figure it out myself right this moment.

Code for square:

package lab2;
public class Square {
public double [][] vertices = new double[4][2]; //not good to make this public
public Square(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) {
vertices[0][0]=x1;
vertices[0][1]=y1;
vertices[1][0]=x2;

[Code] ....

In the Square code there is a method to write an equation to rotate it but I can't figure that part out ....

View Replies View Related

JavaFX 2.0 :: Progress Indicator Doesn't Rotate Anymore (8u20)

Aug 28, 2014

Since the upgrade to JavaFX 8u20 my ProgressIndicator won't rotate anymore when using Caspian style. Is there any workaround for this?
 
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.ProgressIndicator;
import javafx.stage.Stage;
public class TestApp2 extends Application {
    public static void main(String[] args) {
    
[Code] ....

View Replies View Related

Not Getting A Proper Shape Of Leftarrow

Apr 22, 2014

why am I not getting a proper shape of "Leftarrow"? The result should look like the following (the system draws the arrow abnormally, so the beginning should a real ARROW:

*

* *

* *

* * * * * * * * *

* *

* *

*

here is the class:

Java Code: public class LeftArrow extends ShapeBase {
private int lengthOfTail;
private int widthOfArrowHead;

[Code]....

View Replies View Related

ASCII Star Shape

Feb 2, 2014

I am having an awful time submitting the right program for this star pattern. 2.4: Star Pattern Write a program that displays the following pattern:

*
***
*****
*******
*****

I input the following:

// Program Challenge 2.4
2
3 public class PC24
4 {
5 public static void main(String[ ] args)
6
7 /**
Newline Advances the cursor to the next line for subsequent printing p.42*/
8
9 {
10
11 System.out.println(" *
"+ " ***
"+" *****
"+"*******
"+ " *****
");
12
13
14 }
15 }

View Replies View Related

Print Triangle Shape Using Numbers?

Jun 1, 2014

i want to print triangle shape using number like

this

1

12

123

1234

12345

123456

this is my code

class shape{
public static void main(String [] args){
for(int x =0 ; x<=6;x++){
for(int y =0 ; x > y ; y++){
System.out.print(x);
}
System.out.print("
");
}
}
}

but my output is

1

22

333

4444

55555

666666

View Replies View Related

Combobox To Change Color And Shape

Nov 19, 2014

i java a project with java draw golf course and currently working on 2 combo boxes to change shape of the flag on the post and fill color as well on combo box item change. I have below code. as am new to java what to do next.

import java.awt.*;
import java.awt.event.ItemEvent;
import javax.swing.*;
public class GulfCourse extends JPanel{
public void paintComponent( Graphics g){
super.paintComponents(g);
//draw green oval

[Code]...

View Replies View Related

Displacing A Shape Made Of Asterisks

May 5, 2014

I'm making a program that prints arrows of varying tail length, head width, and displacement.The shape algorithms are working properly, but the displacement isn't working. The first arrow has zero displacement, and the second one is supposed to be bigger and start the print at 10 spaces right and 5 spaces down from the default, but it's not working. I tried changing the displacement settings of the first arrow, and no changes happened, so I know that the positions aren't registering properly in general. How to pass the xAdj and yAdj (displacement) values? I think I have the empty space formula set up, but it's still not running.

Driver:
public class Driver
{
//default values
public static final int Arrow_Default_xAdj = 0;
public static final int Arrow_Default_yAdj = 0;
public static final int Arrow_Default_tail = 5;
public static final int Arrow_Default_width = 5;

[code]...

View Replies View Related

Graphics 2D Shape Cutter For BufferedImages

Jul 15, 2014

I'm going to make tiles for my RPG game, instead of drawing each shape of the tile, I will just draw the full tile in a spritesheet. I will create a sprite sheet of shapes that I want to clip somehow or use to cut the original full image into the shape I want. How can I, take a Buffered Image, cut it's shape and perhaps add something, giving me a Buffered Image of a cut tile with possibly added features that I can then draw with Graphics?

View Replies View Related

Printing Asterisks Shape In Java

Mar 17, 2014

I am supposed to Write a program that prints a shape similar to the following shape. Maximize use of loops and minimize use of print statements.

.....*
....**
...***
..****
...***
....**
.....*

(without the "...")(i couldn't get it to stay in shape)

This is what i got so far:

Java Code: package assignment7;

public class Exercise3
{
public static void main (String[] args)
{
for (int count =0; count < 4; count++)
{
for (int j=0; j < count+1; j++)
[Code] ....

Tthis compiles to:

*
**
***
****
**
*

How do i center it to create the shape?

View Replies View Related

Cutting Out Specific SHAPE From IMAGE

Apr 9, 2014

I'm making my 2D Java game, in my own style, in my own way. I'm trying to make it as code efficient as possible and compact, it usually is easier to change that way. I'm going to use BufferedImage subdivision on tilesets to take out tiles that I need, rather than creating multiple images with a tile each. Now, I've made multiple water tiles, for how they would be arranged differently.

So let's say you have a single water spot, it will be circular, you have two water spots, you have a tile-thick line with circular ends like two little water spots connected, this makes the game look more advanced, better, more realistic and good in many other ways. But, I found that an avarage amount of shapes needed is 25. I thought, how could I make this more efficient?

Could it be possible to use like shape cutting tools or something that would take out a specific shape of a single water tile to leave out all the different shapes, this is a good idea because I could use these tools for all kinds of different tiles in order to make specific features. By tools I mean simple black shapes which will remove the unwanted parts of the tile to form the wanted shape.

View Replies View Related







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