Program That Puts 2 Images Into Frame Window

Dec 6, 2014

I just started to learn Java Swing and I was trying to make a program that puts 2 images into the Frame window. The code itself doesn't have any errors but when I compile it gives a nullpointerexception, I checked the line with the error and it had to do with my image file but I can confirm the name is correct and I tried both using the path and the name of the image in the package but neither is working.

Error message:
Exception in thread "main" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(Unknown Source)
at ImageTutorial.<init>(ImageTutorial.java:25)
at ImageTutorial.main(ImageTutorial.java:33)

[Code] ....

View Replies


ADVERTISEMENT

Java Frame Window Using Button

Jan 21, 2014

How one frame to another frame using button ?

View Replies View Related

New Window / Frame Created When Certain Key Entered

Dec 10, 2014

I'm trying to write a program where a new window/frame is created when a certain key in entered, here F1. It doesn't seem to be working..

I've done it using JApplet. Here are the functions:

String msg="";
int X=10, Y=20;
  public void init()
{
addKeyListener(this);
}
public void keyPressed(KeyEvent ke)

[Code] .....

View Replies View Related

When Code Runs - Images Are Not Showing Up In Frame

Apr 27, 2014

I'm using the book "How to Program in Java 9th Edition". The following is code from that book. I'm using eclipse. When the code is run the images are not showing up in the frame. The images are located in the directory with the java file and I have tried using the fully qualified image locations with no success. I've looked around on the web but can't see any reason why this code won't work. The code compiles and no errors are reported.

// Fig. 9.13: LabelDemo.java
// Demonstrates the use of labels
package Fig9_13DisplayTextImagesWithLabels;
import java.awt.BorderLayout;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JFrame;
public class LabelDemo

[code]....

View Replies View Related

How To Add Images To Program

Dec 14, 2014

I just finished a tutorial on youtube that covers the basic java, and now i want to try and make a game / program thing, only problem is that i have never worked with graphics before (i have tried to make ovals, rectangles, and other things with the paint method tho )

I know how to make a jframe and a jpanel, and i feel like i can make a simple "game" (not a complicated one, just a simple one with a guy walking around on the screen) in fact i have already make a such game, where you are a oval walking around on the screen, so thats not really my problem.

My problem is that i want to draw an image on the screen that can walk around instead of the oval, but how to do that. I have made a new project and set up the jframe and jpanel, and my code looks like this:

(main)

import javax.swing.JFrame;
 public class main_class {
public static void main(String[] args){
 JFrame f = new JFrame();
f.setTitle("title");
f.setVisible(true);
f.setSize(800,600);

[code]...

but once again, i get a blank jframe with no image and no "test" string . How i can display images on the screen?

View Replies View Related

Program That Will Have GUI Window And Display Image?

Jun 24, 2014

I am writing a program that will have a GUI window and displays an image when clicked on the image changes and clicked on again the image changes once more. Here is what i have.

package ButtonLab;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

[Code]....

The issue i am having is when i run it the window pops up but with no images. The images wont load, I have tried to use the c: path to the image also.

View Replies View Related

Program That Shows A Square Frame Filled With 100 Buttons Label

Apr 13, 2014

Write a program that shows a square frame filled with 100 buttons labeled 1 to 100. Nothing needs to happen when you press any of the buttons. I keep getting errors i am a beginner.

import java.awt.Frame;
import javax.swing.JButton;
import javax.swing.JPanel;
class TestFrame extends Frame {

[Code] ...

View Replies View Related

ACM Graphics Program - How To Set Location Of Entire Window

Jun 15, 2014

I have one quick question. If you are extending the acm graphics program, how can you set the location of the entire window? All the set location methods within the graphics program only seem to set the location of graphical objects. I know with JFrames I can use the setLocationRelativeTo(null) to position the JFrame in the center. How to set the location of a graphics window.

View Replies View Related

How To Put Console On JFrame Or Graphics Program Window

Sep 8, 2014

how to put a console on a JFrame or on graphics window. I thought about simply using a JtextField however I don't have access to the readline command since it appears to me that it is only found in a Console Program. So basically I was wondering how to put up a console on JFrame so I can issue commands on it and watch graphical stuff happen on the same screen(minus where the console box is of course).

View Replies View Related

Adding Popup Window To Calendar Program?

Jul 11, 2014

I was trying this sample java calendar program.

[URL] ....

How can I make popup window, which shows the date value when I click a date?

View Replies View Related

Program To Change Colors Of A Shape In Other Window

Feb 13, 2015

I was working on this project, and I have everything working, except that it doesn't change the colors of the shapes in the other window. Here's the code to see what I'm doing wrong:

Java Code:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class JDemo {
//Global Variables
static Color color0 = Color.blue; //sets the value in the color0 variable to the method Color.blue .
static Color color1 = Color.red; //Sets the value in the color1 variable to the method Color.red .

[Code] ....

The button0 is supposed to switch the color in window1, and button1 is supposed to switch the color in window0.

View Replies View Related

Java Program Not Able To Read Images / Files - AccessControlException

Nov 8, 2014

I am quite new to Java. I have downloaded a tictac example Java applet code and I run it on Eclipse with no problems. But when I try to test it outside Eclipse by doing the following:

I copy the .class file and two gif-images to another location and call the Java from html code:

<applet code="hello/HelloWorld.class" WIDTH="300" HEIGHT="300">

And I put the two gif-files to hello/images folder. I get and an error:

AccessControlException
access denied ("java.io.FilePermission")
"I:ImportantProgrammingWebProgramminghelloim ages
ot.gif" "read")

The path seems to be correct. I load the pictures from the Java code by:

notImage = getImage(getCodeBase(), "http://www.javaprogrammingforums.com/images/not.gif");

If I draw (drawLine) the X and O instead of using gif, then it works.... so its really the gif-loading which is the problem.

I have a Windows XP. I also tried to run it inside XAMPP server folder in my machine but the same problem. How could I be able to run it on my machine?

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

JavaFX 2.0 :: Manipulating Several Windows (Window Inside Window)

Apr 6, 2015

I am new to javafx I start using it instead of swing i used the scene builder for my forms the problem i faced i don't know how to have main screen with menu bar at top and depending the select from the menu it will open other windows and those window must be inside my window just like for example netbeans.

I don't need to open new window in separate i need all windows inside my main window and controlling over them minimize maximize perhaps.

View Replies View Related

How To Add Applet To The Frame

Aug 13, 2014

i have created a frame with a menu bar displaying contents..now i want to set a username and password to that flame through an applet how to add applet to the frame??

here is my code ..

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
class MenuFrame extends Frame{
String msg="";
int flag=0;
CheckboxMenuItem debug,test;

[Code]...

View Replies View Related

Cannot Add Second Component To Frame?

Apr 13, 2014

I can't seem to add second component to frame what this class creates:

package TestVersion;
import java.awt.Color;
import java.awt.Component;
import javax.swing.JFrame;
import TestVersion.CKeyListener;
import TestVersion.GameWorld;
import TestVersion.MatWood;
public class MYCoreWorld {

[Code] .....

View Replies View Related

Frame Not Displaying

Sep 20, 2014

I created a instance of a class AddItemView, inside StartUpMenuController. I then passed it into the class, the main method is below showing that as well. However when I do this:

else if(e.getSource()==menu.addBtn)
{
new addItem();
}

I get an error, little red line on the bottom of the text. I am testing the frame at the moment to make sure it is what I want before I move on to the Controller side of it. I just want to display it and go from there.

package mainMenu.Home.DataBase;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import addItemBtn.Home.DataBase.AddItemView;
public class StartUpMenuController
{
StartUpMenu menu;
AddItemView addItem;
 
[code]...

Not sure if this is the issue but the class I am making a new instance of is in a different package. I imported the package though.

View Replies View Related

How To Let A Frame Disappear And Let Another One Appear

Mar 12, 2014

i have been struggling with 2 frames.the question here is, how can you let a frame disappear and let another one appear.im making a game and when i click on start it needs to show another frame.got the whole code here:

import java.awt.Color;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class RushhourStart
{
public static void main(String [] args)
{
JFrame frame = new JFrame();
frame.setSize(700, 700);
frame.setTitle("Rushhour");
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame. EXIT_ON_CLOSE);
frame.setVisible(true);
 
[code]...

View Replies View Related

Moving Oval Around The Frame

Feb 3, 2014

I'm trying to understand and learn Java for GUI but I'm stacked around a project. I had done some other "test app" but on this, I can't figure out what I had done. I can't move my circle around the panel.... Where I had made some errors?

Main class
package main;
// imports
import javax.swing.JFrame;
import java.awt.Dimension;
public class Main {
public static final int WIDTH = 320;
public static final int HEIGHT = 240;
public static final int SCALE = 2;

[Code] .....

View Replies View Related

How To Get All Methods On One World Frame

Oct 17, 2014

I'm pretty new at java and I was wondering on how to get all my methods on one world frame?

The code is this:

public class TurtleTester
{
public static void main (String[] args)
{
World world= new World();
Turtle turtle= new Turtle(world);
turtle.drawRectangle(50,100);
turtle.drawHexagon(100);

[Code]...

When I run the main method, it would give me a bunch of world frames with one method in each one. I'm using BlueJ btw.

View Replies View Related

Getting And Setting Frame Name From Another Class

Aug 7, 2014

package com.simbaorka101.te.gui;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.ScrollPaneConstants;
import javax.swing.event.DocumentListener;

[code]....

This is my frame class, now I want to be able to change the name of the frame, and get the name with frame.getName() in another class. But I'm not sure how to do this, i tried making a new frame in that class but i feel it's just another frame and not the one i made, also tried something like

public JFrame getFrame(){
this.getFrame();
}

and few variations but it was wrong.

View Replies View Related

Nothing Except Frame And Label Shows Up

Apr 3, 2014

Java Code:

import java.awt.*;
import java.awt.event.*;
public class TestFrame extends Frame implements ActionListener {
static int i;
Frame fr;
Button b1,b2;
Image img[]=new Image[3];

[Code] .....

View Replies View Related

Swing/AWT/SWT :: Frame And Panels

Nov 30, 2014

I wrote the following code to get a frame,button in south and a red color circle,which i got.In the "actionPerformed" method i wrote "setContentPane(mp2)" thinking it would put another panel on the frame with a blue circle but when i pushed the button,the button got stuck and the circled did not change.

import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Fra implements ActionListener
{
MyPanel2 mp2;
JFrame frame;
JButton button;
public static void main(String[] args)

[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

JLabel Will Not Show Up In Frame

Apr 5, 2014

So Im making a game with a start screen followed by my game. I have a button centered but Im having a hard time displaying my label. Here's my code:

import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
 import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JFrame;
 public class TitleScreen extends JPanel implements ActionListener{
 
[Code] ....

View Replies View Related

How To Pass Values To A New Frame

Nov 28, 2014

I'm new to Java and I'm trying to pass several values from one frame to another. I've searched around and most codes I've come across are from auto generated GUI code. This what I've been trying to do

Frame1

private class SubmitButtonListener implements ActionListener {
public void actionPerformed (ActionEvent e) {
Frame2 f2 = new Frame2();
//call setValue from Frame2
f2.setValue(4.0);
f2.setVisible(true);
}
}

Frame2

private double val;
public double getvalue()
{
return val;
}
public void setValue(double v)

[code]...

View Replies View Related







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