Loading Images/Having images load at the center of a JFrame with random col

Hey Guys,
I was wondering how could i go about loading images two at a time for instance have two circle images load at the center of a J Frame connected to each other and also each time the J Frame is executed the circles are different colors. Ive posted this question before and have posted it on another forum but i have not gotten any help. I looked into using media tracker and the Random command but i am still not if these are the proper solution to my problem. Id appreciate any help if this post doesn't make sense let me know i will try and clarify better. Thanks in advance

Ah alright then so what i have to far is i have an image load to my J Frame/J Panel and after it loads it starts to fall like a tetris block and i am able to move it left and right. When the image loads it loads to the default coordinates of 0,0 the left hand top corner. What i want to do it when i run my application the image loads at the center of the J Frame/J Panel but also have another block connected to it when it loads. So basically i have loaded four separate different images and want them to load to my J Frame/ J Panel two at a time side by side like tetris and puyo puyo smashed together here is my code sorry its hard for me to explain it for some reason hope this makes more sense.
import javax.swing.*;
import java.awt.*;
public class DemoTest extends JPanel {
     public DemoTest() {
        add(new BlockPanel());
    public static void main(String[] args) { {
    JFrame frame = new JFrame("Tetris");
    frame.setContentPane(new BlockPanel());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(200,500);
    frame.setResizable(false);
    frame.setVisible(true);
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class BlockAnimation extends JPanel {
  public static final int numDroppingBlocks=2;
  private static final int MAX_X = 200;
  private static final int MAX_Y = 430;
  private static final int DELTA_Y = 2;
  private static final int TIMER_DELAY = 20;
   // Declare name's for the Image object.
   Image image[];
   Timer pptimer;
   boolean right,left;
   int X = 0;
   int x = 32;
   int y;
public BlockAnimation() {
      super();
      //Load an image file into the Image object. This file has to be in the same folder
      image = new Image[4];
      image[0] = Toolkit.getDefaultToolkit().getImage("block_yellow.png");
      image[1] = Toolkit.getDefaultToolkit().getImage("block_blue.png");
      image[2] = Toolkit.getDefaultToolkit().getImage("block_green.png");
      image[3] = Toolkit.getDefaultToolkit().getImage("block_red.png");
    //image5 = Toolkit.getDefaultToolkit().getImage("DeathNote1.jpg");
      setFocusable(true);
      BlockMove block_move = new BlockMove(); // Make a new video game KeyListener
      addKeyListener(block_move);
      //setBackground(Color.BLACK);
      pptimer = new Timer(TIMER_DELAY, new TimerAction());
      pptimer.start();
        public void setAnimation(boolean OnandOff) {
        if (OnandOff) {
            pptimer.start(); 
        } else {
            pptimer.stop(); 
        public void paintComponent(Graphics g) {
         super.paintComponent(g); 
         // draw the "stop" line for the animation
         g.setColor(Color.black);
         g.drawLine(0, MAX_Y, getWidth(), MAX_Y);
            // Draw our Image object.
       g.drawImage(image[0],X,y,this);
         if(right) // Move the block to the right
               X++;
               if(left) // Move the block to the left
              X--;
             repaint();
     private class BlockMove implements KeyListener {
     public void keyTyped(KeyEvent e){}
      public void keyReleased(KeyEvent e)
       if(e.getKeyCode() == e.VK_RIGHT)
        right = false;
        if(e.getKeyCode() == e.VK_LEFT)
          left = false;
               public void  keyPressed(KeyEvent e)
              if(e.getKeyCode() == e.VK_RIGHT)
                         right = true;
                    if(e.getKeyCode() == e.VK_LEFT)
                         left = true;
        class TimerAction implements ActionListener {
        public void actionPerformed(ActionEvent e) {
             y += DELTA_Y;
            if (y + x  >= MAX_Y) {
            setAnimation(false);
}//end class
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class BlockPanel extends JPanel {
   BlockAnimation pa;  
    BlockPanel() {
        pa = new BlockAnimation();       
        JButton startButton = new JButton("Start");       
        JButton stopButton  = new JButton("Stop");
        startButton.addActionListener(new Start());
        stopButton.addActionListener(new Stop());
        JPanel button = new JPanel();
        button.setLayout(new FlowLayout());
        button.add(startButton);
        button.add(stopButton);
        this.setLayout(new BorderLayout());
        this.add(button, BorderLayout.SOUTH);
        this.add(pa,BorderLayout.CENTER);
    class Start implements ActionListener {
        public void actionPerformed(ActionEvent e) {
            pa.setAnimation(true);
    class Stop implements ActionListener {
        public void actionPerformed(ActionEvent e) {
            pa.setAnimation(false);
}//endclass Edited by: Riz01 on Sep 14, 2009 2:34 PM

Similar Messages

  • I have a Blackberry 8330 and a MacBook. For some reason I started having connectivity issues. The handheld will not sync with the computer via pocketmac. I have uninstalled, etc 15 times. Please help

    I have a Blackberry 8330 and a MacBook. For some reason I started having connectivity issues. The handheld will not sync with the computer via pocketmac. I have uninstalled, etc 15 times. Please help

    Hi Peter!
    I'm sorry to read that you are having issues with your Sync account.
    Your best bet is to follow the steps described in this blogposts and open a bug:
    https://philikon.wordpress.com/2011/06/13/how-to-file-a-good-sync-bug/
    After that, if you don't want to user Sync in your computer, you can stop it with this simple steps:
    * At the top of the Firefox window, click on the Firefox button (Tools menu in Windows XP) and then click Options.
    * Once the options window opens, click on the Sync tab.
    * At the bottom of the Sync tab click on '''Deactivate this Device''' link

  • HT4528 I have an iPhone 5c. When I woke up this morning to take it off the charger, the iTunes icon was in the center of my screen with an arrow and a white plug illustration. I have rebooted and it is still stuck. Any suggestions?

    I have an iPhone 5c. When I woke up this morning to take it off the charger, the iTunes icon was in the center of my screen with an arrow and a white plug illustration. I have rebooted and it is still stuck. Any suggestions?

    Ante Boras wrote:
    wich OS you are using?
    @ ckuan: wich Jailbreak Tools? He wan't to jailbreak his iPhone. It's hang in the recovery mode, or i not understand right your quastion?
    iPhone 5c & 5s comes with IOS 7, if you don't know.
    You deleted the TinyUmbrella suggestion and act dumb?\

  • Is there a command to open an application menu because on other peoples macs i saw them open a little bar in the center of there screen with 4 apps running and i have did that before but on accident and i did not know what i clicked. how do i open it?

    HELP! I WANT TO KNOW!

    Mission Control? It isn't a little bar in the center of the screen but does display the running apps. You can access it via the Control+Up arrow key combination and there are preferences for it in System Preferences.

  • Firefox loads in the center of my screen and I have to use Ctrl+ to make it bigger so I can read it.

    When Firefox loads, or when it changes to a different screen, it is always centered on my monitor with lots of white space on both sides of the content. To make it larger so I can read thescreen, I have to hold the Ctrl key and tap the Plus key (+) several times until the screen is full.
    Under Options/Content/Advanced, I have checked the "Allow pages to choose their own fonts..." If I don't check this, then the fonts on the pages overlap each other and I can't read anything.

    You can use one of these extensions to set a default font size and page zoom on web pages:
    *Default FullZoom Level: https://addons.mozilla.org/firefox/addon/default-fullzoom-level/
    *NoSquint: https://addons.mozilla.org/firefox/addon/nosquint/
    It is best to leave the Font settings in "Tools > Options > Content : Fonts & Colors > Advanced" at the default to avoid problems.

  • Proxy Server asking for username and password almost 6 times for every page I load, but the same doesn't happen with other browsers like chrome

    The same question keeps popping up again and again "The proxy moz-proxy://proxy.iitm.ac.in:3128 is requesting a username and password. The site says: "moz-proxy://proxy.iitm.ac.in:3128""
    Even after i give the right details, it asks me like 5 more times before it completely loads the page. Some times it happens only 2 times.
    With other browsers like chrome, it asks only in the beginning. it doesn't occur after that.
    This started occurring only recently. i upgraded to firefox 9.0 and it functioned properly for more than 12 hours before it started occuring. i tried downgrading back to 8.0.1 but the problem still continued.

    i'm afraid i need to use proxy settings to connect to internet. The settings are all fine because it used to work properly all this time. i specify the proxy address and the port, which is correct, i am very confident. it is so because the page actually loads on firefox, but not before it asks for my user name and password for it a lot of times, and for every page. for other browsers, it asks only in the beginning, that is, when i start the browser.
    i've put three pics here. under the first two settings, the third image showing the user name and password thingy popping up. this happens a lot of times for every page.

  • Whenever I connect my iPod touch 5th generation to the charger and turn it on, my touch sensor seems to stop working so I cant unlock my iPod without having to take out the charger. Whats wrong with it?

    I got this iPod about 3 weeks ago. Whenever I connect my iPod to the charger the touch sensor seems to stop working. When my alarm goes off in the mornings i have to unplug the charger to stop the alarm. I cant do anything while the charger is connected. Any ideas what the problem is or how I can stop this happening?

    A few other users have report the same but I have not heard of a solution. Y can try:
    - Another cable
    - Another USB port
    - A wall charger
    - Reset the iOS device. Nothing will be lost       
    Reset iOS device: Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears.
    - Restore from backup. See:                                                
    iOS: How to back up                                                                                     
    - Restore to factory settings/new iOS device.                     
    If still problem, make an appointment at the Genius Bar of an Apple store since it appears you have a hardware problem.
    Apple Retail Store - Genius Bar                                      

  • "Hi,I'm having problems controllin​g the Agilent E4422B Signal Generator with Labview. When using the Labview driver functions such as initialize instrument I always get an Error -107413504​0.

    I can query the device through the measurement and automation tool. I can also Identify the instrument by issuing a *IDN? with VISA write and read. Why do I get this error while using the drivers supplied by NI for this equipment? Any Ideas?

    Hi, Brooks.
    Attached please find the files containing all the information concerning my attempt to control the Agilent E4438C. Hope you can make sense of it and help me.
    Regards
    isaac
    Attachments:
    nireport.txt ‏2 KB
    Capture.spy ‏5 KB
    CaptureSpy.doc ‏117 KB

  • How to get the data from a jtable with random order??

    hi everyone,
    i have a jtable i filled with Strring and Float data, i put this data to a MySQL database, and i use vectors and iterators to filled the database. the problem is there are some cells that are empty, and the Floats' columns throws me nullpointerexceptions.
    please if anyone know how to avoid that exception i'd would be great.
    thanks for your time.

    HI Siggi,
    Thank you for your reply..
    I am also planning to do FM to get the data. But it is saying that the Cluster table ZES does not exist (ZES is the the standard table, in SE11 also).
    How can I use the Fields from the that table.?
    What can I do now, can you please explain me about this point.
    Waiting for your reply.
    Thanks and Regards
    Rajesh
    Message was edited by:
            rajesh

  • Zooming into the center of an image

    Hi, I have this code that allows the user to zoom into an image that they have selected. However, when the image is zoomed into using the slider, it goes towards the top left corner of the image rather than the center. How can I modify my code to zoom into the center of the image instead?
    import java.awt.*;
    import java.awt.geom.AffineTransform;
    import java.awt.image.BufferedImage;
    import java.io.*;
    import javax.imageio.ImageIO;
    import javax.swing.*;
    import javax.swing.event.*;
    public class MapScale extends JPanel
         BufferedImage image;
         double scale = 1.0;
         public MapScale(BufferedImage image)
              this.image = image;
         protected void paintComponent(Graphics g)
              super.paintComponent(g);
              Graphics2D g2 = (Graphics2D)g;
              g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
              double x = (getWidth() - scale*image.getWidth())/2;
              double y = (getHeight() - scale*image.getHeight())/2;
              AffineTransform at = AffineTransform.getTranslateInstance(x,y);
              at.scale(scale, scale);
              g2.drawRenderedImage(image, at);
         public Dimension getPreferredSize()
              int w = (int)(scale*image.getWidth());
              int h = (int)(scale*image.getHeight());
              return new Dimension(w, h);
         private JSlider getSlider()
              int min = 1, max = 36;
              final JSlider slider = new JSlider(min, max, 16);
              slider.setMajorTickSpacing(5);
              slider.setMinorTickSpacing(1);
              slider.setPaintTicks(true);
              slider.setSnapToTicks(true);
              slider.setPaintLabels(true);
              slider.addChangeListener(new ChangeListener()
                   public void stateChanged(ChangeEvent e)
                        int value = slider.getValue();
                        scale = (value+4)/20.0;
                        revalidate();
                        repaint();
              return slider;
         public static void main(String[] args) throws IOException
              JFileChooser selectImage = new JFileChooser();
              if (selectImage.showOpenDialog(null) == JFileChooser.APPROVE_OPTION)
                   String path = selectImage.getSelectedFile().getAbsolutePath();
                   BufferedImage image = ImageIO.read(new File(path));
                   MapScale test = new MapScale(image);
                   JFrame f = new JFrame();
                   f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                   f.getContentPane().add(new JScrollPane(test));
                   f.getContentPane().add(test.getSlider(), "Last");
                   f.setSize(400,400);
                   f.setLocation(200,200);
                   f.setVisible(true);
    }

    KGCeltsGev wrote:
    Hi, I have this code that allows the user to zoom into an image that they have selected. However, when the image is zoomed into using the slider, it goes towards the top left corner of the image rather than the center. How can I modify my code to zoom into the center of the image instead?Since you use a JScrollPane and change the client size when you zoom in/out you need to scroll to the center every time you zoom in/out.
    This is done by using scrollRectToVisible.
    slider.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            int value = slider.getValue();
            scale = (value+4)/20.0;
            revalidate();     
            Dimension d = getPreferredSize();
            Dimension extentSize = ((JViewport) getParent()).getExtentSize();
            scrollRectToVisible(new Rectangle((d.width-extentSize.width)/2, (d.height-extentSize.height)/2, extentSize.width, extentSize.height));
    });

  • Image all over the button

    Hi guys,
    Wonder if it is possible to place an image all over the button (as if it is "center" borderLayout).
    login = new JButton(new ImageIcon("images/login.gif"));
    in this case the image is in the center and i want to eliminate all the gray area.
    thanks
    peter

    button.setInserts(0,0,0,0);
    button.setBorder(null);
    button.setBorderPainted(false);think that might work!! try one of those all all of them hope that it helps

  • How to get background image to fill the browser and remain fixed in both IE and Firefox?

    Basically what it says in the title. I've come very close in achieving this but something just doesn't tie up in the html and css code...
    First of all, I'm using IE8 and the latest version of Firefox to test this.
    I used 2 sources of information for getting this done: 1) http://css-tricks.com/perfect-full-page-background-image/ and 2) http://stackoverflow.com/questions/8958697/css3-background-size-cover-doesnt-make-image-co ver-vertically
    In Case 1 the example on the page called CSS-Only Technique #1 gives code that works almost perfectly for me, except that obviously I need a background image, however the CSS provided there is clearly just for an image dropped in the body of a page with no regard for other content that may already be there. The html code that I put on the page is simply <img class="bg" src="../images/background_image.jpg">
    Obviously I used the CSS code provided in the example, minus the last bit which is "@media screen" etc etc, which seems irrelevant to me. Obviously substituting values to suit the image on my page.
    So what happened is that it almost worked as intended in both the browsers (which means the image filled both browsers width-wise as intended and also remained fixed when I zoomed in or out in each case) except that the image went over the top of the current content that I had there already precisely because it's not a background in this "technique". (A curious side-note is that the image didn't push down the content, as I'd have expected in normal circumstances, but went right over the top of it so it hid it (like z-index).
    One thing that does bother me about this "technique" is that if you click on View Demo just below the code provided you will see on the working example page (forest background) the image clearly works as a background and the content sits happily on top! So I don't know whether the person providing the example was trying to mislead people or what! Or he got lazy and showed a different page that didn't use the exact code he provided. No matter.
    In any case this leaves me with the job only half finished, as I still need a background image that works like the 'normal image' code provided.
    On to Case 2 and on this page the first example provided gives the CSS for the background image - namely the code within html {...} part and also shows the same 'normal image' code as given in Case 1. In this case however, although the person provided a suggestion, the css and html doesn't really tie up properly plus some of the css and html seems a bit redundant. So this time when I used the 'html portion' of the CSS code (i.e. just the bit that was most relevant) I got two different behaviours in each browser and neither of which was quite what I'm looking for. In IE8 initially the page looks fine (background fills the page and content is on top) however when I zoom in or out the background also zooms in or out accordingly so is NOT fixed. In Firefox the background image DOES stay fixed, however because the image originally is not the whole height of the browser I'm guessing the code stretches it downwards (while keeping proportions - so the image essentially enlarges) to fill all of it. The quick way to get around it is to probably add some white space to the bottom of the image just to give it enough height that it doesn't stretch/resize automatically. But it would be nice to find out anyway how to get around this in the code. Overall I would say that the result in Firefox comes closest to the desired solution but of course it doesn't help matters with IE8.
    Apologies for the lengthy description but that should at least provide plenty info for anybody that might have a possible solution for me. Essentially what would be great is if somebody could advise me how to take the code from Case 1 and apply it to a 'background' piece of coding like the type that's contained within html {...} in Case 2. Like I said, it's so nearly there but I just can't make it work atm after trying to combine the various bits of code this way and that... Alternatively, if somebody has another html-css version that works nicely for achieving this then please by all means let me know! Thanks v much in advance!

    This works in modern CSS3 supporting browsers.  But not pre-IE9.
    http://alt-web.com/TEST/Resizable-BG.shtml
    Nancy O.

  • HT5281 Update to Lion 10.7.4 and Security update 02/2012 upped Ruby load to the ceiling

    After updating our home Mac mini server to Lion 10.7.4 and Security update 02/2012, with the machine now just sitting idle, no user logged-in, network cable unplugged, Ruby is generating 96% load on the CPU at all times, with processor temperature running near its limit and fans blowing full-blast.
    Switching off the Wiki server cut the load back to normal, Ruby process went behind the curtain, and things appear back to normal, but of course this is no cure, it's just a temporary fix-up.
    Any other user is experiencing anything similar?
    Any possible solution in form of a next update coming soon, for the graphic-shell-only illiterate users like me?

    Yesterday I applied the latest Lion Server Update to my Mac Mini Server (not sure about the update's number).
    I also experienced the "fans blowing full-blast" symptom for no apparent reason (no heavy apps running - Mac almost idle- and CPU, HDD, Network monitors flatlining). As well as a minor issue on the screen-sharing side: it didn't display the initial grey-background login page, but after I logged in blindly it was fine.
    The update did a restart but no power-off, so I thought the issues might occur because the hardware hadn't properly reset (yep, I had to use Windows at work...)
    Dunno if that was the cause, but after a shutdown, power-off and restart, the symptoms disappeared. Will see... so far so good.

  • Does the Lens Profile Creator work with Photoshop Elements 8.0..?

    Hello,
    I am very new to the world of Photoshop, so please forgive if this is an obvious/stupid question...
    I am using Photoshop Elements 8.0 and I have a couple of pictures that I need to remove the 'fish eye' lens distortion from around the edges...
    The blurb for the Lens Profile Creator says that it is for use in the "Adobe Photoshop® family of products"...
    Does this include Photoshop Elements 8.0 or do they really mean it is just for Photoshop CS5, Camera Raw and Photoshop Lightroom...
    Any help will be appreciated...
    Many Thanks
    mc1903uk

    PSE does not have the user-interface to turn on lens-corrections, nor does the ACR 6.1 update for PSE contain the lens-profile database installer, so if PSE is the only member of the PS-family that you have installed then effectively you cannot apply lens profiles.
    If a computer has the lens-profile database installed and lens-distortion-correction has been enabled in the XMP sidecar for a particular image, both requiring PS-CS5's ACR 6.1-updater or LR3 to be installed and one of those used to enable lens-corrections for the image, then PSE can use ACR 6.1 to apply a lens profile, because the version of the ACR 6.1 plug-in for PS and PSE is the same plug-in.
    BTW, removing fish-eye distortion completely, which is what enabling lens-corrections does by default, will leave a rather poor looking image that has been completely rectilinearized but has severe stretching of the pixels at the edges, so only the center is useable.  With my 8mm Sigma fisheye, I reduce the Distortion part of the correction down to 44 so the black corners are gone, but there is still some bulging of the image.
    If you want to experiment with lens-corrections, you could install the 30-day trial of LR3.

  • How can I fix the error image and get the regular image to load?

    Ever since the recent big update for Firefox I've been getting some sort of error for loading certain images.
    Here: http://tinypic.com/r/103bf3l/8 I have put one of those sites that give that error
    --The original image that is supposed to show is also available in that image
    Certain sites give a different size of that error image, but it looks the most like an error triangle
    I've already tried the troubleshoot of not loading images and none of the options worked
    If someone has this problem or knows how to fix it, it would be a great help

    Solution found:
    The addon "Stylish" with the theme "Google two themes" interfered with the image loading of the sites. Disabling the theme was the solution.

Maybe you are looking for

  • Data from a deleted datasource

    Hi guys, I've deleted a datasource and since all data loaded with this datasource seems to be deleted in my cube when I do a report on these. Nevertheless, the requests of these are still in the cube. Who can say me if the data have been really delet

  • Syncing and backing up take forever

    before update, if i plug phone in and it syncs automatically, it was pretty quick if there wasn't new music, etc. just say only a contact was changed. now when i plug in, even if there were no new apps purchased since the last sync, it goes through a

  • Using the Pen tool to create a shape with equal sides?

    I am new to working with the Pen tool and started drawing a rounded button (I know I can easily do this with the rounded rectangle, I'm just practicing to learn the Pen), I draw the top horizontal line and start the curve going down the right side. H

  • Sound in only one earphone - It's not the earphones though

    I just bought a pair of refurbished 1st gen. shuffles from Apple in Nov. After a couple of weeks, one of the stopped plaing music through one side of the earphones. I thought I blew the earphone, so I grab another pair, same thing. Same thing with th

  • Fund Management Configurations and user Documents - ECC 6 Version

    Dear all, If anybody have the Configuration and user documents pertaining to Fund Management - Government - ECC 6 Version and also the Configurations and user documents pertaining to Budget Control System (BCS), kindly send it to me. My E-mail ID is