Swing/AWT/SWT :: Drawing Various Shapes - Repaint Not Working

Jan 16, 2015

I'm trying to make a simple program that will feature some graphics. It will have a JCombobox that the user selects to draw various shapes. I can't get the repaint function to work however.

package selectingshapes;
import java.awt.Graphics;
import java.awt.Color;
import javax.swing.JPanel;
import java.awt.Graphics2D;

[Code] .....

View Replies


ADVERTISEMENT

Drawing 3D Shapes With Java

Feb 17, 2014

I have a problem which can't solve it for 2 days search. I need to draw 3d shapes , i downloaded all packages and set an example code and run it ...

Exception in thread "main" java.lang.UnsatisfiedLinkError: no J3D in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java :1886)
at java.lang.Runtime.loadLibrary0(Runtime.java:849)
at java.lang.System.loadLibrary(System.java:1088)

[Code] ....

View Replies View Related

Drawing Shapes Bottom Right To Top Left

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

Swing/AWT/SWT :: Trigger A Repaint From Another Method?

Mar 5, 2014

I have two classes. One constructs my a rectangle using Graphics2D (the class is called Rectangles). The second takes a user input for the triangle, which I am passing back to the first class. I am trying to trigger a repaint of class one from the action listener I have on a button in the second class. how to trigger this event?

View Replies View Related

Swing/AWT/SWT :: Repaint Causes Stack Over Flow

Feb 26, 2014

I have the following code where I call panel repaint method from the action listener of the calc button but it causes stack over flow but when I modify it to call paint component method and removing the super term, the program executes. here is the code

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Box;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.BoxLayout;

[Code] .....

View Replies View Related

Swing/AWT/SWT :: JTable - How To Repaint With Updated Data

Jun 5, 2014

Here's what I would like to happen:

Java/Swing dialog box appears on the user's screenIt allows the user to enter 2 values into labelled text fields (fname/sname)They select a "Click Me" push button which I hope will write the data into the table. But the table does not get refreshed.

If I minimise the dialog box and then open it again, the data still does not appear.

The code I originally built using eclipse/WindowBuilder. I've cut it back and tried to isolate the issue. But I still cannot figure it out.

I've added some diagnostic log messages to ensure that I am seeing the various events I think I need to see and have put code in the action callbacks etc.

import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.GridBagLayout;

[Code] .....

View Replies View Related

Swing/AWT/SWT :: Repaint Method Is Automatically Erasing Old Circle?

Feb 19, 2014

This code is shown to eliminate "smearing":

public void paintComponent (Graphics g) {
g.setColor(Color.white);
g.fillRect(0,0,this.getWidth(), this.getHeight());
g.setColor(Color.green);
g.fillOval(x, y, 40, 40);
}

I had done all the previous code (in my own style) and found that the background rectangle was either being redrawn on its own, or there was something else removing the old circles from the screen. I then typed in the code from the previous page exactly as it was, to see if I had some change in syntax that would cause this, and it did the same thing.

Here's my code:

import javax.swing.*;
import java.awt.*;
public class SimpleAnimation {
int x, y;
private static final int HEIGHT = 600;
private static final int WIDTH = 600;

[Code] .....

Is this because I'm using JRE7? I can't find any documentation that indicates the repaint() method has changed since Java 5.

View Replies View Related

Swing/AWT/SWT :: How To Update JPanel Rather Than Refresh It Every Time On Calling Repaint

Jan 4, 2015

I would like to be able to draw things onto the panel (via paintComponent), but I'd like it to draw 'on top' of what's already there. The default seems to be that it resets every time I call repaint.

View Replies View Related

Swing/AWT/SWT :: Call Repaint 200 Times In Loop And It Only Calls PaintComponent Once?

Dec 2, 2014

I have been baffled by the functioning of repaint() - and the SwingPaintDemo3 with the moving square seems mysterious - you call repaint(x,y,w,h) twice and the first time it clears the clip area and the 2nd time it paints the red box. The code in paintComponent tells it to paint the box both times, yet somehow it ignores the initial box and only paints the 2nd one.

I've been writing code to bounce some balls in a box to try and understand the behavior. I set up an array of ball objects, loop through them, move them adjusting for collisions with walls and each other, then repaint(). I call repaint x2 for each ball, just like in the example. In my paintComponenet code, if I try to just paint the current ball only one ball will move, even if I send a different ball object each time. The only way to get all the balls to show up is to put a loop in paintComponenet that goes through all 100 balls every time I call it. I was worried that to move 100 balls I was painting 100x100 times.

So I put some System.out.println commands in my ball move loop, inside my object ball draw commands, and inside the paint component.

private void calculateMoveBall(BoxBalls oneBall) {
System.out.printf("
Entering calculateMoveBall [%1$2d]
",

[Code].....

So even though I called repaint() 200 times (twice for each ball), repaint was actually only called once, drew all the balls at once, and then went back. And I just noticed it appears to have waited until I exited the calculateMoveBall loop to go into paintComponent! The spooky things is how does it know to do that? Does the Java machine 'see' that it is inside of a loop, and perhaps also sees the loop inside of paintComponent, and somehow correctly guesses that it doesn't have to do it 200 times, but can wait and do it once? If I attempt to do the same thing in code, take the loop out of paintComponent() and call repaint() with the current ball, expecting the machine to do exactly what I tell it, it refuses and does it's own thing, waiting to call paintComponent on the 100th ball, drawing only the last ball (so I guess the loop inside paintComponent is not in the logic).

So a call to repaint() is a request for a higher being to decide if it has the time or energy to repaint the clip. If not, it ignores the call, or stacks them up for later (maybe I should try a million and see if it has room for that!) - well so far up to 4000 it behaves the same. This is useful if you are happy with "this is how it works so use it that way". However I really don't like having some kind of hidden logic that I have to trust to work the right way. If I don't want it to wait until later I'm not sure what to do. And I don't trust the machine to do whatever whenever. How do you debug that???

Questions: Is there documentation to know what repaint() will do or how it decides when to call paintComponent? The Swing tutorial gives the example but not the why. "By now you know that the paintComponent method is where all of your painting code should be placed. It is true that this method will be invoked when it is time to paint" "An important point worth noting is that although we have invoked repaint twice in a row in the same event handler, Swing is smart enough to take that information and repaint those sections of the screen all in one single paint operation. In other words, Swing will not repaint the component twice in a row, even if that is what the code appears to be doing." (What the code appears to be doing - now we have to guess what it is doing)

Is there a way to force repaint() to call paintComponent on a clip rectangle (not just on the whole thing?) I would think invalidate() would force repainting of the whole componenet.

Perhaps this is when you draw to a bitmap in memory and paint the whole thing on the screen...

View Replies View Related

Swing/AWT/SWT :: Mini Paint Program - Changing Size Of Shapes

Jun 4, 2014

I am currently writing a small drawing program and I am having trouble with changing the size of the shapes. To do this, I have to access the arraylist shapes, check whether pressedX/pressedY is on any of the shapes in the arraylist using the findShape() method and then when released, uses moveBy() in the Rectangle/Oval/Line class and moveShape() in the miniDraw class to move the shape and draw it in the newreleasedX/releasedY position.

So far I think I have pin pointed the problem to being the method in all the shapes classes, that checks whether the pressedX/pressedY which is the on() method, and the findShape() method in the miniDraw class.

This is the minidraw class

import ecs100.*;
import java.awt.Color;
import java.io.*;
import java.util.*;
import javax.swing.JColorChooser;

[Code] .....

View Replies View Related

Swing/AWT/SWT :: Why Delays In Drawing Images

Jun 17, 2014

I have a question about the execution of code to draw images relative to code that comes after that. I don't normally do this sort of thinghere's the problematic code:

int stn = 0;
while (stn < 10)
{
glb1.xOfText += 20;
glb1.yOfText += 20;
gc1.drawImage(glb1.img1 , glb1.xOfText , glb1.yOfText);
TimeKeeper.pause(500);
stn++;
}

Where glb1 is a final reference to an object that holds common data for the game.while its x and y values say they are for text, they are also used for image placement (at least during this testing phase.)

gc1 is the "graphics context" of the canvas that the images are being drawn on.

The person who wrote this said, "When the attached code is run, the calls to TimeKeeper.pause(500), which in turn call Thread.sleep(500), are all executed in row, and then the results of drawing the image 10 times is displayed. (I know because some of the previous image pastes left some visual data behind.)"

I recall from reading about drawing graphics (a long time ago) that drawImage() could take time, but I don't know why the thread does not indeed sleep between calls to drawImage().

View Replies View Related

Swing/AWT/SWT :: Drawing Images That Are GIFs

Dec 20, 2014

how to phrase the question. I created a small applet in java.. it allows me to move a toon around a blank applet window. I am using four gif files that have a walking animation in them. The issue i am having is after moving around the gif just flashes in and out really quickly.. when i start the program, moving up and down seems to be working perfectly fine, but the moment i move left or right it starts messing up for all directions. here is my code.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class CharactorMove extends JApplet implements KeyListener

[code]....

View Replies View Related

Drawing Multiple Objects Swing

Jun 30, 2014

I have to do an assigment using Swing, where I have to make a Board(extends JPanel) and add multiple instances of moving elements to it, with following requirements:

By adding a new object to the Board, the others must not slow down. Also the user interface must not be blocked by the moving objects. So, the movement of the objects must be handled in a separate thread.

and

The application must support adding lots of objects, so it is not okay if every object has its own thread, as this would take too many resources. Design the application in such a way that it uses a constant number of threads, meaning that the number of threads does not grow when adding more objects.

The question is:

How to do this thing with constant number of threads?

View Replies View Related

Swing/AWT/SWT :: Add Free Hand Drawing To ArrayList

Nov 6, 2014

I am buildning a paint application in java, where the user can choose from a combobox wheather he/she wants to draw a rectangle or by free hand. The objects are stored in an arrayList. The user can also choose in the menubar to go back one step, which means to remove the last drawn item from the arrayList and then loop through the arraylist to draw the remaining objects.

It works fine with rectangles. When I create a rectangle it creates only one rectangle, which I add to the arrayList.
My problem is with the free hand. When I draw by free hand (using mousePressed and mouseDragged) I add every "dot" of the line as an object. Which means that when I remove the last item in the arrayList it only removes one dot of the line, not the whole line.

I need to add the dots together as one line, but how can I do that?

if (e.getSource().equals(comboBox)) {
JComboBox cb = (JComboBox)e.getSource();
if (cb.getSelectedItem().equals("Rectangle")) {
this.addMouseListener(new MouseAdapter() {

[Code] .....

View Replies View Related

Swing/AWT/SWT :: Drawing A Semicircle Using Formula For The Equation Of A Circle

Sep 19, 2014

So Ive got to make a turtle on an image draw a semicircle that starts at the top of a circle and goes down and to the left, changing colors halfway through. I've got everything down, I can draw the turtles and make them do straight lines. My problem is more math related. I need to use the equation of a circle, give it points, and figure out how to write that code in java.

We use the equation for a circle: (x - a)^2 + (y - b)^2 = r^2

amanda.setName("amanda");
amanda.setShellColor(Color.BLUE);
amanda.setBodyColor(Color.RED);
amanda.setPenColor(Color.YELLOW);
amanda.setPenWidth(3);
amanda.forward();
amanda.turn(-90);
amanda.setPenColor(Color.BLUE);
amanda.forward(???);

the question marks are where I need to draw a line on an arc, like in the picture.

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

Swing/AWT/SWT :: Drawing Arcs And Later Make It Move Anti-clockwise

Nov 12, 2014

I first need to draw this exact shape, which later I will have to make it move anti-clockwise, but for now, how to draw this thing:

First thing I can think of is drawArc, but not so sure...

View Replies View Related

Swing/AWT/SWT :: Double Drawing Pixels When Manipulating DataBuffer Of BufferedImage

Feb 9, 2014

I've been working my way through a tutorial to build a simple 2D tile-based engine that also allows the code to manipulate the colour of pixels on the screen based on a monochrome map read from a file. I've got the code right line for line, but I seem to have a bug when it comes to draw to the screen! At regular intervals, despite what is held in the pixel array of ints (which I have confirmed to be correct when debugging), I get the same row of pixels being draw twice in a row. I figured there was some loop issue somewhere, but after attempting to debug this for some time, I haven't come up with the answer.

Original tilesheet:As rendered:

Game.java:
package igg.engine.game;
import igg.engine.game.gfx.Screen;
import igg.engine.game.gfx.SpriteSheet;
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Color;

[Code] ....

View Replies View Related

Swing/AWT/SWT :: Reading Point Objects From DRW File And Drawing Lines On Panel

Sep 15, 2014

I am trying to read Point objects from .drw file which contains endpoints of line segments, and draw lines making a square on panel when I run the program. This is what I have got so far. how to get the points using array for drawing ?

// inside the method to read points objects from .drw file
try {
fos = new FileInputStream("square.drw");
oos = new ObjectInputStream(fos);
// creating an object of Point class
endPoints = new Point[sampleSize];

[code]...

View Replies View Related

Swing/AWT/SWT :: Progress Bar Not Working?

Feb 14, 2014

I'm trying to get a progress bar to work on my GUI.

This is what I have so far, the parameters are taken from another class that takes in an image in packets from a Raspberry Pi and stores them to a file on PC.

public void ImageInfoReceivedHandler(int sizeOfFile) {
progressBar.setMinimum(0);
progressBar.setMaximum(sizeOfFile);
progressBar.setIndeterminate(false);

[Code] .....

The println are printing out the correct values and they are being implemented in the methods, but nothing is happening in the GUI.

I have a thread setup in the GUI when a button is pressed

getImageButton.setText("Timer Started");
transmit = new transferImage(port);
lblImgProcess.setText("Getting Image, Please Wait");
transferThread = new Thread(transmit);
transferThread.start();

So the thread starts and image is then transmitted, does the progress bar need to be in that event handler?

View Replies View Related

Swing/AWT/SWT :: SetDefaultLookAndFeel Is Not Working

Mar 26, 2014

setDefaultLookAndFeel is not working as i'm expecting.this is my code: URL....

import javax.swing.*;
import java.awt.*;
import javax.swing.event.*;
import java.awt.event.*;
import javax.swing.text.*;
import java.io.*;
import java.text.*;

[code]....

after reading the oracle tutorial on how to make frames and reading FrameDemo2.java. URL....i thought setDefaultLookAndFeelDecorated(true); would give me a different decoration than the default windows 7 border.but toggling between true and false changes nothing, and changing setUndecorated does nothing either.what am i supposed to do to make it look like the one in theFrameDemo2 window?

View Replies View Related

How To Tell Another Class To Repaint

Jan 24, 2014

It has to be from another class because the other class controls the fps timer, and I want it to repaint() the panel every tick. However, I cannot seem to find a way to do this because repaint() is not static, and therefor can not be called in any way from another class.

View Replies View Related

Swing/AWT/SWT :: JButton Actionlistener Not Working?

Mar 5, 2014

I was suspecting I had a jButton not working, so I added a console print to test. See below. When I click the button, the console doesn't display anything. Am I using the button wrong?

private void jButtonUpdateItemsMouseClicked(java.awt.event.MouseEvent evt) {
System.out.println("click");
System.out.println(drawPreviousRectangle);//this is a boolean
}

I have also tried the following with the same results (or lack of).

private void jButtonUpdateMajorDeckItemsActionPerformed(java.awt.event.ActionEvent evt) {
System.out.println("click");
System.out.println(drawPreviousRectangle);//this is a boolean
}

View Replies View Related

Swing/AWT/SWT :: ScrollPane Not Working As Expected

Mar 11, 2014

I am trying to get a scrollPane working correctly, but not having any luck. The picture drawn in the center panel is quite large and goes off the screen. I visited URL... but I am missing something vital. Both tracks show, but there is no knob to do the scrolling.

public DViewer() {
super();
frame = new JFrame();
frame.setSize(Toolkit.getDefaultToolkit().getScreenSize());
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

[code]....

View Replies View Related

Swing/AWT/SWT :: Scroll Pane Is Not Working

Sep 6, 2014

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.sql.*;
class Stock extends JFrame implements ActionListener

[code]....

well everything seems to be working fine only the scroll pane is not working.

View Replies View Related

Swing/AWT/SWT :: Submit Button Not Working?

Feb 27, 2015

The class does get compiled but the submit button doesn't work?

/**
* Orchestration class for Account
*/
import java.awt.*; //Importing the java.awt.* class
import java.awt.event.*;//Importing the java.awt.event.* class
import javax.swing.*;//Importing the javax.swing. class
public class AccountDemo extends JFrame
{
/// initializes the variables in the container

[Code] ....

View Replies View Related







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