Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: JFrame Edit

  1. #1
    Junior Member
    Join Date
    May 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default JFrame Edit

    Hello, I was wondering how to edit the characteristics for the picture. I'm trying to make it so that I can specify a width, height, and location where the image appears. Here's my Main class...

    package JavaGame;
     
    import java.awt.Color;
    import java.awt.Container;
    import javax.swing.JFrame;
    import JavaGame.movingsprite;
     
     
    public class Main {
     
        //movingsprite ='s Garrets playa
     
        public static void main(String[] args) {
            JFrame f = new JFrame("Girl Trauma");
            Container fc = f.getContentPane();
            f.setSize(800, 800);
            f.setLocation(100, 100);
            fc.setBackground(Color.cyan);
            f.setVisible(true);
            movingsprite tim = new movingsprite();
     
     
     
     
     
        }
     
    }



    and here's my code for the movingsprite class...

     
    package JavaGame;
     
    import javax.swing.*;
    public class movingsprite extends javax.swing.JFrame{
        public movingsprite() {
            a = new javax.swing.JLabel();
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            a.setIcon(new javax.swing.ImageIcon("C:/Documents and Settings/apcompsci/My Documents/NetBeansProjects/JavaApplication42/src/JavaGame/bball.jpg"));
            add(a);
            pack();
        }
     
        public static void main(String args[]){
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new movingsprite().setVisible(true);
                }
            });
        }
     
        private javax.swing.JLabel a;
     
    }


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: JFrame Edit

    If you are looking to do some image movements and animation, you might be better off doing the custom drawing in a JPanel. See Trail: 2D Graphics (The Java™ Tutorials), most notably look at the Graphics object where you can draw an image (g.drawImage) by specifying the upper left and top coordinates. If you want to resize, look at Image getScaledInstance method.

Similar Threads

  1. Loading Images and Edit it
    By shadihrr in forum Java Theory & Questions
    Replies: 1
    Last Post: March 25th, 2010, 08:39 PM
  2. Eclipse: How to use/edit shorcut keys.
    By Truffy in forum Java JDK & IDE Tutorials
    Replies: 3
    Last Post: December 3rd, 2009, 12:51 PM
  3. Edit ArrayList Object
    By frankycool in forum Collections and Generics
    Replies: 12
    Last Post: November 16th, 2009, 12:31 AM
  4. Struts combobox edit
    By kalees in forum Web Frameworks
    Replies: 2
    Last Post: November 1st, 2009, 12:27 AM
  5. How to edit eclipse project builds
    By akhilachuthan@yahoo.co.in in forum Java IDEs
    Replies: 1
    Last Post: June 25th, 2009, 09:36 AM