How to move a button in gird layout(16-block game)?

I am designing a 16-block puzzel game and don't have any idea about how to move buttons in a grid on mouse click.

This is the code now me help me to solve this problem.
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.*;
public class Puzzel extends JFrame {
          JButton[] arr = new JButton[15];
          String[] add = {"1.jpg","2.jpg","3.jpg","4.jpg","5.jpg","6.jpg","7.jpg","8.jpg","9.jpg","10.jpg","11.jpg","12.jpg","13.jpg","14.jpg","15.jpg"};
          int X;
          int Y;
          public Puzzel(){
                    Image image;
                    Toolkit toolkit= Toolkit.getDefaultToolkit();
                    image=toolkit.getImage("icon.jpg");
                    ImageIcon icon=new ImageIcon("icon.jpg");
                    setIconImage(image);
                    setTitle("Puzzal");
                    JMenuItem pic = new JMenuItem("Solved");
                    pic.setMnemonic('a');
                    JPanel jp = new JPanel(new GridLayout(4,4));
                    ArrayList list = new ArrayList();
MouseListenerClass M1 = new MouseListenerClass();
                       for(int x = 0; x < arr.length; x++)
                           arr[x] = new JButton(add[x], new ImageIcon(add[x]));
                           getContentPane().add(arr[x]);
                          list.add(arr[x]);
                    Collections.shuffle(list);
                    for(int x = 0; x < list.size(); x++)
                          jp.add((JButton)list.get(x));
                        getContentPane().add(jp);
                             pack();
                             setSize(427,427);
                                    setResizable(false);
                    /*for(int x=0;x<arr.length;x++){
                         arr[x].addSelectionListener(new SelectionAdapter());
               public void widgetSelected(SelectionEvent event){System.out.println("IN");
                    if (event.getSource().getClass().equals(Button.class)){
                         Button button = (Button) event.getSource();
                         if (button.getText().equals("") )
                              Toolkit.getDefaultToolkit().beep();
                              else
                                   this.swapPlaces(((Integer) button.getData()).intValue());
               public void widgetDefaultSelected(SelectionEvent event){
                              System.out.println("Widget was defaultselected: " + event.getSource());
           for(int x = 0; x < arr.length; x++)
          arr[x].addMouseMotionListener(M1);
          private class MouseListenerClass extends MouseMotionAdapter
               public void mouseDragged(MouseEvent E)
               X=E.getX();
               Y=E.getY();
               for(int x = 0; x < arr.length; x++)
                    arr[x].setBounds(X,Y,100,100);
public static void main(String[] args){
                new Puzzel().setVisible(true);}
     }

Similar Messages

  • How To Move Reload Button Back To Left Hand Side

    For those who have posted about their dislike at having the reload button in the url field on the right, here is an article to get it back over to the left of the toolbar
    http://www.macworld.com/article/141588/2009/07/safarireload.html?lsrc=nlmwhints_hcrawl

    I've been a Mac user for quite a few years. In fact my first Apple computer was a IIc. But I've found myself frustrated at the reload button move. In fact I've been pretty baffled at why the decision was made. I do find the suggestion of the using the key command useful. I've not used the reload function so much that I've ever considered memorizing the key command but I'm finding that the move is causing me some discomfort with the new Safari. It seems that most of my browsing is mouse based rather than keyboard based. On the subject of improvements, I'm not sure what they are, to be honest. Safari 4 might be slightly faster but it still has a tendency to quit spontaneously. And this is on a fresh install of the OS. I'm a bit baffled at this as well after all the time and resources that Apple has put into the Safari platform. Instead of Safari, for the past several years I've been using Camino as my main browser and except for a few sites that don't quite work right I've found it to be pretty good. It doesn't just quit on me like Safari. So, the idea that this friction is coming from PC switchers is, I think, a little unfounded. Maybe it's coming from people who are switching from other browsers that all have the buttons in roughly the same place? But beyond that, perhaps someone can lend some light on why they moved it in the first place? My logic tells me that the nuts and bolts browsing functions should be grouped together. Why not put the bookmark thingy on the right?
    drew

  • How to check radio button on view  layout?

    Hi All,
            How to check on view layout whether a radiobutton is checked or not?
    Thanks & Regards,
    Rahul Rathi

    Use the below in layout, it should work..
    <%
                    DATA: rbg       TYPE REF TO CL_HTMLB_RADIOBUTTONGROUP.
                  rbg ?= CL_HTMLB_MANAGER=>GET_DATA( request = request id = 'radio_id' name = 'radioButtonGroup' ).
    %>
    Here rbg->selection will have the selected radiobutton.
    <i>*Reward each useful answer</i>
    Raja T

  • How to move the "back" button to the top ?

    Hi there,
    I had some sub-menus and iDVD auto generate the "FORWARD" and "BACKWARD" buttons in the shape of a triangle. Problem is this buttons are alwayd at the bottom and I do not seem to be able to move the buttons around.
    Any tips on how to move these buttons to other places ?
    Thanks

    Old Toad wrote:
    You can't move them.  Those are hard coded into the themes.
    OT
    Thanks OT ... been trying for hours to move them !!

  • How to move multiple components into a Tab Component and still keep layout?

    I have created a Combination Chart with multiple combo boxes and a slider on my Xcelsius Canvas.  Now, I realize that I want to put all of this into a Tab Set Component.  How can I move everything into this new Tab Component without messing up all the layout and alignment I have done on all my components already?  I tried shift-selecting everything and doing a drag --> drop into the Tab Canvas but they just all stack on top of each other.
    Can this be done?  Would it be wiser to start a new Xcelsius document, place a Tab Set Component on the canvas and then copy --> paste from the original document into the new one? I'm reluctant to do this though (even within the same document) because it forces all components to be renamed back to their defaults such as Chart 1, Combo Box 1, etc etc.
    Edit:
    Bolded my biggest concern on this topic, can components be copy/pasted or cut/pasted and still retain their original name?

    i think this scenario would work fine for you
    choose all the components you want to move from the "Object Browser"
    you can show the Object Browser from the View Menu
    after you select them all, you can drag them to your Tab component
    or you can make them as a group, so it will be easy to move them as the same layout they have.
    to make them as one group
    select them all, go to format menu, and select Group
    now you have all of them as one item, move them to the tab and then you can ungroup them the same way
    good luck
    Amr

  • How to move the UIs in layout?

    Hi everyone,
    In NetWeaver Developer Studio I have the Views which under a Web dynpro. I want to move the UIs in the screen on right clicking the view  and choosing 'edit'. But nothing happened. I can't do anything in the 'layout' . So could anyone tell me how to working on the UIs in layout?
    Thanks!

    Hi wuyia,
                What is the version of your NWDS?
    If I understood your problem, you are trying to arrange the UI Elements in layout but not able to do that.
    If you open the layout tab then in the outline view (downside left most), you can select UI elements and move them. For better arrangement, set the layout property of the RootUIElementContainer   to GridLayout.
    Regards,
    Siva

  • How to dynamically add button to a movie/stage?

    I am using Flex Developer and I am designing a Flash Lite app
    which uses AS2. However I cant find anyway of adding a control such
    as a button to the stage from code. Do I need to buy a tool to do
    that or can I add controls/containers from code?
    E.g. in AS3 you create the button object then do an
    addChild(button) and it adds.
    Any sample docs apprecietd..

    You would create a movie clip button and from your library
    make sure the linkage identifier is set then call a function in
    your action script to attach the button(s) to the stage, the code
    should look something like such:

  • Move Home button

    OK the new FF 4.x has some changes that DRAMATICALLY reduce usability. This post deals with one of those changes that may seem rather small but is not to many users. Please tell me how to move the home button back to the left side of the address bar where it logically belongs with the other navigation button (forward/back). Whoever thought it would be good to move that must have been smoking crack. This simple feature is one of the things that made FF superior to IE. I REALLY wish FF would quit trying to emulate IE constantly and stay on track of actually being a better browser. Please do not respond with the typical "give it a chance you will like it once you get sued to it", because I won't. It is 100% absurd and illogical to have the home button way over on the right side of my browser when all of the other navigation is on the left. Please tell me how to move it back to where it belongs.

    Open the Customize window via "View > Toolbars > Customize" or via "Firefox > Options > Toolbar Layout"<br />
    Drag the Home button from its current position at the right to the left end of the location bar.
    See:
    * http://kb.mozillazine.org/Toolbar_customization

  • How to add multiple button in a column of a table in sapui5?

    Hi Experts,
         I have a requirement i have list of orders in a table and i want to place two buttons in a column for approval and reject,
    if it approved i want to display approved as a text.
    i tried like this i place two buttons in matrix layout and i write a case statement i tried to return but its not displaying the layout.
    Please help me.
    Thanks & Regards
    chittibabu.

    Hi,
    You can't add a layout to the text property of a textfield, so this won't work.
    A better approach would be something like this:
    oTable.addColumn(new sap.ui.table.Column({
      label: new sap.ui.commons.Label({text: "Confirmation"}),
      template: new sap.ui.layout.HorizontalLayout({
        content : [
          new sap.ui.commons.TextView({
            text: "Confirmed",
            textAlign: sap.ui.core.TextAlign.Left,
            visible : ...
          new sap.ui.commons.Button({
            text : Approve,
            press : doApprove,
            visible : ...
          new sap.ui.commons.Button({
            text : "Reject",
            press : doReject,
            visible : ...
    Simply place all needed elements inside the layout, and based on the 'visible' property, you either show both buttons, or the textview.
    I'll leave it as an exercise to you on how you should actually handle the visible state for the TextView and Buttons (hint: use model binding)

  • Photoshop elements 8 for Mac - how to move photos (events) from iphoto to pse

    I have figured out how to move one  photo over through opening a file.  But I can't move a full event or album from iphoto.  Ive tried going to bridge but when i click on the iphoto folder, it takes me into my iphoto and I'm not sure what do then, no buttons or anything that seems to connect to PSE.  Any help would be appreciated!  I wish Adobe supported this product better for Mac users.  Maybe they read these discussions?

    Hi,
    Are you opening iPhoto files from within Photoshop Elements? You can open all the files in an iPhoto event into PSE8 through a single click.
    In Photoshop Elements, go to File menu > Open. In the browser window that appears, click Photos under Media in the sidebar. Now, you should be able to see iPhoto with all its events. When you click on an event and "Open" it, you should get all the photos of that event in the project bin.
    Is this the problem being asked?
    Thanks.

  • How can i use Button in BEx  7.0

    Dear Folks,
    Could you help me please ..
    In BI 7.0, for BEx analyzer i see we can use button, combo box, analysis grid.
    If i have a requirement like this:
    1. I have sales report, where it has information about sales person.
    2. And i want to filter that report with the sales person that i choose from combo box.
    For that requirement, i tried to :
    1. I Create a query to Sales info-provider for displaying sales.
    2. I Create a query to either to MD Sales person / Sales info-provider in order to get Sales persons data.
    3. I assign point no 1 to Analysis Grid.
    4. I assign point no 2 to Combo box.
    My questions are:
    a. Is my techniques correct ??
    b. How can i use button to execute filter into the corresponding report ???
    c. Is there any tutorial regarding this ?? Could you share it to me please ..
    Really need your guidances..
    regards,
    Niel..

    Hi Niel,
    You can use the method you specified.
    In Bex Analyzer you have design mode where you can have the following items Button, Analysis Grid and Combo box.
    To work with the button you need to use the Command Wizard which consists of pre-defined functions, out of those select the one which suits your requirement and supply the parameters. As it is done thorugh a Wizard it would be easy to do.
    Also,
    The Button Name displays the name of the button, which is generated automatically and is unique. This name is used on the BEx Analyzer Design Toolbar menu to refer to a particular instance of the button.
    · Range u2013 Manipulate coordinates for a cell or cells in this field to move or resize the button.
    · Button Text - The text (caption) you want to display on the button. You can use this to describe the command the button executes.
    · Command Range (optional) - Specify a three-column range of cells in the worksheet that contains command parameters. In these cells, you provide the same parameters (Name, Index, and Value) as in the Static Parameters, but in the worksheet these can be variable, changing during
    navigation based on query results or on a value you manually specify.
    Button in Bex analyzer
    Regards,
    Neelesh Jain.

  • My scrollbar unexpectedly has moved to the left side of the screen (only in Firefox), and I don't know how to move it back

    my scrollbar has unexpected moved to the left side of the screen in stead of the right side, and I don't know how to move it back. This only occurs in Firefox.

    Set the pref layout.scrollbar.side to ''2'' to place the scroll bar at the right side.
    See:
    * http://kb.mozillazine.org/layout.scrollbar.side (default is 0: user interface)

  • How to setup the button inactive in pf-status?

    who can tell me how to setup a button inactive in pf-status so that the button is inactive when the program is running?
    there is a sample of button '&SUM' in PF-STATUS 'STANDARD'(lines 303) of program 'RM07MKON'.

    Hi huanzhiyu,
    In a custom (Z) program you can make PF status buttons and subsequently their OK codes inactive by using the following command:
    SET PF-STATUS 'STANDARD' EXCLUDING '&SUM'.
    And if you need to exclude more than one OK code
    data: itab type sy-ucomm occurs 0,
          wa type sy-ucomm.
    move '&SUM' to wa. append wa to itab.
    move '&ADD' to wa. append wa to itab.
    set pf-status 'STANDARD' excluding itab.
    Hope this helps.
    Regards,
    Aditya

  • How to change the lengths of the layout

    Hi ,
    I am executing one report, output is coming fine but next if i go to print preview for PO number only 9 digits are appearing one digit is missing, actually column is trucated, there in print preview there is one tab called Change Layout, there if i see length of the PO no is 9, so its showing only 9 digits, actually length of the PO no should be 10.in change layout the length is editable i can change from 9 to 10, after that there is a button called copy, then it will show correctly, it works only one time, so each and every time user has to change the length, so can any one suggest how to change that length in the layout permanently, bcos there is no save button there.
    Can any one tell me from where all these lengths are coming which are appearing in change layout.Surely its not coming from the report.

    Hi friend,
    That depends upon the space provided by the ALV column for that variable or the heading size its not based on the data element size.
    If you want to be more clear lust count the space available for each field available at the print preview.
    The details for that are stored in table T180S just see the documentation available for that table.
    And see when the table is getting filled like that so that you will be able to find a solution where and how it is getting populated.
    Use column width optimization for getting the correct output.
    If you have any queries in this please revert back to me i will help you.
    Thanks,
    Sri Hari
    Edited by: srihari.kumar on Jan 5, 2012 4:01 PM

  • How to disable save button on selection screen (1000) run from other report

    Hi Experts,
    Can any one let me know how to disable save button on selection screen (1000) run from other report.
    Say I am running from report R1 which submits report R2, but the save button should be disabled on
    report R2(selection screen 100).
    Thanks in advance.
    Regards
    RP.

    Hi RPReddy16 ,
    Try this:
    DATA :BEGIN OF t_extab occurs 0,
                     fcode like rsmpe-func,
                 END OF t_extab.
    REFRESH T_EXTAB.
    MOVE 'SAVE' TO T_EXTAB-FCODE.
    APPEND T_EXTAB.
    CLEAR T_EXTAB.
    SET PF-STATUS 'STATUS' EXCLUDING T_EXTAB.
    Regards,
    José

Maybe you are looking for