Drawing Image On To Screen - Nothing Appears?

Feb 7, 2014

I am trying to draw an image unto the screen, however, nothing appears...

Java Code:

private ImageIcon i = new ImageIcon("image.png");
private Image image;
...
image = i.getImage();
...
g.drawImage(image, (int)(x - r), (int)(y - r), null); mh_sh_highlight_all('java');

Am I doing it right? The program gives me no error, it's just that when I try to draw it, I see nothing.

View Replies


ADVERTISEMENT

Drawing Polygon On Screen - Collections As Arguments

Aug 29, 2014

I have a method that draws a polygon on the screen:

public void poly(List<Point> points) {
//code
}

For the usage of the method, it makes no difference whether points is an array or a List. In fact, switching doesn't even change any of the code in the method since I use a for-each loop. So, my question is, is it a better practice to use a List as an argument, or an array when the method itself doesn't care about which to use?

View Replies View Related

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

Drawing Image In Grayscale

Jul 14, 2014

I'm trying to draw an image in grayscale. This is my code:

Java Code:

public void paintComponent(Graphics g) {
super.paintComponent(g);
setOpaque(true);
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY);
Graphics g1 = image.getGraphics();
g1.drawImage(CardData.CARD_ART[cardID], 0, 0, null);
g1.dispose();
setOpaque(false);
} mh_sh_highlight_all('java');

For some reason, nothing displays.

View Replies View Related

Drawing Image - Specify File Path

Jul 3, 2014

Gyazo - e5663e8da42ac46a642895d72836b933.png

As you can see I have specified a file path, as it is needed to draw the image.

The image "sun" is in a certain folder inside the directory of my jar file.

But If I were to send the whole package to my teacher to review. The file path would still remain the same, local to my computer making the image, unloadable.?

View Replies View Related

How To Have A Camera View On A Bigger Image Than Screen

Apr 8, 2014

Where can I find tutorials about how you like have a big image, bigger than the specified screen, for the map of a game, and then you have camera view, the image is being printed on the screen continously as the character moves in different areas depending on what area of the map the character is in?

NOTE!!! I don't want to move objects around, I just want a camera view on a large image!

View Replies View Related

Make A Screen Black For A Buffered Image

Jan 10, 2015

I tried to make a buffered screen image that constantly refreshed an image (a black screen) however it does not seem to be working.

Java Code: import java.awt.Canvas;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferStrategy;
import java.awt.image.BufferedImage;

[code]....

View Replies View Related

Software To Display Image On Screen Using Particular Library

Jul 30, 2014

I am writing a piece of software to display an image on the screen using a particular library. The library lets me create an Atlas out of texture file data, to fetch Textures out of the Atlas using the textures' names, and to draw the textures by calling Renderer.draw(texture). It doesn't make a great deal of sense to create more than one of an Atlas or Renderer. I previously designed my code as follows:

public class SystemAssets {
static Atlas atlas;
public static void initializeAtlas(String pathToTextureFiles) {
atlas = new Atlas(pathToTextureFiles);
}
public static Texture getTexture(String textureName) {
return atlas.getTexture(textureName);
}
}

Similarly, I made a TextureRenderer class whose sole purpose is to provide static access to a Renderer. But many people seem to say that opening up a class like this to global access is bad. I cannot think of any better alternative, however. My core update/draw logic currently works something like this:

public class Game extends AbstractGame {
public void init() {
Screen current = new FirstScreen();
TextureRenderer.initialize();

[code]...

Making a Renderer object belong to the Game or Screen class doesn't make much sense to me, as there doesn't seem to really be a 'has-a' relationship between them; it's more of a 'uses-a', so that seems to imply that it would be best to just call Renderer.draw(thing) from outside the class rather than making it a data member. This would make my main code essentially call the various methods in order to get or print some form of data, much like System.out.println(). And of course, making one of the classes a subclass of Renderer makes even less sense. But making data members static for the purpose of global access and using singletons are often cited as 'bad' programming practices. This problem also arises in a lot of other scenarios in my program, ie. when I want to serialize Thing data members like texture filenames; do I put the serializer as a static data member in a class for global access and call it like I would a function, or do I put it in a class? And it seems like the Renderer will have to be initialized at the start of the program, which would take place in the init() method in Game, then be used to draw Textures in the Screen, so it would have to be accessible from both locations.

edit: In case it's suggested to put these in the main class, that's unfortunately going to be difficult without using static variables; the library recommends having the main class creating an Application object, which is essentially a black box that actually does all the work of calling Game's init() and draw() methods (via a Game object passed into its constructor) and looping until the program exits. AbstractGame and Screen are classes supplied by the library, so it doesn't seem like I can easily give Game any data that AbstractGame doesn't specifically ask for.

View Replies View Related

JPanel Appears To Be Null

Feb 23, 2014

I've a JPanel declared as a field in a JFrame:

public static javax.swing.JPanel pane;
I initialize it in a method (Well, Netbeans' GUI builder does. :P)
pane = new javax.swing.JPanel(){
@Override
public void paint(Graphics g){
g.setColor(Color.BLACK);
g.drawArc(8, 6, 15, 15, 0, 90); /* This works. The panel and frame are displayed, the arc is drawn, &c. */
}
};

it works and all; the arc is drawn.I want to draw on it dynamically by instantiating its Graphics (I call the "public Graphics getGraphics()" method.). This has worked for me before, taking a JPanel's Graphics and drawing with it through a different method than public void paint(Graphics g); But when I do, it comes up with a NullPointerException. WAIT! Don't go rambling on about initializing the variable because I've gotten past that NPE newbie's blockade.public static void render(Something s) { /*This is in a different file altogether. pane is public, static so I can access it from here. That's not the problem.*/

JPanel jp = Frame.pane;
Graphics g = jp.getGraphics();
g.fillRect(s.x, s.y, 4, 4);
}

Upon further investigation:
Exception in thread "main" java.lang.NullPointerException
at physics.Renderer.render(Renderer.java:30) <-- This line is "JPanel jp = Frame.pane;"
at physics.Renderer.renderall(Renderer.java:24) <--This line calls public static void render(Something s)
at physics.Updater.update(Updater.java:47) <--Renderer is just a tool used by the Updater. Sounds like a game loop, right?
at physics.Physics.main(Physics.java:31) <-- The game loop.

it says that Line 30, making jp and pointing it to pane itself is the problem.

Conclusion:
-The JPanel in the JFrame is created, initialized and overrides a parent method.
-The JPanel is not initialized, meaning that it is null. There is obviously a problem.

View Replies View Related

Get Background Image Showing Other Two Are Not Showing On Screen

Jan 20, 2015

public void paint(Graphics g) {
g.drawImage(Background, bg1.getbX(), bg1.getbY(), this);
for(int i=0;i==400;i+=10){
g.drawImage(block1,fg1.getBlockX(),fg1.getBlockY(),this);
g.drawImage(block2,fg1.getBlockX(),fg1.getBlockY()+10,this);
}
}

This is what im dealing with right now. When i click run i only get the background image showing the other two are not showing on the screen.

View Replies View Related

Counting How Many Times A Value Appears In Array

Nov 23, 2014

I have this code but I can't seem to get it to work. It keeps saying that "count" cat be found and that it cannot return a value whose type is void.

Java Code: public class Cuantos {
static int getPosition(double listOfValues[], double targetValue ) {
int i,count,
position = -1;
for (i=0; i < listOfValues.length; i++) {
if (listOfValues[i] == targetValue)

[code]....

View Replies View Related

How To Find How Many Times A Number Appears In Array

Dec 7, 2014

This is my code up to now and I can't do anything to make it work. I want it to tell me how many times the number 3 appears, and the last position it was in. I am getting errors like"Cuanto.java:88: getPosition(double[],double) in Cuanto cannot be applied to (double) ....

a = getPosition(a);" and unreachable statements, and value not found. It's all over the place every time I make a change to it.

Java Code:

public class Cuanto {
static int getPosition(int count,double listOfValues[],
double targetValue) {
int a = 0, i;
for (i=0; i < listOfValues.length; i++) {
if (listOfValues[i] == targetValue) {
a++;

[Code] ....

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

Count And Display Number Of Times Specified Character Appears In String

Mar 7, 2014

Write a program using a while-loop (and a for-loop) that asks the user to enter a string, and then asks the user to enter a character. The program should count and display the number of times that the specified character appears in the string. (So, you will have two separate program codes, one using a while-loop and the other one using a for-loop.)

Example:
Enter a string: "Hello, JAVA is my favorite programming language."
Enter a character: e
The number of times the specified character appears in the string: 3

I don't even know where to begin I've only got this

import java.util.Scanner;
 public class letterCounter {
 public static void main(String [] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a string");
String myString = sc.nextLine();
System.out.println("Enter a letter");
String letter = sc.nextLine();
}
}

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

Retrieve Image From MySQL DB And Display In Jtable If Image Type Is Medium Blob Using Swings And Hibernate

Jan 5, 2015

I stored an image into MySQL database using swings and hibernate but I am struggling to retrieve that image from MySQL database and display same image in the jTable cell and same as on jLabel whatever I retrieve from the database using swings and hibernate .

View Replies View Related

JSP :: String URL For Image In Database And Show Image In File

Dec 24, 2014

I had string url for image in mysql database and I want show image in mu jsp file bu I can't.

<c:forEach var="urun" items="${listUrun.rows}">
<tr>
<td><c:out value="${urun.kitapresim}" /></td>
<img src="<c:url value="${urun.kitapresim}" /> " width="270" height="190"/>

URL...

View Replies View Related

JButton Image Does Not Show On Background Image

Feb 23, 2014

I successfully added a background image on the Panel but I can't create my JButton image on top of my background image.

ImageIcon piano = new ImageIcon("src/img/piano_backgrd.png");
JLabel backlabel = new JLabel(piano);
panel.add(backlabel, new Integer(Integer.MIN_VALUE));
backlabel.setBounds(0, 0, piano.getIconWidth(), piano.getIconHeight()); 
JButton volup = new JButton(new ImageIcon("src/img/volup.png"));
volup.setLocation(10, 0);
panel.add(volup);

View Replies View Related

Graphics - Drawing A Building

May 28, 2014

I have to write a program for class that basically uses Paint Component to draw a bunch of rectangles to look like a building then have them change color randomly. I am stuck I can't figure out how to make it draw the rectangles in rows and columns to look like the building i can make it display multiple squares randomly however but thats not the assignment.. here is my code

package labBuilding;
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JPanel;
@SuppressWarnings("serial")
public class Building extends JPanel {

[code]....

View Replies View Related

Graphing Using Drawing Panel

May 1, 2014

import java.awt.*;
 public class Program5 {
 public static void main(String[] args) {
DrawingPanel panel = new DrawingPanel(300,500);
panel.setBackground(Color.white);
Graphics g = panel.getGraphics();
g.setFont(new Font("Helvetica", Font.PLAIN, 12));
double ball = 10;

[code]....

I'm fairly new to Java and am having a hard time with this particular assignment. The program runs and shows up on the drawing panel fine but I can't get the lines quite right.Capture.jpg

View Replies View Related

Drawing Animations In Java (SWT)

Apr 21, 2014

I've got a question about drawing animations in Java (SWT). I try to draw an animation of some process.

When i use canvas.redraw() it seems like program firstly erases everything that has been drawn and then draws again.

My program draws about 1000 of rectangles per time step so animation doesn't looks smooth - it blinks all the time and I can't avoid drawing that many rectangles.

Is there a way to make it look smoother (for example to paint new objects over old ones, without erasing them)?

I won't paste code, it's rather large.

View Replies View Related

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

Transparent Panel Drawing

Apr 23, 2015

solve my problems regarding drawings on my JPanel(Transparent panel).My Jframe & other components are created by netbeans GUI builder & the transparent panel is created manually but one problem is that i can't impose this Transparent panel into JFrame like it is attached to the JFrame.Another problem is that,i want that transparent panel size should be counted in inch like my attached picture(TOTAL SIze 36 inch) & also when i clicked on that panel those mouse points highest distance should be measured in Inch.How can i do all of these three task??

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 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







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