Making a moving bar

I'd like to make a box move back and forth in a bar. I know this sounds vague, but I'll try to draw a picture:
|                   [ ]                 |Now, I want that [ ] to move back and forth a varying speeds as I want to make a game where you have to try to press a button as it is in a specific area, kind of like this:
|        [ ]   |    here    |           |So when the box passes through that area and the player presses a button, they will get a point. Now, my question is, how do I go about to making that? As of now, my idea is very inefficient but I'll explain it anyways.
I'll make several images of this bar and box with the box in a different position each time. Then I'll make a loop with a timer and it'll go through to make the box go one way, switch to another loop and make it go the other way. When the player presses a button, it'll record what number the loop is at (like a for loop for example, and the counter) to determine if it's in the area or not. As the player consecutively hits the area, the timer's increments will be changed.
Now, I assume there's a easier way, but I could be wrong. If there's another way to do this, could someone just explain how to do it? Thank you very much in advanced.

* MovingBar.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.Timer;
import javax.swing.border.*;
public class MovingBar extends JFrame implements ActionListener{
    public MovingBar(){
        setTitle("Moving Bar");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JPanel mainPanel = new JPanel();
        bar = new Bar();
        mainPanel.add(bar);
        getContentPane().add(mainPanel,BorderLayout.CENTER);
        btn.addActionListener(this);
        toolbar.add(btn);
        results.add(label);
        getContentPane().add(results,BorderLayout.NORTH);
        getContentPane().add(toolbar,BorderLayout.SOUTH);
        setSize(500, 130);
        setLocationRelativeTo(null);
        setVisible(true);
        bar.setPosition(0);
        Timer timer = new Timer(1,this);
        timer.start();
    public static void main(String[] args) {
        new MovingBar();
    public void actionPerformed(ActionEvent evt){
        if(evt.getSource() instanceof JButton){
            if( newGame ){
                label.setText("");
                points=0;
                newGame = false;
            if( position>200 && position<300 ){
                if(speed<=11){
                    points++;
                    speed++;
                    label.setText(points+" points     ");
                    if(speed==11){
                        label.setText(points+" points       Game Over");
                        speed = 1;
                        newGame = true;
            }else{
                if(speed<=11){
                    points--;
                    label.setText(points+" points     ");
            return;
        if(rightDirection) position += speed;
        else               position -= speed;
        if( position >480 ) rightDirection=false;
        if( position <0 )   rightDirection=true;
        bar.setPosition(position);
        bar.repaint();
    private boolean rightDirection = true;
    private boolean newGame = true;
    private JPanel toolbar = new JPanel();
    private JPanel results = new JPanel();
    private JButton btn = new JButton("Hit");
    private JLabel label = new JLabel();
    private Bar bar;
    private int position, points;
    private int speed = 1;
* Bar
class Bar extends JPanel {
    public Bar() {
        setPreferredSize(new Dimension(10, 30));
        setBackground(Color.red);
        setBorder(new LineBorder(Color.BLACK));
    public void setPosition(int position){
        setLayout(null);
        setLocation( position, 0 );
}

Similar Messages

  • Moving bars In score

    Anyone else having problems moving bars downward in the score window. It seems they only go up even when you grab and pull them down. I've set the max limit in score preferences. Perhaps just another score bugger in 8.01.

    Hello Pianoman,
    I read your problem. If you use the lay out tool their should be no problem moving bars downwards. But there are many bugs in the score set window.
    Do you know why the scale function does not apear when you open it for the second time?? Or why you can't divide the brackets in the score after 28 tracks?
    Can you help me with that?
    Harold

  • Stuck on moving bar and black screen?

    Hi, I have a Toshiba Satellite A300 Series. Windows Vista. My laptop was working perfectly fine last night and when I woke up this morning, I turned it on and it was stuck on the Windows Corporation where the green bar is moving from left to right. I tried doing pressing F8 for safe mode and it went pass through the moving bar but then the screen turned black and all I can move is the cursor. I left it there for good hours just to see if it'll work but it stayed like that. I also tried start up repair and it said if the start up repair fixed the problem, windows should start normally. Then I clicked finish, but it still did the same, still stuck on the moving bar. It showed me a code 0x0 after the start up repair if that will help?
    Any suggestions? Greatly appreciated! Thank you!

    Try the solutions in this article.
    What can I do if my Windows 7 or Windows Vista laptop won't start?
    - Peter

  • [svn:osmf:] 13116: Making the control bar's 'stop' button optional ( and toggled off by default).

    Revision: 13116
    Revision: 13116
    Author:   [email protected]
    Date:     2009-12-21 04:50:52 -0800 (Mon, 21 Dec 2009)
    Log Message:
    Making the control bar's 'stop' button optional (and toggled off by default).
    Modified Paths:
        osmf/trunk/apps/samples/framework/WebPlayer/html-template/index.template.html
        osmf/trunk/apps/samples/framework/WebPlayer/src/Configuration.as
        osmf/trunk/apps/samples/framework/WebPlayer/src/WebPlayer.as

    Remember that Arch Arm is a different distribution, but we try to bend the rules and provide limited support for them.  This may or may not be unique to Arch Arm, so you might try asking on their forums as well.

  • Moving Bars and Camera

    I've been a graphic designer for years, but I'm just getting into motion graphics. I want to make a short video bumber with multiple bars moving through 3D space, very similar to this:
    http://www.youtube.com/watch?v=LOa2iylnHtA
    I have read the now archived post with a similar question (http://discussions.apple.com/thread.jspa?threadID=2548415&tstart=225) but didn't really get anything from it.
    How would I go about doing this?

    Your best option is to make several lines. One for each leg of the animation. Lines and Paint Strokes are 2D elements which means they only have X and Y position for their control points.
    I've done a design very close to this and that's how it was accomplished. You can create one line, adjust it's anchor point to one end and then duplicate it and arrange it in 3D space so that it appears to be on solid line. The animation can be achieved with a Shape/Write On behavior for each line. The camera animation can be done with a Move, Motion Path behavior or just keyframes if you prefer.
    Andy

  • Facebook posting making new multiple bars on left panel

    Everytime I post an album to facebook a new facebook icon bar on left panel is created. Is this correct? The bar has the facebook icon as well as arrow to expand with only one album listed under it.  I cannot imagine having endless bars for facebook as I upload albums.  How do I correct this path.
    Also it doesn't show a wall post place as I saw on a tutorial. there is only an option to amke albums.  What if I want to post a single photo to my wall?

    How are you adding the new albums?  You should just right-click on the existing Facebook icon bar and choose Create Collection - then you get a dialog like this, where you can create a new album or link to an existing one.

  • Moving bars to conceal/reveal text - how?

    Hello
    Using Flash Prof 8...Couple of major things that I have no
    idea how to do...if you go to
    http://www.enhancedwireless.net/Technology/keyMechtest.shtml
    and press play on the "ODMA" demo graphic (it's a work in
    progress not complete), you'll see the vise-like bars closing and
    shutting - I need for the text to be hidden then revealed as the
    bars move across the text...how do I do this? I'm newish to Flash
    so as detailed (code whatever) as you could be, would be
    appreciated greatly. Thanks in advance for your time.
    And if you let the whole clip play to end (under :50) it
    jumps back to the beginning, which I want, but you'll notice that
    the "play_mc" button pops up then immediately disappears...I need
    it to stay on as at the beginning.
    On the last frame (actions layer) of my main mc called
    keyMech_mc is this code:
    gotoAndStop("Scene 1", 1);
    _root.play_mc._alpha = 100;
    My play button which is actually a movie clip, play_mc, has
    various alpha code for it on my main timeline on actions layer
    first frame as follows:
    _root.KeyMech_mc.stop();
    play_mc.onRollOver = function(){
    this.gotoAndStop("over");
    play_mc.onRollOut = function(){
    this.gotoAndStop("out");
    play_mc.onRelease = function(){
    this.onEnterFrame = function(){
    so = this;
    rate = 5; // choose number between 1 and 100
    newAlpha = so._alpha - rate; // subtract rate from current
    visibility
    if(newAlpha > 0) { // continue fade
    so._alpha = newAlpha; // set newVolume to decrease visibility
    }else if(newAlpha == 0){
    so._alpha = 0;
    ===========
    Just wanted you to have all the info possible re: this
    play_mc so I can get it to stay back up at the end of the movie...
    And I'm really stumped as to how to do the revealing bars
    thing.
    Thanks for any help!
    KB

    OK got the bars to work, courtesy a good suggestion from some
    one (just put a white rectangle behind the lines) - but what about
    this play button reappearing?
    KB

  • Making a moving/running backround

    Hey guys, I am a beginner in Adobe After Effects, and I just finished my first intro for all my videos. However, my background just sits there. Is there any way to make the dots move like a conveyor belt moving towards the back?
    here is my background
    Thanks,
    TsterT

    Ok, here's a step in the right direction, but beware that
    without a fundamental knowledge of after effects some of this may seem a bit complex:
    Looking at what you've created, if I wanted to translate that to the type of animation that you want, I would first create a dot comp.  That's a comp that just has your source dots in it.  Could be done any number of ways: photoshop, illustrator, shape layers or masks inside of AE, whatever.  But these dots are laying flat, undistorted in any way.
    Then I would take that comp into another comp, and to get the horizontal motion I would try the effect: stylize->motion tile.  Adjust the output width property so that your dots now tile horizontally, and you are able to animate the x-position for your dots comp.
    Then I would put this animated dots comp into a 3rd, master comp, where I would first try something like a distort->mesh warp to get the shape you are after (play with the settings, grab the warp points on the stage and move them around...my thought is that the less rows and columns you have the cleaner the distortion will be).  I would also play with something like corner pin (this will create a different, but possibly interesting distortion), and I might even try the puppet tool to shape it, although the puppet tool needs to mature a little bit before it can cleanly and efficiently handle something like this.
    In doing this, you will have your dots layer animating, and the distort will take care of the custom shape you want.  To get that reflection you may want to take that master comp into a FOURTH comp, duplicate it, set the y scale to a -100% (or whatever) and then try effect->transition->linear wipe and play with the settings in there to get that soft falloff.
    This is not the only way it can be done, and it may not even work exactly as you'd like, but again if I were doing it, this is where I would start.
    I hope that helps

  • Making a search bar adjust to the size of the screen

    I need to make my search bar static but one side adjust to the browsers width. Just like the one on YouTube. Is their any way to easily achive this? If not how could i just make my search bar remain centered on my screen?
    (I am using bootstrap 3 for my site)
    Edit fiddle - JSFiddle

    <!doctype html>
    <html>
    <head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta charset="utf-8">
    <title>Untitled Document</title>
    <link rel="stylesheet" type="text/css" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" />
    <link rel="stylesheet" type="text/css" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap-theme.min.css" />
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script type="text/javascript" src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
    <style>
    </style>
    </head>
    <body>
    <div class="container">
        <div class="row">
            <div class="col-xs-6">
                <form>
                    <div class="input-group">
                        <input type="text" class="form-control " placeholder="Text input">
                        <span class="input-group-btn">
                        <button type="submit" class="btn btn-search">Search</button>
                        </span> </div>
                </form>
            </div>
        </div>
    </div>
    </body>
    </html>

  • Making a scroll bar

    In CS5, I want to place content on a frame and give the user the ability to scroll through it all. I know no AS3 and have been using code snippets. How can I use code snippets or some other way to do this?
    Thanks!!!

    You can either drag it in from the components library or load it in dynamically.  If uou go dynamically you still need to have it in the regular library, which you can achieve by dragging one onto the stage and then deleting it from the stage... you'll find it in your library after you drag it onto the stage.

  • Making a moving shape

    hi, i am looking to see how to paint a circle on a panel and then make it move up and down with buttons.
    can anyone help me? could someone post a simple program of what i am looking for please?
    thank you

    hi,Hello
    i am looking to see how to paint a circleGraphics.drawOval (int x, int y, int width, int height)
    on a panelOverride paintComponent (Graphics g) and don't forget to call super.paintComponent (g).
    and then make it move up and down with buttons.addActionListener (...) to the buttons and change the x and y coordinates used by Graphics.drawOval (...). x and y sould be instance fields.
    can anyone help me? could someone post a simple program of what i am looking for please?Posting a program is not help. Do you have a link to the Swing tutorials?
    {color:0000ff}http://java.sun.com/docs/books/tutorial/uiswing/TOC.html{color}
    You'll find all you need (and more) there. Put something together, and come back if you have a specific question to ask.
    {color:0000ff}http://catb.org/~esr/faqs/smart-questions.html
    mindprod.com/jgloss/sscce.html{color}
    To post code, use the code tags -- [code]Your Code[/code]will display asYour CodeOr use the code button above the editing area and paste your code between the tags it generates.
    luck, db

  • Making a Stacked Bar chart Series Dynamic

    in the below example i have 3 series Region 1,2 & 3.. i want these series also to be dyanamic what ive done is used a mysql query using the DISTINCT CLAUSE got all the values of the attribute now depending on how many distinct values i have i need that many Series. n then the values for these Series again needs an invocation of the Mysql query.
    public class StackedBarChartSmple extends Application {
    private void init(Stage primaryStage) {
    Group root = new Group();
    primaryStage.setScene(new Scene(root));
    String[] years = {"2007", "2008", "2009"};
    CategoryAxis xAxis = CategoryAxisBuilder.create()
    .categories(FXCollections.<String>observableArrayList(years)).build();
    NumberAxis yAxis = NumberAxisBuilder.create()
    .label("Units Sold")
    .lowerBound(0.0d)
    .upperBound(10000.0d)
    .tickUnit(1000.0d).build();
    ObservableList<StackedBarChart.Series> barChartData = FXCollections.observableArrayList(
    new StackedBarChart.Series("Region 1", FXCollections.observableArrayList(
    new StackedBarChart.Data(years[0], 567d),
    new StackedBarChart.Data(years[1], 1292d),
    new StackedBarChart.Data(years[2], 1292d)
    new StackedBarChart.Series("Region 2", FXCollections.observableArrayList(
    new StackedBarChart.Data(years[0], 956),
    new StackedBarChart.Data(years[1], 1665),
    new StackedBarChart.Data(years[2], 2559)
    new StackedBarChart.Series("Region 3", FXCollections.observableArrayList(
    new StackedBarChart.Data(years[0], 1154),
    new StackedBarChart.Data(years[1], 1927),
    new StackedBarChart.Data(years[2], 2774)
    StackedBarChart chart = new StackedBarChart(xAxis, yAxis, barChartData, 25.0d);
    root.getChildren().add(chart);
    @Override public void start(Stage primaryStage) throws Exception {
    init(primaryStage);
    primaryStage.show();
    public static void main(String[] args) { launch(args); }
    }

    Hi. Does the following work for you? May be I am missing something.
            ObservableList<StackedBarChart.Series> barChartData = FXCollections.observableArrayList();
            Set<String> regions = new HashSet();  //from database
            for (String region : regions) {
                barChartData.add(
                        new StackedBarChart.Series(region, FXCollections.observableArrayList(
                        new StackedBarChart.Data(years[0], 567d),     //values from db query
                        new StackedBarChart.Data(years[1], 1292d),
                        new StackedBarChart.Data(years[2], 1292d))));
           StackedBarChart chart = new StackedBarChart(xAxis, yAxis, barChartData, 25.0d);

  • Why is there a mysterious moving bar ?

    I have a 5th gen iTouch.  After a sync to nite, I went to listen to a podcast.  There is now a blue box scrolling down row by row. It does not matter if on the home screen, a folder or in my settings.  It's  like the device has a mind of its own.  It does not affect the functionality of the device.
    I tried a reboot and full off , but it's not going away.
    this has not yet affected my iPad which is running the same IOS : 7.1.2

    it was already set for "off"
    i did play with "guided access"  it was activated, now it's not.
    so far the scrolling box is gone.

  • I keep getting window up saying urgent update recommending download, but when i do try, all i get is a blue and white bar moving . i have left it run for hours and nothing happens. what is it?

    i downloaded new FF 2 weeks ago. Since then i keep getting update window coming up every day highly recommending i update but when i try, nothing happens except blue/white moving bar at top of window. i have left it run for hours and no progress, so i close it. The next time I open FF, it appears again and again same happens.
    If there is an urgent update, how urgent is it if I cannot download it.It's worries me that i can,t load it and how it might affect my security.

    It would be a great idea to uninstall Norton - you don't need it and it has a pretty poor reputation for mucking up otherwise healthy Macs.
    Have a look at this User Tip from klaus1: https://discussions.apple.com/docs/DOC-2435
    To uninstall Norton:
    https://support.norton.com/sp/en/us/home/current/solutions/kb20080427024142EN_En dUserProfile_en_us
    Edit: To see whether you actually have Norton installed launch Activity Monitor in the Utilities folder. If it's installed you'll likely see some Norton entries there.
    Also, in System Preferences>Users & Groups or Accounts, depending on OS)>Login Items, it might be listed.

  • LE7:Score Layout:Global Format:Maximum Bars per Line - Line Break Bug!

    Hello
    This problem occurs in Logic Express version 7.
    (I am using MacOS version 10.4.2 on an eMac)
    I am currently compiling and editing a large score for a big band composition consisting of 22 parts:
    Flute 1
    Flute 2
    Clarinet 1
    Clarinet 2
    Alto Sax 1
    Alto Sax 2
    Tenor Sax 1
    Tenor Sax 2
    Baritone Sax
    Trombone 1
    Trombone 2
    Trombone 3
    Trombone 4
    Trumpet 1
    Trumpet 2
    Trumpet 3
    Trumpet 4
    Guitar
    Keyboard
    Electric Bass
    Percussion 1 (Kit)
    Percussion 2 (Aux)
    I am creating the score in a separate file, and I am combining parts into 1 stave each by instrument like this:
    Flute 1 & 2
    Clarinet 1 & 2
    Alto Sax 1 & 2
    Tenor Sax 1 & 2
    Baritone Sax
    Trombone 1 - 4
    Trumpet 1 - 4
    Guitar
    Keyboard (2 staves)
    Bass
    Percussion
    Each instrument, with the exception of keyboard which has 2 staves, consists of one stave, making up systems of twelve staves each. By sizing down each score style to 2,
    I have managed to fit 2 systems onto each page, therefore significantly reducing the amount of paper needed.
    The problem comes when organising the layout of my score,
    in particular, the line breaks. Using layout:global format, I have limited the maximum number of bars per line to 8, both in the page edit and normal score mode.
    I am trying to divide up my score so that there are 8 bars per system. Using the white arrow tool, I am dragging bars up and down in order to achieve this.
    However, when I get 30 odd bars in, I discover a system with 12 bars crammed into it - and even printing it off, it is clear that the system could benefit with less bars; the notation is squashed up together and not very easy to read.
    THIS IS THE ACTUAL PROBLEM:
    So I tried using the white arrow to move the last 4 bars down onto the next system, and a bug occurs where I end up with about 20 bars on the system, oddly distorted, the first few bars of which are squashed up together at the beginning of the line, and the last bar of which is stretched far off the right hand side of the page out of view. Then the next 20 or so bars are no where to be seen (probably far off the right hand side of the page) before the system below.
    If you dont know what I am talking about, I could provide a screenshot if you request.
    I have tried everything to get 8 bars on that particular system; dragging the stretched bar downwards, dragging squashed bars downward, moving bars down 1 by 1, moving bars onto the system above, moving bars away from the system below (to make room for the 4 bars that I want to move from above), adding more bars and dragging them down, but none of these methods have worked. I am either stuck with 12 bars crammed onto one system and 4 bars on the next or an oddly distorted version of the system which cannot possibly be read. Even when I settle with the unsatistactory former, I encounter further problems on subsequent systems below, some systems of which are already distorted.
    All I want is to have 8 bars per system, it should not be too much to ask! The layout:global format:maximum-bars-per-line calculation seems to be redundant, even when I reset the default line breaks - it just does not automatically set 8 bars per line, which it should do. Is there not an option to determine bars individually by number onto their respective lines, without having to use the white arrow graphic layout tool?
    The problem is extremely frustrating, and it is preventing me from completing, presenting and handing in a score for my university music composition.
    I have no other score producing software, and starting it
    from scratch on paper is going to take me weeks, because it consists of 830 12/8 bars in 22 parts, and I need to get it ready by next term!
    Any help would be extremely helpful and much appreciated, especially a patch or a useful way round. It could be related to memory, or hard drive space, as I have experienced similar problems in the past, where my score has been stretched off the page during a time when I have had little disk space...and this is a very large piece of music which might stretch the score capabilities of Logic.
    If so, has anyone got any suggestions?
    Thanks!
    Rory
    eMac   Mac OS X (10.4.2)  
    eMac   Mac OS X (10.4.2)  

    nope just cutting should work.
    here are some things to try:
    1. try assigning a different score style. for the regions. duplicate and then adjust the default ones if necessary.
    2. try creating a new instrument set. in fact delete them and make a new one (use the key command: create instrument set from selected)
    3. it may be a formatting problem so check:
    in global layout constant spacing (try 8 or 9) and proportional spacing (try 45 or so). then try factory defaults.
    4. try copying and pasting the midi into a brand new region and looking at the score for that.
    5. try fiddling with the layout tool drqagging bars up or down.
    normally simply cutting the region of just one object is enough to force a redraw. maybe try it on all of the regions. what happens when you double click on a region?

Maybe you are looking for