Swing/AWT/SWT :: Moving Image Left Or Right

Mar 11, 2014

I can't find any resource on the net about a simple Java code just to move a gif image left or right. I've already accomplished the up, down, and center and they're working fine, thus, I'm still struggling with moving the image left or right. Here's the code.

public class MoveIt extends Applet implements ActionListener
{
private Image cup;
private Panel keypad;
public int top = 10;
public int left = 10;

[Code] ....

I remember in Visual BASIC it's easily achieved by NameOfImage.left = NameOfImage.left - 10 to move left and NameOfImage.left = NameOfImage.left + 10.

View Replies


ADVERTISEMENT

Java Scrolling Game - Moving Image When Key Is Pressed

Mar 19, 2015

Okay, gotta be able to move the image when a key is pressed. When I test it, the image moves, but leaves the old image behind.

package Game;
import java.awt.Component;
import javax.swing.JOptionPane;
 public class Game
{
private Grid grid; //holds the grid used to store and display images
private int userRow; //keep track of which row the user-controlled image appears in
private int msElapsed; //keep track of the total amount of milliseconds that have elapsed since the start of the game

[Code] ....

Here is what I was given on instructions:

Complete the handleKeyPress method. Write the following line of code in the handleKeyPress method to check for a key press:

int key = grid.checkLastKeyPressed();

If the user pressed the up arrow (key == 38), move the user's image up one row (unless the user is already in the top row). Likewise, if the user pressed the down arrow (key == 40), move the user's image down one row (unless the user is already in the bottom row). Either way, make sure to update userRow.

Movement of the image can be accomplished by changing the value of userRow. Study how the initial image is displayed in the game constructor, then

Set the current image location to null

Update userRow to the new location and,

Set the image in the new value of userRow.

You should be able to move the user image up and down, and you should be prevented from moving the image off the screen.

View Replies View Related

Swing/AWT/SWT :: Image Manipulation - Create Application Where Image Is Displayed On One Label

Apr 7, 2014

Sir, I'am new to Swing Programming. I have to create an application where an image is displayed on one Label. The same image has to be split in parts and stored in database pert wise. Later the user has to retrieve the entire image by viewing a small part of the image. I have already displayed the full image on the Label, now i don't know how to split the image and store it part wise in the database.

View Replies View Related

Swing/AWT/SWT :: Snakes Stopped Moving When Tried Hitting Keys

Mar 28, 2014

I've visited this great site been following this java tutorial on making the snake game, and as I followed along at added the second player. Right up to the point I got into the resetting if I hit borders or myself or the other player, the snakes stopped moving when i tried hitting keys...problem started up to the point where I added snake2 in the GenerateDefaultSnake method

import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.LinkedList;
import java.util.Random;

[code]....

View Replies View Related

Swing/AWT/SWT :: Continuous Flash When Moving Mouse Next To Text Of Button

Jan 27, 2015

Just run the following code and move the mouse next to the text of the button and you will see exactly what I am talking about. Any way to prevent this continuous flash?

import java.awt.Dimension;
import javax.swing.JButton;
public class GUI {
public static void main (String[] args) {
javax.swing.JFrame frame = new javax.swing.JFrame();
javax.swing.JPanel panel = new javax.swing.JPanel();

[Code] .....

View Replies View Related

Swing/AWT/SWT :: Code Prevent Cursor From Moving When Inside A Cell Of JTable

Jun 24, 2014

Tried creating a simple sample but all works as expected.

The following code prevents the cursor from moving when inside a cell of a JTable.

public void keyPressed(KeyEvent e) {
if ( (e.getKeyCode() == KeyEvent.VK_KP_LEFT) || (e.getKeyCode() == KeyEvent.VK_KP_RIGHT)
|| (e.getKeyCode() == KeyEvent.VK_RIGHT) || (e.getKeyCode() == KeyEvent.VK_LEFT) )
{
//Do nothing
e.consume();
}
}
});

When editing a cell, the existing code would use the right/left cursor keys to move from cell to cell as opposed to from character to character when editing a cell. I planned to override the functionality by tossing in the above code as a test to see if it stops the functionality before I override it.

After placing in the above code, the above functionality no longer occurs, but now the cursor moves within the cell as I wanted which is to move from character to character instead of cell to cell. Its great it works, but it really shouldn't. Essentially the default behavior has been restored when it should have really disabled the left/right keys.

I assume there is some underlying class someplace that is doing something to affect the behavior. Since a sample can't be provided I am wondering in what scenarios would the e.consume() restore default functionality?

View Replies View Related

Swing/AWT/SWT :: How To Scroll Image

Sep 30, 2014

I have a java swing application.

1. The human user of my application asks it to fire up a scanner which scans a paper document. The document is a filled in form.
2. The application then displays the scanned image to the human user.The image is displayed in a JScrollPane since it may be larger than the scroll pane.
3. The human user needs to locate a certain item in the form, for example a social security number, and enter it into a field in a data entry screen.Note that the image and the field appear on the same screen.

Of-course the social security number always appears in the same location in the image. Also the image needs to be the appropriate magnification and resolution to allow the human user to easily read and understand the item he is searching for in the image.

What is the best way to present the scanned image to the user such that he immediately sees the item he requires and can enter it into the data entry field.

View Replies View Related

Swing/AWT/SWT :: Why Isn't Image Loading

Jun 20, 2014

I have added the image in the src and bin directories and cross-checked that the name of the image file is correct..Here is the main class

import javax.swing.*;
public class apples
{
public static void main(String args[])
{
JFrame frame = new JFrame();
MyDrawPanel wid = new MyDrawPanel();
frame.add(wid);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.setSize(300,300);
}
}

and here is the class that does the image adding part

import java.awt.*;
import javax.swing.*;

public class MyDrawPanel extends JPanel
{
public void paintComponent(Graphics g)
{

Image image = new ImageIcon("b.png").getImage();
g.drawImage(image,20, 20, this);
}
}

View Replies View Related

Swing/AWT/SWT :: JComboBox With Image

Apr 14, 2014

My database contains path of images that I want my jComboBox to diaplay. I have written the following code but it does not work for comboBox but works fine when I display image on jLabel etc. How should I go about this

try {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (ClassNotFoundException ex) {
Logger.getLogger(updatedetail.class.getName()).log(Level.SEVERE, null, ex);

[Code] ....

View Replies View Related

Swing/AWT/SWT :: Image Not Being Displayed In Jpanel

Feb 19, 2014

Trying to get an image to display in a GUI.

try {
ByteArrayInputStream in = new ByteArrayInputStream(
transferWorker.bOutput
.toByteArray());
BufferedImage bufferedImage = ImageIO
.read(in);

[Code] ....

But nothing is happening in the GUI. I have stepped through and bufferedimage contains the data, but its not being displayed. Whats happening is, an image is being transmitted to serial port of laptop, so i'm taking it in and storing it in a BufferOutputStream and then trying to open it in my GUI class.

View Replies View Related

Swing/AWT/SWT :: Get Image To Show Up On Compiled GUI?

Feb 16, 2014

trying to get my image to show up on my compiled GUI.

Here is my GUI, I just need to know how to get the image to show, where do I save an image file so that it comes up in my GUI.

import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Vector;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

[code]...

View Replies View Related

Swing/AWT/SWT :: How To Load Image To JFrame

Jul 23, 2014

How to load an image to a swing application?? I want to load it to myframe(JFrame)..

View Replies View Related

Swing/AWT/SWT :: How To Update Image In Java GUI

Jul 10, 2014

I have a GUI with several buttons and I'm using NetBeans GUI Builder to do. At the click of one of these I would like for it to open another frame containing a picture. So I associate a listener (actionPerformed) the button and when clicked it opens actually post the new frame.

In the new frame I waxed a JLabel and then I associate the image of the label. I saw that to do that NetBeans generates this code:

label.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/tree.png")));

My problem is that the picture is overwritten several times during the execution of the program is not changed yet in the frame. That is, in the new frame is always displayed an old version of the image.

I have an image that is created every time I click on the button (it always has the same name and same path). Basically I have a generic tree on which I perform the operations (add, remove, etc..). When I click on the button I call a method that generates the image of the tree (using Graphviz). So I have one image that changes over the time...

How can I do so that the image is always up to date?

The Code:

package View;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
public class AlberoIpotesi extends javax.swing.JFrame {

[Code] ....

View Replies View Related

Swing/AWT/SWT :: Doesn't Display Image

Mar 28, 2015

why this code, doesn't display the image?

import java.awt.Graphics;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

[code]...

View Replies View Related

Swing/AWT/SWT :: How To Resize Image Icon

Aug 15, 2001

Any way to resize an ImageIcon when placing it on a Button so that I don't have to physically rezize the image file?? I am writing an Application, not an applet, so the getImage method won't work.

View Replies View Related

Swing/AWT/SWT :: How To Paint Image On Frame

Mar 8, 2015

I simply want to paint an image on my frame, just once each time the paint() method is called, but how to call the paint method in any good way. This is how it looks:

import java.awt.AWTException;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;

[Code] ....

I have a frame in another class, and from my assumption I need to somehow tell my paint method to paint on that specific frame right?

View Replies View Related

Swing/AWT/SWT :: How To Create JPG Image From JTable

Feb 24, 2014

how to create a jpg image from a JTable ?

View Replies View Related

Swing/AWT/SWT :: Displaying Image Using ImageIcon?

Jul 5, 2014

I'm currently following this Java tutorial:[URL]

I'm at the Image part of this chapter and I wrote/copied these 2 classes:

[URL]

The error:

Exception in thread "main" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(Unknown Source)
at image.Board.<init>(Board.java:17)
at image.Image.<init>(Image.java:10)
at image.Image.main(Image.java:20)

I'm fairly certain the problem is the path in this piece of code:

ImageIcon ii = new ImageIcon(this.getClass().getResource("C:GebruikersKristofferworkspaceImagessrcimageNature.jpeg"));

I've done some research and found that I should place the image in the same folder as my .java files, which I did [URL] but the problem still persists.

View Replies View Related

Swing/AWT/SWT :: Display Image On Game

Jan 19, 2014

I have a class that retrieves an image, and a class that is a game. I want to put my image onto the game to use it as the main figure. As of right now in eclipse, the game class runs, so the game works, but the image doesn't do anything. Need to put the image into the game? Here is my image class:

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.*;

[code]....

View Replies View Related

Swing/AWT/SWT :: Input Image In Textarea

Jun 4, 2014

I am trying to input an image into a JTextArea using following code . Image is not displaying in the textarea

else if(action=="Image")
{
final ImageIcon imageIcon=new ImageIcon("E:/Anu/sec.gif");
final Image image=imageIcon.getImage();
Image grayImage = GrayFilter.createDisabledImage(image);

MF.TxtMsg=new JTextArea(){ //MailFrame MF

[code]....

View Replies View Related

Swing/AWT/SWT :: How To Set Opacity Of JLabel And Image

Feb 27, 2014

I'm trying to make a JLabel with an image fade in from transparent to fully visible.Is this possible with the JLabel itself or would I have to change the Image? If I'd have to change the Image's opacity how would I do this?

View Replies View Related

Swing - Display Image On JFrame?

Jan 16, 2014

How to display an image on a JFrame. If you can, pany example code.

View Replies View Related

Swing/AWT/SWT :: Simple Image Display

Aug 8, 2014

I am fairly new to Java. I am trying to learn some image manipulation basics. I have searched the web endlessly and made numerous attempts but I cannot seem to get a darn image to display. This code is my latest attempt in Eclipse. The file I am using is chairangle.jpg which is is the src folder of the package I am working in in Eclipse. I am on Windows 8.

import java.awt.*;
import javax.swing.*;
import javax.swing.ImageIcon;
public class otherimg extends JFrame
{
public static void main(String args[]){
JFrame f = new JFrame();
ImageIcon image = new ImageIcon("image/chairangle.jpg");
JLabel label = new JLabel("", image, JLabel.CENTER);
JPanel panel = new JPanel(new BorderLayout());
panel.add( label, BorderLayout.CENTER );
f.pack();
f.setVisible(true);
}
}

View Replies View Related

Swing/AWT/SWT :: AffineTransform Making Image To Move

Aug 5, 2009

I've been trying to make an image rotate in a panel. I did it. But also i want the image to make a translation.

Here is the code i tryed at paintComponent() :

//////////////////////////

Graphics2D g2 = (Graphics2D) g ;
AffineTransform at = new AffineTransform() ;
// at.rotate ( angle in radians ) ;
at.rotate( this.getAngulo(1, 1) ) ;
g2.drawImage(imgemFlecha, at, this);
/////////////////////////////

I cant change image x,y doing this drawImage(). I want to make that change.

View Replies View Related

Swing/AWT/SWT :: How To Flip Image Along Vertical Or Horizontal

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

Swing/AWT/SWT :: Loading Image From Relative Path

Mar 15, 2015

All I want to do is load an image into a swing JLabel and display it, but I'm going to have to make a JAR of the program and submit it for grading, so I need to be able to get the path of the image file relative to the JAR (at least I think that's how it works - I've never made a JAR before. Right now I'm just trying to load it from a path relative to my netbeans project). I've tried at least 20 different combinations of paths, file locations within the project, etc., but nothing works.

Anyways, here's the test class I've been using to try to figure this out in its current iteration. Right now the image I want to load is in src/resources and the class is in

src/imagedisplaytest
package imagedisplaytest;
import javax.swing.*;
import java.awt.*;
public class ImageDisplayTest extends JFrame {
private JLabel testLabel;
public ImageDisplayTest()

[Code]...

What's the best way to do this?

View Replies View Related







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