Making moving eyes in java

i have been trying to make a java applet in which:
there is a circle as an eye (using the drawOval())
and then there is an eyeball (using the fillOval())
the eyeball is supposed to follow the movements of the mouse cursor...
and i m not able think of any idea to do that...
can anyone please give me an idea as to how to do this??

the code i posted earlier was opaque and unclear, so this time i post a clearer code
//moving eyeball
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class eyeball extends Applet implements MouseMotionListener
//(x1,y1)=mouse co-ordiantes
//(x,y)=eyeball co-ordianates
//(cx,cy)=eye-centre co-ordinates
//r=radius of eye
int x1,y1,x,y,cx,cy,r;
double m,k1,k2,k3,k4,k5,k6,k7,k8,pvx,pvy,pvx2,pvy2; //these are intermediate values to eventually get the values of (x,y)
                                                    //and are described below as and when required
public void init()
addMouseMotionListener(this);
public void mouseMoved(MouseEvent e)
x1=e.getX();
y1=e.getY();
cx=330;
cy=330;
r=30;
//"slope_numerator" is the numerator part in the formula of slope of the line
//(m=y2-y1/x2-x1) the line here is the line joining the centre of the cirle to
//the co-ordinates of the mouse
double slope_numerator=(y1-cy);
//"slope_dinominator" is the dinominator part in the formula of slope
//(m=y2-y1/x2-x1) the line here is the line joining the centre of the cirle to
//the co-ordinates of the mouse     
double slope_dinominator=(x1-cx);      
//slope of the line
m=slope_numerator/slope_dinominator;   
//start of finding values of x
//from the equation y-y1=m(x-x1) we make y the subject of formula . i.e. y = mx - (mx1-y1)
//so here k1=mx1-y1
//so the equation of line is y=mx-k1
//product_m_and_x1 is the product of m*x1
double product_m_and_x1=m*x1;
//so ,k1 difference between product_m_and_x1 and y1
k1= product_m_and_x1-y1;
//from the equation of circle r^2=(cx-x)^2 +(cy-y)^2 (where r=radius and r^2 => (r squared and so on)
//now i substitute equation of line(y=mx-k1)  in equation of circle
//r^2=(cx-x)^2 + (cy-(mx-k1))^2
//i group (k1+cy) together as k2 ie k2=k1+cy
//so the equation becomes
//r^2=(cx-x)^2+(k2-mx)^2..............................................................................(equation2)
k2=cy+k1;
//when the equation2 is expanded we get
//r^2=[(cx)^2  +  (k2)^2]             -        x(2*cx+2*(k2)m)        +        x^2(1+m^2)...............................(equation3)
//taking k3=[(cx)^2+(k2)^2] ie.sum of cx_squared and k2_squared
//cx_squared is square of cx value
double cx_squared=cx*cx;
//k2_squared is square of k2 value
double k2_squared=k2*k2;
k3=cx_squared+k2_squared;
//from equation3(r^2=(cx)^2+(k2)^2-x(2*cx+2*(k2)m)+x^2(1+m^2))
//take k4=[2*(cx)+2*(k2)*m] ie.sum of 2 times cx and 2*m times k2
//cx_times_2 is 2*cx
double cx_times_2=2*cx;
//k2_times_2_times_m is 2*k2*m
double k2_times_2_times_m=2*k2*m;
//therefore calculating k4
k4=cx_times_2 + k2_times_2_times_m;
//from equation3(r^2=(cx)^2+(k2)^2-x(2*cx+2*(k2)m)+x^2(1+m^2))
//take k5=[1+m^2] ie sum of m_squared and 1
//first calculate m_squared as m*m
double m_squared=m*m;
//calculate k5=[1+m^2]
k5=1+m2_squared;
//so the equation3 is reduced to r^2=k3 - x(k4) + x^2(k5)
//bringing r^2 to Right Hand Side(RHS) ....
//0=[k3-r^2]    -     x(k4)      +      x^2(k5)...............................................................................(equation4)
//k6=[k3-r^2]
//Therefore the quadratic equation in x becomes
//x^2(k5) - x(k4) +k6 = 0.....................................................................................(equation5)
//first we calculated k6
//for that we need value of r_squared
//therefore we calculate r_squared = r*r
double r_squared=r*r;
//then we find k6=k3-r^2 in equation4
k6=k3-r2;
//we now solve the quadratic equation in x of the (equation5)
//for that we use the standard formula used to get the value of x in the equation
// (a)x^2+(b)x+c=0
//which is x= {-b (-+) squareroot of (b_squared - 4*a*c)}/(whole divided by 2*a)
//in (equation5):: a=k5, b=-k4 , c=k6
//first we find the value of the determinant ie. squareroot of (b_squared - 4*a*c)
//so since k4 is b here we find the value of k4_squared
double k4_squared=k4*k4;
//then we find the value of 4*a*c
//so since a=k5 and c=k6 we store the value of product into the variable k5k6
double k5k6=4*k5*k6;                 //(ok u guys were right the coding earlier was horrible. there was a mistake here)
//now we find the difference of b_squared and 4*a*c ie. k4_squared and k5k6
double discriminant_squared=k42-k5k6;
//then we find the discriminant_value by taking square root of discriminant_squared
discriminant_value=Math.sqrt(discriminant_squared);
//we then find the dinominator_value in the formula. ie. 2*a
//the value of a here is k4. so dinominator_value becomes 2*k4
dinominator_value=2*k4;
//then we calculate the value of => (-b - discriminant_value )
//here that would be difference between k4 and discriminant_value
double numerator_value1=k4-discriminant_value;
//then we find the first possible value of x (pvx)
//the first possible value of x(pvx) is numerator_value1/dinominator_value
//since, numerator_value1 represents [-b - squareroot of (b_squared - 4*a*c)]
pvx=numerator_value1/dinominator_value;
//then we calculate the value of => (-b + discriminant_value )
//here that would be sum of k4 and discriminant_value
double numerator_value2=k4+k7;
////then we find the second possible value of x (pvx2)
//the second possible value of x(pvx2) is numerator_value2/dinominator_value
//since, numerator_value2 represents [-b + squareroot of (b_squared - 4*a*c)]
pvx2=numerator_value2/dinominator_value;
//So the two possible x values are pvx,pvx2
//end of finding values of x
//start of finding values of y
//from the equation y-y1=m(x-x1) we made y the subject of formula . i.e. y = mx - (mx1-y1) or y=mx -k1
//now we have the value of x as pvx and pvx2 so now we can find values of y
//product_mx1 represents the product of mx in the equation y=mx-k1 when x is pvx
double product_mx1=m*pvx;
//product_mx2 represents the product of mx in the equation y=mx-k1 when x is pvx2
double product_mx2=m*pvx2;
//so now we can calculate the possible value of y(pvy and pvy2) corresponding to possible value of x(pvx and pvx2)
//so pvy is product_mx1 - k1 form the equation y=mx - k1
pvy=product_mx1-k1;
//similarly pvy2 is product_mx2 -k1 from the equation of line y=mx-k1
pvy2=product_mx2-k1;
//end of finding values of y
//but the values of (pvx,pvy) and (pvx2,pvy2) are in double , so convert them to int
//therefore
x=(int) pvx;
y=(int) pvy;
//so the co-ordinates of the eyeball should be (x,y)
//(x,y) is the point on the eye(circle) which satisfies the line joining the mouse pointer co-ordinates and centre of eye(circle)
//end of calculations
repaint();
//end of mouseMoved method
public void mouseDragged(MouseEvent e){}
public void paint(Graphics g)
//the eye
g.drawOval(300,300,60,60); 
//the eyeball
g.fillOval(x,y,20,20);
//the line joining the centre of eye(circle) to the position of mousepointer
g.drawLine(330,330,x1,y1);
//calculated values for the sake of reference
g.drawString("x1,y1="+x1+"::::"+y1,50,50);                  //this shows current co-ordinates of mouse pointer
g.drawString("m="+m,50,65);                                 //this shows the slope(m) of the line y=mx-k1
g.drawString("k1="+k1,50,80);                               //this shows the value of k1 
g.drawString("k2="+k2,50,95);                               //this shows the value of k2           
g.drawString("k3="+k3,50,110);                              //this shows the value of k3
g.drawString("k4="+k4,50,125);                              //this shows the value of k4
g.drawString("k5="+k5,50,140);                              //this shows the value of k5
g.drawString("k6="+k6,50,155);                              //this shows the value of k6
g.drawString("k7="+k7,50,170);                              //this shows the value of k7
g.drawString("k8="+k8,50,185);                              //this shows the value of k8
g.drawString("pvx,pvy="+pvx+"::::"+pvy,50,200);             //this shows current co-ordinates (pvx,pvy)
g.drawString("pvx2,pvy2="+pvx2+"::::"+pvy2,50,220);         //this shows current co-ordinates (pvx2,pvy2)
g.drawString("x,y="+x+"::::"+y,50,240);                     //this shows current co-ordinates of the eye-ball(fillOval)
//end of paint method
//end of applet
/*<applet code="eyeball" height=800 width=600></applet>*/

Similar Messages

  • Making a database in Java

    would making a database in Java be hard especially if I wanted to incorporate SQL into the data base?

    jverd wrote:
    Adrienk wrote:
    can I make a program that will interact with a database (lets say oracle)Google for jdbc tutorial.
    in such a way where i can use arrays to store information and then sort through the arrays at a latter time by use of a search method to find and pull specific information? or would i even need a data base for this type of project?That's very vague, and arrays really have nothing to do with it. You will define classes in Java, such as, say, Student, Course, Instructor, Classroom, etc. A given application or feature will use some or all of those classes. If an application needs to be able to do things like "print the class list for a given student," and "find the classrooms available for a particular course," and a dozen others, then, yes, you probably want a database to manage the relationships, searching, filtering, and all the stuff that a DB is made for. If, on the other hand, it's just a simple app that displays a few things, lets you select something, and maybe retrieves a few simple objects by fixed keys like name or ID, then a DB is probably overkill.the relationship is what i want to do, so now i wonder - how do you create an application in java to interact with a database?

  • How to view impact of making Moving Average ?

    Post Author: izhar
    CA Forum: Performance Management and Dashboards
    Hi, group members I am working on BOXI R2. Following are the steps which i performed for making moving average according to the manual. I have selected "Monthly" from the Calendar option Move the "Moving Average" in Defined Transformation and in last changed the entries of "Number of Points and Offset" Changes are saved successfully. But not able to see the impact of it. Can any member guide me here, How to view the impact of it. Regards, Izhar

    Post Author: Ferhat
    CA Forum: Performance Management and Dashboards
    hi,
    moving average is a transformation which we use to remove the seasonality from the time series data.
    we do it for to forecast based on just trend variability.
    if there is already no seasonality in your data you shouldn't see any clear impact.

  • Making optgroup /optgroup in Java

    Is it possible to implement this drop-down box in a Java Swing application? I kept searching for this from the web, but I cant find relevant info. I cant make the optgroup function in neither JComboBox nor JList. Tell me how to do it, if you have this experience.
    Thanks in advance!
    <select>
      <optgroup label="Swedish Cars">
        <option value="volvo">Volvo</option>
        <option value="saab">Saab</option>
      </optgroup>
      <optgroup label="German Cars">
        <option value="mercedes">Mercedes</option>
        <option value="audi">Audi</option>
      </optgroup>
    </select>

    Sorry for my inaccurate English.
    And thank you DarrylBurke for the correction, I have looked it in the dictionary.
    Back to my question, actually I have a particular question about making the list items of JComboBox not selectable, as in the first picture. The second picture is the Swing version, in which I'm not able to make it not selectable.
    [1. HTML combo box|http://home.netvigator.com/~bigblack/labu/drop-down-box.gif]
    [2. JComboBox|http://home.netvigator.com/~bigblack/labu/drop-down-box-swing.png]
    I always read the suggested tutorials, the closest parts are about implementing ActionListener and ListCelRenderer. Do I have a more-convenient alternative?

  • Making nice GUI in Java!!!???

    I've used Visual Basic where you add frames to an MDI parent for making a multiscreen project
    I want to do similar in Java. Is the only way to do this through using Desktoppane or splitpane? I dont like the visible split in splitpane, and I don't like the topbar on the jinternalframe. What can I do. Any good suggestions.

    Hello,
    you can try to use change the CommonLookAndFell.
    try {
    UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    catch(ClassNotFoundException e){}
    then the topbar should have another appearance.
    Andre

  • Moving to 64bit Java

    Hi,
    We are interested in moving to 64 bit java due to memory issues (HUGE data models)
    We are in the process of investigating possible OS and hardware platforms.
    Our preference is for 64bit Windows Vista and Intel Xeon based workstations from DELL.
    Does anyone know if this is a problem with this OS and CPU combination ?
    The 64 bit jdk download is specifically named ***amd64****
    jdk-6u10-rc-bin-b28-windows-amd64-21_jul_2008.exe
    Does this indicate that only the AMD family of 64 bit CPUs is supported and not the Intel Xeon ?
    /Geir

    It is called AMD64, because AMD was the first to implement a 64bit variant of the x86 platform, and therefor defined the 64 bit instruction set. Since then Intel has 'copied' (under agreement with AMD) this instruction set, and most Intel 64 bit processors use the same instruction set. It is still refered to as AMD64, while it x86-64 would be more correct nowadays. See also [http://en.wikipedia.org/wiki/AMD64]
    So with an Intel Xeon you should have no problem running Java-AMD64
    Edited by: TheAvalanche on 23-aug-2008 19:11

  • Making Moving average price a mandatory field in MM01

    Hello,
    I've tried to make MBEW-VERPR a mandatory field in TC MM01, but with no success.
    I tried using field selection (OMSR), screen variant (SHD0), making system message M3 131 an Error - nothing worked.
    Please advice.
    Thanks,
    Dikla

    Dear Lakshman,
    You are right in what you are saying, and to explain the reason why I'm trying to make this field mandatory, I'll describe a scenario:
    You have a Make To Order purchased material and you received an order for this material from one of your customers. You go out to purchase this material.
    When you do GR for this PO, the PO price does not change the moving average price (MAP) of this material - it changes the sales order MAP of this material.
    If, for some reason, the customer cancels his order at this point, you will do transfer posting to this material and change it from sales order stock to own stock.
    We do this transfer posting with movement type 414 and that movement does not change the MAP of the material.
    Now we have stock for this material, but with MAP zero.
    If now we receive another customer order, we don't have to go out for purchase because we have this material in stock.
    If we will use MvT 413 to allocate the stock to the sales order,
    it will be allocated with price zero.
    In this case, when we'll post the outbound delivery, no financial document will be created because the price of the material was zero.
    I want to prevent this situation.
    If the field is mandatory, even a price of 0.01 will be enough for the creation of financial document when I post a material document.
    Dikla

  • Making .exe for a java file

    Hello all, i'm much interested in making
    a java file to be in .exe form without using any
    IDE's available for JAVA .
    Is it possible for us to make the .exe form of a
    java file to be executed in a machine
    which has only JRE AND JVM.

    Hi Jayandh,
    Please see these forum threads. It will give you some idea.
    http://forum.java.sun.com/thread.jsp?forum=17&thread=150203
    http://forum.java.sun.com/thread.jsp?forum=31&thread=149733
    I hope this will help you.
    Thanks
    Bakrudeen

  • I think the new grey icons are making my eyes hurt...

    After upgrading to Lion today, my eyes started hurting while I was using the computer. There may be other reasons, but one of them could be because the icons are now in grayscale. I've noticed myself squinting when I go to click on one. They also seem to be slightly out of focus compared to everything else. Is anyone else getting this? Is there a way of changing the icons back to colour or making them larger?

    baltwo,
      I've thought of signing up on the Developer Page a few times. But the first information window that comes up asks about specific areas of development your working in. If your not actually a developer and you primarily want to get involved with bug reporting and enhancement areas, how would you fill the form out.
    Complete your professional profile
    (All form fields are required)
    Which Apple platforms do you develop with? Select all that apply.
    iOS
    Mac OS X
    Safari
    What is your primary market?
    Business
    Medical
    Reference
    Education
    Music
    Social Networking
    Entertainment
    Navigation
    Sports
    Finance
    News
    Travel
    Games
    Photography
    Utilities
    Health & Fitness
    Productivity
    Weather
    Lifestyle
    Check this box if you are currently enrolled in a college or university.

  • Making https: connection from java code loaded into Oracle 8i database

    A bit of a blast from the past, really, as 8i provides a JVM at 1.2.2.
    I need to provide an PL/SQL function which accesses a RESTful web service requiring https connection. Got the call working under 1.2 locally without much trouble using:
    static {
            System.setProperty("java.protocol.handler.pkgs",
                    "com.sun.net.ssl.internal.www.protocol");
            Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
        }The trick is to get the Oracle database to run the code internally. What libraries do I need where? I get an extremely unhelpful NoClassDefFoundError, without mention of the offending class.
    By doing loadjava with jcert.jar,. jnet.jar and jsse.jar (the libraries I'm using with the test program) I can get loadjava to accept and allegedly resolve the class.

    endasil wrote:
    malcolmmc wrote:
    Well, sadly look at the colour scheme.Yeah, sarcastic was I. The NoClassDef error seriously doesn't give a class name? I find it astonishing that any implementation would be that stupid.Seriously. The strange thing is that before I got to the NoClassDefFound I had a Initialization error (until I added a security rule for setting the Provider) and for that I got a full stack trace (in an obscure trace file, granted).

  • Making system calls in java

    I want to join some split files into one. In command prompt I use COPY /B file.1+file.2 file to join the files. How can i do the same in my java application. Please show the code which I suppose will use getRuntime. Thanks in advance.

    Well if there is a problem with system calls then can
    you tell me if there is a class in java for
    concetanating files. Not directly.
    At present I am joing the files
    by reading each byte from the files and writing them
    to another file which takes hell lot of time. You should read the files in large chunks. Much much faster.
    Thanks
    in advance again. Also if you say about sequential
    file class then please expalin a bit bcs I couldn't
    implement it.Post the code you are having trouble with explaining what it should do and what it actually does.

  • Making jar file for java application with third party (Crystal Report)

    Hi all,
    I'm writing a java program that integrate with Crystal Report, I can run it in JBuilder fine, but when I try to make a jar file with JBuilder and run it, it either doesn't work or give me error.
    Case 1: If i only include the "dependencies", the program run but it woun't call the report when I open it. It give me the following error:
    com.businessobjects.reports.sdk.JRCCommunicationAdapter
    com.crystaldecisions.sdk.occa.report.lib.ReportSDKException: com.businessobjects.reports.sdk.JRCCommunicationAdapter---- Error code:-2147215357 Error code name:internal
         com.crystaldecisions.sdk.occa.report.lib.ReportSDKException.throwReportSDKException(ILjava.lang.String;)V(Unknown Source)
         com.crystaldecisions.proxy.remoteagent.z.a(Ljava.lang.String;)Lcom.crystaldecisions.proxy.remoteagent.ICommunicationAdapter;(Unknown Source)
         com.crystaldecisions.sdk.occa.report.application.ReportAppSession.int()V(Unknown Source)
         com.crystaldecisions.sdk.occa.report.application.ReportAppSession.initialize()V(Unknown Source)
         com.crystaldecisions.sdk.occa.report.application.ClientDocument.for()V(Unknown Source)
         com.crystaldecisions.sdk.occa.report.application.ReportClientDocument.for()V(Unknown Source)
         com.crystaldecisions.sdk.occa.report.application.ClientDocument.open(Ljava.lang.Object;I)V(Unknown Source)
         com.crystaldecisions.reports.sdk.ReportClientDocument.open(Ljava.lang.Object;I)V(Unknown Source)
         GOV.NE.REVENUE.LB775.CRYSTALREPORT.JRCViewReport.launchApplication(JRCViewReport.java:43)
         GOV.NE.REVENUE.LB775.LB775$5.actionPerformed(LB775.java:1114)</message>
    case 2: if I include the "dependence and resources" when create jar file, then the program won't run. It gives me a message:
    Cannot find main class. Program will exit.
    But I do have the manifest.mf file that contain the main class.
    Thank you very much for any help.

    Hello, I have the same problem, did you solved it?
    Thanks

  • Problem in making exe file for java application

    helo,
    i tried to make an windows installer packge for my jar file using advance installer. There is one option for including JRE with this package. i included jre package also.otherwise ,the applicaiton will not work in client side,if java is not installed in his system.
    But the problem is after i make the setup including JRE ,the size of the file become 26mb. So,it took long time to download the application.
    What are the essential jav files we have to include while makes the setup for running the application.I included all the JRE folder itself.
    So the size become heavy. Anybody plz help me solve this
    regards
    jithesh

    Hello, I have the same problem, did you solved it?
    Thanks

  • ADF Faces: Making a selectOneChoice in java code?

    I need to make a selectOneChoice to reuse in my pages (country selection) but can't seem to find how to do it on the web?
    here is what i've attempted with the error output...
    -------------------- the java code:
    public void contextInitialized(ServletContextEvent event)
    ServletContext servletContext = event.getServletContext();
    Utils.log(servletContext, "Initializing Supply Chain Management System...");
    // intitilize selectOne component
    CoreSelectOneChoice countrySelectOne = new CoreSelectOneChoice();
    List countrySelectItems = new ArrayList();
    CountryCoordinator countryCoordinator = new CountryCoordinator();
    try
    List all = countryCoordinator.getAllCountries();
    Iterator i = all.iterator();
    for(;i.hasNext();)
    Object object = i.next();
    CoreSelectItem item = new CoreSelectItem();
    item.setValue((Country)object);
    item.setLabel(((Country)object).getCountry_name());
    countrySelectItems.add(item);
    // place the list of select items into the selectOne component
    countrySelectOne.setValue(countrySelectItems);
    servletContext.setAttribute("countrySelectOne", countrySelectOne);
    Utils.log(servletContext, "Initializing Countries [SUCCESS]");
    } catch(Exception e)
    Utils.log(servletContext, "Initializing Countries [FAILED]");
    Utils.log(servletContext, "Initialization complete...");
    ------------------------------ the JSP:
    <af:selectOneChoice label="#{bundle.ADDRESS_COUNTRY}:" required="#{region_entity_address.required_entity_address_country}" binding="#{applicationScope.countrySelectOne}"/>
    ------------------------------ the error:
    15:36:48,984 INFO [STDOUT] Sep 16, 2005 3:36:48 PM oracle.adfinternal.view.face
    s.renderkit.core.xhtml.SimpleSelectOneRenderer _getSelectedIndex
    WARNING: Could not find selected item matching value "CoreSelectItem[UINodeFaces
    Bean, id=null]" in CoreSelectOneChoice[UIXEditableFacesBeanImpl, id=_id30]
    ....

    That's right. JSF produces such IDs. They are causing problems with JAAS login forms, so we should use plain JSPs for login, but for the rest of the tasks such IDs are okay.
    What I meant is that currenty the buttons are not rendered as
    <input type="button" ... />but as pictures embedded in hyperlinks (&lt;a>).
    It's possible, though not likely, that in some future version of ADF Faces some component will be rendered as an HTML element that doesn't support tab ordering (although I haven't really considered if there are such elements). Then the trick with manually setting the tabIndex of the parent HTML element won't work.
    Of course, I deeply appreciate the fact that you take the time to help us on this forum. In fact, I will go ahead and do just that -- I will dynamically set the tabIndex via JavaScript. I was simply wanting to make sure that I wasn't taking such a hack-like approach, if there was a better method.
    Thank you again.
    Best regards,
    Bisser

  • Need help making pace invaders in java

    So here is my code:
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import javax.swing.*;
    import javax.swing.JFrame;
    import java.awt.*;
    import javax.swing.JPanel;
    import java.awt.Canvas;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.image.BufferedImage;
    import java.net.URL;
    import javax.imageio.ImageIO;
    public class invaders extends Canvas {
    public static final int Width = 800;
    public static final int Height = 600;
    public invaders() {
    JFrame openspace = new JFrame("Space Invaders");
    JPanel window = (JPanel)openspace.getContentPane();
    setBounds(0,0,Width,Height);
    window.setPreferredSize(new Dimension(Width,Height));
    window.setLayout(null);
    window.add(this);
    openspace.setBounds(0,0,Width,Height);
    openspace.setVisible(true);
    openspace.addWindowListener( new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    System.exit(0);
    public void paint(Graphics graph) {
    // graph.setColor(Color.red);
    // graph.fillOval( Width/2-10, Height/2-10,20,20);
    // spacealien = loadImage("spaceAlien.jpg");
    // graph.drawImage(spaceAlien, 50, 50, this);
    public static void main(String[] args) {
    invaders spaceinvaders = new invaders();
    I am trying to add pictures into the JFrame but I don't know how. I am following this tutorial http://www.planetalia.com/cursos/Java-Invaders/JAVA-INVADERS-04.tutorial but I get confused when they talk about how to add in an image.
    This is their Code:
    1 package version04;
    2 /**
    3 * Curso B?sico de desarrollo de Juegos en Java - Invaders
    4 *
    5 * (c) 2004 Planetalia S.L. - Todos los derechos reservados. Prohibida su reproducci?n
    6 *
    7 * http://www.planetalia.com
    8 *
    9 */
    10
    11
    12 import java.awt.Canvas;
    13 import java.awt.Dimension;
    14 import java.awt.Graphics;
    15 import java.awt.event.WindowAdapter;
    16 import java.awt.event.WindowEvent;
    17 import java.awt.image.BufferedImage;
    18 import java.net.URL;
    19
    20 import javax.imageio.ImageIO;
    21 import javax.swing.JFrame;
    22 import javax.swing.JPanel;
    23
    24 public class Invaders extends Canvas {
    25 public static final int WIDTH = 800;
    26 public static final int HEIGHT = 600;
    27
    28
    29 public Invaders() {
    30 JFrame ventana = new JFrame("Invaders");
    31 JPanel panel = (JPanel)ventana.getContentPane();
    32 setBounds(0,0,WIDTH,HEIGHT);
    33 panel.setPreferredSize(new Dimension(WIDTH,HEIGHT));
    34 panel.setLayout(null);
    35 panel.add(this);
    36 ventana.setBounds(0,0,WIDTH,HEIGHT);
    37 ventana.setVisible(true);
    38 ventana.addWindowListener( new WindowAdapter() {
    39 public void windowClosing(WindowEvent e) {
    40 System.exit(0);
    41 }
    42 });
    43 }
    44
    45 public BufferedImage loadImage(String nombre) {
    46 URL url=null;
    47 try {
    48 url = getClass().getClassLoader().getResource(nombre);
    49 return ImageIO.read(url);
    50 } catch (Exception e) {
    51 System.out.println("No se pudo cargar la imagen " + nombre +" de "+url);
    52 System.out.println("El error fue : "+e.getClass().getName()+" "+e.getMessage());
    53 System.exit(0);
    54 return null;
    55 }
    56 }
    57
    58
    59 public void paint(Graphics g) {
    60 BufferedImage bicho = loadImage("res/bicho.gif");
    61 g.drawImage(bicho, 40, 40,this);
    62 }
    63
    64 public static void main(String[] args) {
    65 Invaders inv = new Invaders();
    66 }
    67 }
    68
    I know there must be an easier way. Please help, thanks!!!!

    One way to add an image to a user interface is to use a JLabel with an ImageIcon: [http://java.sun.com/docs/books/tutorial/uiswing/components/label.html]

Maybe you are looking for

  • CR4E     ....   you know someone who works  this plugin with MS ACCESS??

    Post Author: arfetgas CA Forum: Data Connectivity and SQL !SESSION 2008-04-09 10:22:33.775 - eclipse.buildId=M20071023-1652 java.version=1.6.0_05 java.vendor=Sun Microsystems Inc. BootLoader constants: OS=win32, ARCH=x86, WS=win32, NL=es_ES Command-l

  • ContainerBreaks and ColumnBreaks feature in TLF 3.0

    Feature Description Add a way for the user to force the text to break and continue on the next column or container. It is an attribute, and you should either be able to apply it to an element to force it to be the last in the column or container, or

  • Watermark PDF action

    I am having trouble with the Watermark PDF action. Whenever I attempt to enter anything in the X or Y offset, the program locks up and I have to force quit. Anyone else experienced this?

  • Changing Names of Temporary tables Created BY CKm and LKM

    Hi, I am new to ODI. I want to know if we can change the default name structure that is used by ODi to create temp tables. I$,C$ and E$ table. E.G:- If i want to keep I$1 for one schema and I$2 for another schema. Is there any way by which we can do

  • File --- XI --- SOAP scenario

    I have a scenario where I would be reading a input file and invoke a Soap adapter and then get back the response and write to another output file. So, i need to configure two asyncronous file adapters(one for inbound and one for outbound) and one syn