Background Overlapping Images

Jan 7, 2014

Java Code:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class sample{
public static void main(String args[]){
JFrame frame = new JFrame();
frame.setSize(300,300);

[code]....

To limit the amount of drawing done i want unmoving objects to be painted once. So i set a boolean. When it first load the boolean is false so it draws then after first draw i never want it to draw the objects agian but leave them on the screen. Now in this if you run it you get a black screen.

If you didnt have the "getContentPane().setBackground(Color.black)" it would work fine and show a blue brick. Is there something I don't understand about the setBackgound Function that makes it automatically redone even when not called? and if so how do i overwrite this?

View Replies


ADVERTISEMENT

Swing/AWT/SWT :: Loading SVG Images On JPanel With Transparent Background

Mar 27, 2014

I'm working on loading SVG images on Jpanel using "Apache(tm) Batik SVG Toolkit" , but after the image get loaded it has "white background" and "not transparent" one like PNG images.

I checked "fill" of rect attribute on the xml file of the svg image and it was correctly set to none, I also Tested the image on html document and it was trasparent, but in my java app it has white background.

The Question is there any way to load SVG images with transparent background on Jpanel ?

View Replies View Related

Handling Sprite Overlapping?

Sep 16, 2014

The game I am working on now is an overhead game. Anyways I have a visual issues with the sprites where they overlap. I mean its normal to have sprites overlap but I do not want one to appear like it is walking on top of the other rather than the ground. The below is an image illustration the issue I want to address. (I am really good at drawing)

On the right you see what I want my sprites to do, but on left you see overlap in the way I am trying to avoid.

Now my approach to this problem is taking my array of monsters (a class that extends JLabels) and reordering them based on which monster is higher I make this occur at every run of my thread. It seems to me that if a monster is higher it should be added to the screen before the one that is lower. So I try to keep resorting the array of monsters at every iteration of my main game loop based on who is higher to account for the overlap

if (e.getSource() == follower){
c =0;
for (monster m: monsters) {
//Arrays.sort(monsters, new whoHigherComparator()); //I tried having the sort happen here
m.movingToPlayer(joe);//1
Arrays.sort(monsters, new whoHigherComparator());//2
layeredScene1.add(m, new Integer(3));//3

[code]...

The above is code that shows the majority of my games flow I will describe my flow with references to the commented lines above with [num] for better understanding of where I am coming from. Basically, there is a set number of monsters, the monster all locate and move to the player [1], then I attempt to sort the monster array based on height [2], then add my re-sorted monsters back onto the pane in order [3], then bumpers (a type that handle collision and make sure monsters don't overlap too much) attach the current monster [4], if bumpers are touching monsters arae moved away from each other until their bumpers are no longer touching [5], if the monster is moving leftwards set the animation to a leftwards walk [6], and likewise for rightwards walking [7]

By the way this is my comparator

public class whoHigherComparator implements Comparator<monster>
{
@Override
public int compare(monster m1, monster m2) {
System.out.println("comping?");
int h1 = m1.getY();
int h2 = m2.getY();
if (h1 < h2)

[code]...

At this point everything in my game flow works just fine, its just the annoying "walking on top of each other" effect that I am having trouble handling. And my attempt at this is line [2] & [3] from my game flow which seems like it would be an effective way to handle the "walking on top of another" effect but its surely not working. I also swapped the returns from my comparator but still no changes. It seems that maybe the array isn't being sorted and/or these changes are just not being reflected.

View Replies View Related

Stopping Enemy Sprites From Overlapping

Oct 1, 2014

I am currently in the process of making a game in java. it's going fairly well, however, one problem that i am having is that i cant seem to get my enemy sprites not stack up onto one another. What i want to happen is if two enemy sprites come in contact with one another i want them to touch but not to overlap. However, i cant seem to get this to work.

This is the enemy class:

import java.awt.Graphics;
import java.awt.Image;
import java.awt.Rectangle;
import java.util.ArrayList;
import javax.swing.ImageIcon;
public class Enemy extends Base {
int x;
int y;

[Code] ....

View Replies View Related

Putting Images In GUI / Images In Source File Don't Seem To Be Recognized

Jun 7, 2014

This is my class with the GUI:

import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.JPasswordField;

[code]....

Eclipse error message:

Exception in thread "main" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(ImageIcon.java:205)
at GUI.<init>(GUI.java:26)
at Apples.main(Apples.java:7)

i think the problem is to do with my images not being recognised. I put them in my source in User>...>workspace>src which is correct as far as i know. From what i know the images should show up if i look at my src file in eclipse but they dont. I tried changing the file type from .png to .jpg but it makes no difference.

View Replies View Related

How To Add Background Sprite Before The Map

Apr 18, 2014

I need to draw a sprite before the map but it never works.

My Code ( without the background sprite ) :

Java Code:
package com.TEST.Dermat.screens;
import com.TEST.Dermat.entities.Player;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;

[Code] .....

View Replies View Related

How To Get Background To Scale

Jan 22, 2015

I am developing in Android Studio and I made a simple background, the actual resolution of the image is 1440 by 2560. I made it that resolution so, 1, it is easier to scale down than up, and 2, in android studio i use a nexus 6 as my preview. When I plugged in my gs4, not a 1440 by 2560 display, the background wouldn't show up when I ran it on my gs4(galaxy s 4). How do i get my background to scale and display on any display size.

View Replies View Related

Set Background In Mouse Adapter

Sep 9, 2014

import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;
 import java.awt.BorderLayout;
import java.awt.Color;

[Code] .....

Isn't changing my backgrounds in my MouseAdapter I keep getting these errors:

at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)

[Code] ....

View Replies View Related

Setting Background Of JScrollPane?

Aug 19, 2014

My program's tree:

JFrame{
JPanel(That MenuBar at the top)
JPanel(That panel at center with table){
JScrollPane{
JTable
}
}
}

I want to add my custom image to that grey space right there. I guess it is a JScrollPane, because I added that orange background on JPanel that contains it. But when I add this code to my custom class of JScrollPane:

@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
if(background == null){
background = new ImageIcon(ClassLoader.getSystemResource("tableBg.png")).getImage();
}
g.drawImage(background, 0, 0, null);
}

The result is the same, no changes.

Then I read some documentation. I found this method:

scrollPane.getViewport().setBackground(Color c);

It works, but it accepts only color and I want to add image. Is there any way to do that? Do I need to subclass JViewport and use paintComponent ? If yes, then how to make getViewport() method return my custom subclassed version?

View Replies View Related

Set Background Color With Check Box?

Apr 9, 2014

the program runs fine with exception of color background change.. dont laugh at code.

package chapter7;
import java.awt.*;
import java.awt.event.*;

[Code].....

View Replies View Related

How To Add Background Image To Frame

Mar 20, 2014

I'm using notepad++

I want add background Image

View Replies View Related

How To Set Background Image To JPanel

Apr 6, 2014

how to set background image to jpanel

View Replies View Related

Setting Image As Background?

Jan 9, 2015

This is my code and it works! But how/where do I set a background image for it to appear as the background of my calculator? The code I have for it is this -

window.setContentPane(new JLabel(new ImageIcon("C:UsersComputerDownloadschristm as1.jpg")));

My code is below.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/**
* Program using SWING components to create a Christmas themed Calculator.
*/
public class ChristmasCalculator implements ActionListener

[code]....

View Replies View Related

Run Java File In Background

Feb 6, 2015

I have made a little chat program with java(ecplise) but i want build it and if a user opens it is is going to run in the backgroundprocess. I don't know if i have to edit my code or Export it differently.

View Replies View Related

Set Background Image To Calculator Using JLabel?

Jan 13, 2015

I have tried to set a background Image to a calculator usinf JLabel. However I've ended up with my image to the left of my calculator , my calculator textfield becoming the size of the background image and then all my buttons below it.
Like so(if you can view the image)..Calculator.jpg

How can I fix this so the background is behind my buttons and my text area is a normal size again.

My code is below :

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
 
/**
* Program using SWING components to create a Christmas themed Calculator.
*/
public class GridBag1 extends JFrame implements ActionListener

[Code] ....

View Replies View Related

How To Change Background Color Of Panel

Oct 23, 2014

I have a Jpanel with JButtons on the panel is it possible to change the background color of the pannel but leave the JButtons thr default color

View Replies View Related

JSP :: What Happens In Background When User Clicks On Button

Oct 31, 2014

What happens in background when user clicks on button on jsp?How the request goes?

View Replies View Related

Possible To Send Keystrokes To Background Window?

Jun 11, 2014

So I have basic java knowledge from 1st year of college and I wrote a program recently that sends keystrokes with the Robot class. Now I would like it to do the same but to send it to a window that isn't my active one.. I've searched and from what Ive found it seems like you cant do that in java, I need another language like C# (whick sux for me since i dont know any other then java).. Is this true? If not how would i send something to notepad for example while it is not the active window?

View Replies View Related

How To Set Background Image Of JLayeredPane And Then Add Jbutton

Apr 10, 2014

Actually i want to develop a game for that i need a background with a image and over this background i want to move some objects (which are images) and also want to add some button.

Here is my Code.

The Main Class

package last;
import java.awt.*;
import javax.swing.*;
public class Last extends JFrame{
public static void main(String[] args) {
Last l =new Last();
l.setSize(900, 600);

[Code] .....

When i execute the above program only the background image is shown.

View Replies View Related

How To Change Background Color Of Console

Mar 30, 2014

I'm using eclipse to run my java program.

I want to be able to change the background color of the console when the user types in a particular command..

e.g User types: color blue

Then the background color of the console should turn blue

Is this possible and how would I go about doing it?

View Replies View Related

Put A Button On Jpanel In Jframe With Background

Jan 2, 2014

I am trying to put a button (in a container) on a jpanel in a jframe with a background but the container is covering up the background with white color.Below I have an excellent SCCE:

Java Code:

package drawFramePackage;
//drawFramePackage
// Author: Nathan Nelson
import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JPanel;
import java.awt.Dimension;
import javax.swing.JFrame;

[code]...

Basically I just need to set the containers background to transparent.

View Replies View Related

How To Make Image Background For A Window

Jun 17, 2014

I would like to learn how to add an image background to a window in java that I can put controls like buttons, textboxes, and checkboxes in front of. I already tried using a JLabel with an ImageIcon but I cannot overlay controls over the JLabel. From what I understand there are multiple ways to do this. What is the best way and how can I do it?

View Replies View Related

How To Make A Scrolling Background In Java

Nov 1, 2014

i am trying to make a platform game in java and to do this im trying to make a scrolling bacground. i can get the background image to scroll. However, i cant get the image to scroll forever, here is the code.

GamePanel class ( the jpanel )
public class GamePanel extends JPanel implements ActionListener{
static ArrayList<BackGround> store = new ArrayList<BackGround>();
public GamePanel(){
setFocusable(true);
Timer time = new Timer(5,this);
time.start();
store.add(new BackGround(0,-200));

the problem i have is that i want the bacground to loop. however, once the first instance of the background is done scrolling it freezes and doesnt load anymore. here is the code for adding a new background to the list

if(store.get(a).getX() <= -950 ){
GamePanel.store.get(a).setX(-900);
GamePanel.store.add(new BackGround(-951,-200));
}

View Replies View Related

How To Add JPanel With Background Image To Already Setup GUI

Apr 30, 2014

I am trying to set a picture in the background of my GUI. I had already made the GUI with the all the required buttons and labels. So I was trying to separately make a class which extends JPanel and add a picture to a panel by overriding the paintComponent() method, and then added it to a frame (I did not set the default layout of the frame, so it was the default...), and it worked very fine. Here is the code:

Java Code:

private BufferedImage image;
public ParentPanel() {
try {
image = ImageIO.read(getClass().getResource("/com/dev_nna/scheduler/UI/1405188.png"));
} catch (IOException ex) {
ex.printStackTrace();

[code]....

Then I needed to add this panel with background picture to the background frame of my already made frame with all the buttons on it.The layout of the parent frame of my GUI was BorderLayout(50, 50), panels (with buttons) were added to it n the north and south positions.

Then I tried to add a JPanel with the background image to the parent frame (of my GUI), (I wanted it to elapse the entire frame, and come under all the buttons and controls, which were only present in the north and south positions of the border layout), and then the panels holding the buttons to the north and south postions of this panel, everything disappeared.

If I don't do anything except adding this panel with the background image to the parent frame, it only takes up the place not taken up by the two panels on the frame (Border Layout)

how to add this panel to the parent frame of my GUI such that it elapses the entire parent frame's background, and the panels containing the buttons should sit on it.

IMPORTANT PARTS OF CODE:-
Java Code:
//TOP LEFT PANEL
JPanel topleftpanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 5, 5));
parentPanel_top.add(topleftpanel);
topleftpanel.setOpaque(false);

[code]....

View Replies View Related

Jframe Not Drawing Background Color

Oct 21, 2014

I've just started working on a program and I'm already having difficulties with the program. I can't get the background color to change from the basic gray color.

Java Code:

import javax.swing.JFrame;
import javax.swing.WindowConstants;
import java.awt.*;
import java.lang.Object;
import java.awt.Color;
public class FrameDemo{

[Code] .....

View Replies View Related

Draw JButton Over Background Image

Aug 3, 2014

I've tried multiple things but I can't seem to figure out how to get my JButton over the background graphics. On lines 104-108 I create the JButton I need to put on the screen, though I have no clue how to draw it. How I can paint over this background and have my button stay there?

public static final int WIDTH = 1024;
public static final int HEIGHT = 640;
private Thread thread;
private boolean running;
private BufferedImage image;
private Graphics2D g;

[Code] .....

View Replies View Related







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