Add pause in this code....help!!!!

hi everybody!!!
i'm writing code for up and down speed of song....
for play of song i write this code:
public function playMC(evt:MouseEvent):void
            target= new ByteArray();
            var url:URLRequest = new URLRequest("C://song.mp3");
            mp3Start = new Sound();
            mp3Start.addEventListener(Event.COMPLETE, complete);
            mp3Start.load(url);
            position = 0.0;
            rate = 1.0;
            sound = new Sound();
            sound.addEventListener(SampleDataEvent.SAMPLE_DATA, sampleData);
public function complete(event:Event):void
            channel = sound.play();
this code is good for only play and stop song....i want add pause song....how to do??
help me please!!!!

hi!!!
now i have another small problem...
i want add one timer ans progressBar...
for add time i write this:
public function getCurrentSong(evt:TimerEvent):void
                              currentSong.text = convertTimer(sound.position);
but don't go same time!!!!
and how to use the sliderBar or progressBar in this player???
help me please!!!!

Similar Messages

  • How can I add a "Was this Topic Helpful" statement

    RoboHelp 11
    I'm sorry if this has come up and I wasn't able to find the anser, but is there any way to add a statement: Was this topic helpful? Yes No to the end of a topic. It seems many Help programs, including your own, have this capability. If this does not exist within RoboHelp 11, how can it be added? (And, how is it compiled.)
    This may be a very naive question, but I'm grateful for any help.
    Thanks!

    First off – you do realize that this is a user-to-user forum, right? There’s no “including your own help” Adobe people here that you’re talking to ;>)
    Try checking out these threads & links - http://www.grainge.org/pages/snippets/mailto.htm
    http://forums.adobe.com/message/2238475#2238475
    http://forums.adobe.com/message/1973043#1973043

  • Add timer to this code

    Hi all.
    I just wondering how to make this code to have timer so that it will show me the latest data from database.
        private void dbConnect() {
            try {
                Class.forName("org.postgresql.Driver");
                String url = "jdbc:postgresql://localhost:5432/task";
                Connection conn = DriverManager.getConnection(url,"tele","tiny");
                Statement stmt = conn.createStatement();
                ResultSet rs1;
                ResultSet rs2;
                ResultSet rs3;
      //DB query utk RS1
                rs1 = stmt.executeQuery("SELECT * FROM public.mda100_results WHERE public.mda100_results.nodeid = 1 " +
                        "ORDER BY public.mda100_results.result_time DESC Limit 1");
                while ( rs1.next() ) {
                    int itempN1 = rs1.getInt("temp");
                    String tempN1 = rs1.getString("temp");
                    String ligN1 = rs1.getString("light");
                    n1Temp.setText(tempN1);
                    n1Lig.setText(ligN1);
                    if (itempN1 <= 15 || itempN1 >= 21){
                     jLabel7.setForeground(Color.RED);
                    }else{
                     jLabel7.setForeground(Color.gray);
      //DB query utk RS2
                rs2 = stmt.executeQuery("SELECT * FROM public.mda100_results WHERE public.mda100_results.nodeid = 2 " +
                        "ORDER BY public.mda100_results.result_time DESC Limit 1");
                while ( rs2.next() ) {
                    int itempN2 = rs2.getInt("temp");
                    String tempN2 = rs2.getString("temp");
                    String ligN2 = rs2.getString("light");
                    n2Temp.setText(tempN2);
                    n2Lig.setText(ligN2);
                    if (itempN2 <= 15 || itempN2 >= 21){
                     jLabel7.setForeground(Color.RED);
                }else{
                     jLabel7.setForeground(Color.gray);
      //DB query utk RS3
                rs3 = stmt.executeQuery("SELECT * FROM public.mda100_results WHERE public.mda100_results.nodeid = 3 " +
                        "ORDER BY public.mda100_results.result_time DESC Limit 1");
                while ( rs3.next() ) {
                    int itempN3 = rs3.getInt("temp");
                    String tempN3 = rs3.getString("temp");
                    String ligN3 = rs3.getString("light");
                    n3Temp.setText(tempN3);
                    n3Lig.setText(ligN3);
                    if (itempN3 <= 15 || itempN3 >= 21){
                     jLabel7.setForeground(Color.RED);
                }else{
                     jLabel7.setForeground(Color.gray);
                rs1.refreshRow();
                rs2.refreshRow();
                rs3.refreshRow();
                conn.close();
            } catch (Exception e) {
        }another one, how to use refreshRow()? Is that correct in my code?
    anybody can help me? i have tried to make my own timer but not successful.
    TQ

    You'll probably want to use a javax.swing.Timer, to use it go to the Swing Tutorial and read.

  • How could i add attachment in this code

    i have code when_button_pressed (send email) but i want attach file
    how can i do this ?
    this is the code
    -------only for outlook
    --- THIS IS OLE CODE FOR MORE INFO. SEE HELP .
    DECLARE
    --PROCEDURE SendMail
    objOutlook OLE2.OBJ_TYPE;
    objMail OLE2.OBJ_TYPE;
    objArg OLE2.LIST_TYPE;
    vfilename varchar2(300);
    BEGIN
    objOutlook := OLE2.CREATE_OBJ('OUTLOOK.Application');
    objarg := OLE2.CREATE_ARGLIST;
    OLE2.ADD_ARG(objarg,0);
    objMail := OLE2.INVOKE_OBJ(objOutlook,'CreateItem',objarg);
    OLE2.DESTROY_ARGLIST(objarg);
    OLE2.SET_PROPERTY(objmail,'To',:TO);
    OLE2.SET_PROPERTY(objmail,'Subject',:SUBJECT);
    OLE2.SET_PROPERTY(objmail,'Body',:BODY);
    OLE2.INVOKE(objmail,'Send');
    OLE2.INVOKE(objmail,'Display');
    OLE2.RELEASE_OBJ(objmail);
    OLE2.RELEASE_OBJ(objOutlook);
    Message('Your mail sent successfully..............');
    Message('Your mail sent successfully..............');
    exception
    when others then
    message(sqlerrm);message(sqlerrm);
    END;
    thanks.

    Hello,
    Try this:
    OLE2.SET_PROPERTY(objmail,'Attachments','c:\file.txt');Francois

  • How to add stop button in this code AS3

    Hello, im new to this adobe flash AS3. i want to create a simple play sound using flash + XML file for wbesite., this is my code
    all this code are working greate.. but i have the problem to add stop_btn code my playlist button already have pause, prevous and next and play.. only stop button i have fail to create. this is my code
    var my_songs:XMLList;
    var my_total:Number;
    var my_sound:Sound;
    var my_channel:SoundChannel;
    var current_song:Number = 0;
    var song_position:Number;
    var song_paused:Boolean;
    var myXMLLoader:URLLoader = new URLLoader();
    myXMLLoader.load(new URLRequest("playlist2.xml"));
    myXMLLoader.addEventListener(Event.COMPLETE, processXML);
    function processXML (e:Event):void{
    var myXML:XML = new XML(e.target.data);
    my_songs = myXML.SONG;
    my_total = my_songs.length();
    function playSong(mySong:Number):void{
    var myTitle = my_songs[mySong].@TITLE;
    var myArtist = my_songs[mySong].@ARTIST;
    var myURL = my_songs[mySong].@URL;
    title_txt.text = myTitle;
    artist_txt.text = myArtist;
    if (my_channel){
    my_channel.stop();
    my_sound = new Sound();
    my_sound.load(new URLRequest(myURL));
    my_channel = my_sound.play();
    my_channel.addEventListener(Event.SOUND_COMPLETE, onNext);
    next_btn.addEventListener(MouseEvent.CLICK, onNext);
    function onNext(e:Event):void{
    current_song++;
    if (current_song>=my_total){
    current_song=0;
    playSong(current_song);
    prev_btn.addEventListener(MouseEvent.CLICK, onPrev);
    function onPrev(e:MouseEvent):void{
    current_song--;
    if (current_song<0){
    current_song = my_total-1;
    playSong(current_song);
    pause_btn.addEventListener(MouseEvent.CLICK, onPause);
    function onPause(e:MouseEvent):void{
    if (my_channel){
    song_position = my_channel.position;
    my_channel.stop();
    song_paused=true;
    play_btn.addEventListener(MouseEvent.CLICK, onPlay);
    function onPlay(e:MouseEvent):void{
    if (song_paused){
    my_channel = my_sound.play(song_position);
    song_paused=false;
    } else if (!my_channel){
    playSong(current_song);
    can some one help with me... thank you

    stop_btn.addEventListener(MouseEvent.CLICK, onStop);
    function onStop(e:MouseEvent):void{
       if (my_channel){
          my_channel.stop();

  • Can you help me with the WHERE clause? Any issue with this code block?

    Hi,
    I am looking for blogs or any document on how to implement a Lookup during data loads in BW.
    The problem is that all those that I find on this site are mostly about u201CLookup in XIu201D
    I have read bits and hints on different postings on this site and this is the best I could do for the scenario shown below:
    I need to add the Chars: Char1, Char2, Char3 to CubeX
    so that I can display the data for these 3 Chars in a report.
    Char1 and Char2 are filled in ODS12 and Char3 is filled in Cube3.
    Can you help me write a routine so that while loading data to CubeX, it will read Char1, Char2, Char3 from ODS12 and Cube3; and make them available in CubeX?
    This is my attempt so far:   continue:
    u201C----
    select /bic/Char1 from /bic/ODS12
    select /bic/Char2 from /bic/ODS12
    select /bic/Char3 from /bic/Cube3
    into result
    WHERE u2026u2026u2026u2026u2026u2026u2026u2026u2026u2026u2026u2026u2026u2026u2026u2026
    and objvers = 'A' .        
    end select.
    u201C----
    1. What should be my WHERE clause?
    2. In the select statement, by studying samples on this where should there be an u201CMu201D in front of the ODS? e.g. select /bic/Char1 from /bic/MODS12
    If so, what is the significance and the other options?
    3. Should this code be in the Start routing of CubeX? Or any other possible location? Also, in the start routine does it matter where within the start routine this code needs to be placed?
    4. Can you please fix this code and add any lines I may be missing?
    Is what I am looking to do refer to as u201Cdoing a lookupu201D?
    Thanks

    ok

  • Please someone help me with this code..

    hi, i have a big problem trying to figure out how to do this, i get this code somewhere in the net, so it's not me who code this, that's why i got this problem.
    this is a MIDlet games, something like gallaga. i like to add some features like the UP and DOWN movement and also i have a problem with his "fire", i can only shoot once after the fire image is gone in the screen, what i liked to have is even i pressed the fire button and press it again the fire will not gone, what i mean continues fire if i pressed everytime the fire button.
    i will post the code here so you can see it and give me some feedback. i need this badly, hoping to all you guys! thanks..for this forum.
    ----CODE BEGIN ---------------
    import java.io.IOException;
    import java.io.PrintStream;
    import java.util.Random;
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.MIDlet;
    import javax.microedition.midlet.MIDletStateChangeException;
    import javax.microedition.rms.RecordStore;
    import javax.microedition.rms.RecordStoreException;
    public class MobileGalaga extends MIDlet
    implements CommandListener, Runnable
    class ScoreScreen extends Canvas
    public void paint(Graphics g)
    g.setColor(0xffffff);
    g.fillRect(0, 0, MobileGalaga.WIDTH, MobileGalaga.HEIGHT);
    g.setColor(0x160291);
    g.setFont(MobileGalaga.fs);
    g.drawString("Help", MobileGalaga.CENTERW, 2, 17);
    g.setColor(0);
    g.drawString("Use left/right and fire", MobileGalaga.CENTERW, 20, 17);
    g.drawString("to destory the", MobileGalaga.CENTERW, 30, 17);
    g.drawString("incoming alien MobileGalaga", MobileGalaga.CENTERW, 40, 17);
    public void keyPressed(int i)
    int j = getGameAction(i);
    if(j == 8)
    display.setCurrent(titlescreen);
    ScoreScreen()
    class TitleScreen extends Canvas
    public void paint(Graphics g)
    g.setColor(0xffffff);
    g.fillRect(0, 0, MobileGalaga.WIDTH, MobileGalaga.HEIGHT);
    g.drawImage(MobileGalaga.logoimg, MobileGalaga.CENTERW, 15, 17);
    g.setColor(0);
    g.setFont(MobileGalaga.fs);
    g.drawString("Press 5 to", MobileGalaga.CENTERW, 43, 17);
    g.drawString("see help", MobileGalaga.CENTERW, 53, 17);
    public void keyPressed(int i)
    int j = getGameAction(i);
    if(j == 8)
    display.setCurrent(scorescreen);
    TitleScreen()
    class MainScreen extends Canvas
    public void paint(Graphics g)
    offg.setColor(0xffffff);
    offg.fillRect(0, 0, MobileGalaga.WIDTH, MobileGalaga.HEIGHT);
    for(int i = 0; i < MobileGalaga.slen; i++)
    if(!MobileGalaga.dead)
    offg.drawImage(MobileGalaga.alienimg[MobileGalaga.frame[i]], MobileGalaga.x[i], MobileGalaga.y[i], 17);
    if(!MobileGalaga.playerdead)
    offg.drawImage(MobileGalaga.playerimg, MobileGalaga.px, MobileGalaga.py, 17);
    } else
    if(MobileGalaga.explodeframe < 3)
    offg.drawImage(MobileGalaga.explosionimg[MobileGalaga.explodeframe], MobileGalaga.px, MobileGalaga.py, 17);
    MobileGalaga.explodeframe++;
    if(!MobileGalaga.gameover)
    MobileGalaga.playerpause++;
    if(MobileGalaga.playerpause < 50)
    MobileGalaga.playerpause++;
    } else
    MobileGalaga.playerdead = false;
    MobileGalaga.playerpause = 0;
    MobileGalaga.px = MobileGalaga.CENTERW;
    offg.setColor(0);
    offg.drawString(MobileGalaga.scorestr, MobileGalaga.WIDTH, 0, 24);
    offg.drawImage(MobileGalaga.playerimg, 0, 0, 20);
    offg.drawString(MobileGalaga.lives + "", 12, 0, 20);
    if(MobileGalaga.laser)
    offg.drawLine(MobileGalaga.laserx, MobileGalaga.lasery, MobileGalaga.laserx, MobileGalaga.lasery + 4);
    if(MobileGalaga.showscores)
    for(int j = 0; j < 5; j++)
    if(j == MobileGalaga.rank)
    offg.setColor(0xff0000);
    else
    offg.setColor(0);
    offg.drawString((j + 1) + " .... " + getScoreStr(MobileGalaga.highscore[j]), MobileGalaga.CENTERW, 20 + j * 10, 17);
    if(MobileGalaga.showmessage)
    offg.setColor(0xff0000);
    offg.drawString(MobileGalaga.msg, MobileGalaga.CENTERW, MobileGalaga.CENTERH, 17);
    MobileGalaga.messagepause++;
    if(MobileGalaga.messagepause > 20)
    MobileGalaga.showmessage = false;
    MobileGalaga.messagepause = 0;
    if(MobileGalaga.gameover)
    MobileGalaga.showscores = true;
    else
    if(MobileGalaga.wavecomplete)
    initWave();
    g.drawImage(offimg, 0, 0, 20);
    public void keyPressed(int i)
    int j = getGameAction(i);
    if(j == 2)
    MobileGalaga.playerLeft = true;
    else
    if(j == 5)
    MobileGalaga.playerRight = true;
    else
    if(j == 8)
    fireLaser();
    public void keyReleased(int i)
    int j = getGameAction(i);
    if(j == 2)
    MobileGalaga.playerLeft = false;
    else
    if(j == 5)
    MobileGalaga.playerRight = false;
    private Image offimg;
    private Graphics offg;
    public MainScreen()
    offimg = Image.createImage(getWidth(), getHeight());
    offg = offimg.getGraphics();
    offg.setFont(MobileGalaga.fs);
    public MobileGalaga()
    rand = new Random();
    display = Display.getDisplay(this);
    mainscreen = new MainScreen();
    titlescreen = new TitleScreen();
    scorescreen = new ScoreScreen();
    WIDTH = mainscreen.getWidth();
    HEIGHT = mainscreen.getHeight();
    CENTERW = WIDTH / 2;
    CENTERH = HEIGHT / 2;
    exitCommand = new Command("Exit", 7, 1);
    playCommand = new Command("Play", 1, 1);
    quitCommand = new Command("Quit", 1, 1);
    againCommand = new Command("Again", 1, 1);
    nullCommand = new Command("", 1, 1);
    try
    alienimg[0] = Image.createImage("/alien1.png");
    alienimg[1] = Image.createImage("/alien2.png");
    explosionimg[0] = Image.createImage("/explosion1.png");
    explosionimg[1] = Image.createImage("/explosion2.png");
    explosionimg[2] = Image.createImage("/explosion3.png");
    playerimg = Image.createImage("/player.png");
    logoimg = Image.createImage("/logo.png");
    catch(IOException ioexception)
    db("Couldn't get images!");
    imgW = alienimg[0].getWidth();
    imgH = alienimg[0].getHeight();
    edgeH = imgW / 2;
    edgeV = imgH / 2;
    pimgW = playerimg.getWidth();
    pimgH = playerimg.getHeight();
    pedgeH = pimgW / 2;
    pedgeV = pimgH / 2;
    highscore = getHighScores();
    public void run()
    while(runner)
    rp();
    updatePos();
    try
    MobileGalaga _tmp = this;
    Thread.sleep(75L);
    catch(InterruptedException interruptedexception)
    db("interrupted");
    runner = false;
    MobileGalaga _tmp1 = this;
    Thread.yield();
    public void startApp()
    throws MIDletStateChangeException
    display.setCurrent(titlescreen);
    addBeginCommands(titlescreen, false);
    addBeginCommands(scorescreen, false);
    addPlayCommands(mainscreen, false);
    public void pauseApp()
    public void destroyApp(boolean flag)
    runner = false;
    th = null;
    private void rp()
    mainscreen.repaint();
    private void startGame()
    initGame();
    if(th == null)
    th = new Thread(this);
    runner = true;
    th.start();
    private void initGame()
    px = CENTERW;
    py = HEIGHT - pedgeV - pimgH;
    packcount = 0;
    lives = 3;
    score = 0;
    scorestr = "000000";
    rank = -1;
    difficulty = 400;
    wave = 1;
    initWave();
    private void initWave()
    for(int i = 0; i < slen; i++)
    frame[i] = i % 2;
    x[i] = packX[i] = sposX[i];
    y[i] = packY[i] = sposY[i];
    dx[i] = packdx = alien_dx_right;
    dy[i] = packdy = alien_dy_right;
    dxcount[i] = dycount[i] = 0;
    pmode[i] = 0;
    flying[i] = false;
    dead[i] = false;
    playerLeft = false;
    playerRight = false;
    laser = false;
    playerdead = false;
    showscores = false;
    showmessage = false;
    gameover = false;
    wavecomplete = false;
    playerpause = 0;
    messagepause = 0;
    killed = 0;
    private void updatePos()
    if(playerLeft)
    updatePlayerPos(-2);
    else
    if(playerRight)
    updatePlayerPos(2);
    fly = Math.abs(rand.nextInt() % difficulty);
    if(fly < slen && !flying[fly] && !dead[fly])
    if(x[fly] < CENTERW)
    setDX(fly, alien_dx_flyright, 2);
    setDY(fly, alien_dy_flyright, 2);
    } else
    setDX(fly, alien_dx_flyleft, 2);
    setDY(fly, alien_dy_flyleft, 2);
    flying[fly] = true;
    for(int i = 0; i < slen; i++)
    if(!dead[i])
    if(!flying[i])
    if(x[i] + edgeH + dx[i][dxcount[i]] > WIDTH)
    changePackDir(alien_dx_left, alien_dy_left);
    if((x[i] - edgeH) + dx[i][dxcount[i]] < 0)
    changePackDir(alien_dx_right, alien_dy_right);
    } else
    if(y[i] + edgeV + dy[i][dycount[i]] > HEIGHT)
    x[i] = packX[i];
    y[i] = packY[i];
    flying[i] = false;
    setDX(i, packdx, 0);
    setDY(i, packdy, 0);
    if(!playerdead && y[i] <= py + pedgeV && y[i] >= py - pedgeV && x[i] <= px + pedgeH && x[i] >= px - pedgeH)
    playerHit();
    if(laser && lasery <= y[i] + edgeV && lasery >= y[i] - edgeV && laserx <= x[i] + edgeH && laserx >= x[i] - edgeH)
    alienHit(i);
    for(int j = 0; j < slen; j++)
    if(!dead[j])
    if(framecount == 3)
    frame[j] = frame[j] + 1 < 2 ? 1 : 0;
    lastx = x[j];
    lasty = y[j];
    x[j] += dx[j][dxcount[j]];
    y[j] += dy[j][dycount[j]];
    if(pmode[j] == 0)
    dxcount[j] = dxcount[j] + 1 < dx[j].length ? dxcount[j] + 1 : 0;
    dycount[j] = dycount[j] + 1 < dy[j].length ? dycount[j] + 1 : 0;
    } else
    if(pmode[j] == 2)
    dxcount[j] = dxcount[j] + 1 < dx[j].length ? dxcount[j] + 1 : dxcount[j];
    dycount[j] = dycount[j] + 1 < dy[j].length ? dycount[j] + 1 : dycount[j];
    packX[j] += packdx[packcount];
    packY[j] += packdy[packcount];
    packcount = packcount + 1 < packlen ? packcount + 1 : 0;
    framecount = framecount + 1 < 4 ? framecount + 1 : 0;
    if(laser)
    lasery -= 6;
    if(lasery < 0)
    laser = false;
    private void setDX(int i, int ai[], int j)
    if(i == -1)
    for(int k = 0; k < slen; k++)
    if(!flying[k])
    dx[k] = ai;
    dxcount[k] = 0;
    pmode[k] = j;
    } else
    dx[i] = ai;
    dxcount[i] = 0;
    pmode[i] = j;
    private void setDY(int i, int ai[], int j)
    if(i == -1)
    for(int k = 0; k < slen; k++)
    if(!flying[k])
    dy[k] = ai;
    dycount[k] = 0;
    pmode[k] = j;
    } else
    dy[i] = ai;
    dycount[i] = 0;
    pmode[i] = j;
    private void changePackDir(int ai[], int ai1[])
    setDX(-1, ai, 0);
    setDY(-1, ai1, 0);
    packdx = ai;
    packdy = ai1;
    packcount = 0;
    private void updatePlayerPos(int i)
    plastx = px;
    px += i;
    if(px + pedgeH > WIDTH || px - pedgeH < 0)
    px = plastx;
    private void fireLaser()
    if(!laser)
    laser = true;
    laserx = px;
    lasery = py;
    private void alienHit(int i)
    if(!playerdead)
    dead[i] = true;
    laser = false;
    killed++;
    if(flying[i])
    score += 200;
    else
    score += 50;
    if(killed == slen)
    waveComplete();
    scorestr = getScoreStr(score);
    private void playerHit()
    playerdead = true;
    playerpause = 0;
    explodeframe = 0;
    lives--;
    if(lives == 0)
    gameOver();
    private void waveComplete()
    wavecomplete = true;
    difficulty -= 100;
    if(difficulty < 100)
    difficulty = 100;
    msg = "WAVE " + wave + " COMPLETE";
    messagepause = 0;
    showmessage = true;
    wave++;
    score += 1000 * wave;
    scorestr = getScoreStr(score);
    private void gameOver()
    gameover = true;
    msg = "GAME OVER";
    for(int i = 0; i < 5; i++)
    if(score < highscore[i])
    continue;
    for(int j = 4; j > i; j--)
    highscore[j] = highscore[j - 1];
    highscore[i] = score;
    rank = i;
    break;
    setHighScores();
    showmessage = true;
    messagepause = 0;
    addEndCommands(mainscreen, true);
    private void addBeginCommands(Displayable displayable, boolean flag)
    if(flag)
    removeCommands();
    displayable.addCommand(playCommand);
    displayable.addCommand(exitCommand);
    displayable.setCommandListener(this);
    private void addPlayCommands(Displayable displayable, boolean flag)
    if(flag)
    removeCommands();
    displayable.addCommand(nullCommand);
    displayable.addCommand(quitCommand);
    displayable.setCommandListener(this);
    private void addEndCommands(Displayable displayable, boolean flag)
    if(flag)
    removeCommands();
    displayable.addCommand(againCommand);
    displayable.addCommand(quitCommand);
    displayable.setCommandListener(this);
    private void removeCommands()
    Displayable displayable = display.getCurrent();
    displayable.removeCommand(nullCommand);
    displayable.removeCommand(quitCommand);
    displayable.removeCommand(againCommand);
    displayable.removeCommand(playCommand);
    displayable.removeCommand(exitCommand);
    public void commandAction(Command command, Displayable displayable)
    if(command == playCommand)
    display.setCurrent(mainscreen);
    startGame();
    if(command == quitCommand)
    runner = false;
    while(th.isAlive()) ;
    th = null;
    addPlayCommands(mainscreen, true);
    display.setCurrent(titlescreen);
    if(command == againCommand)
    runner = false;
    while(th.isAlive()) ;
    th = null;
    display.setCurrent(mainscreen);
    addPlayCommands(mainscreen, true);
    startGame();
    if(command == exitCommand)
    destroyApp(false);
    notifyDestroyed();
    private int[] getHighScores()
    int ai[] = new int[5];
    ai[0] = 5000;
    ai[1] = 4000;
    ai[2] = 3000;
    ai[3] = 2000;
    ai[4] = 1000;
    byte abyte0[][] = new byte[5][6];
    try
    hsdata = RecordStore.openRecordStore("MobileGalaga", true);
    int i = hsdata.getNumRecords();
    if(i == 0)
    for(int j = 0; j < 5; j++)
    abyte0[j] = Integer.toString(ai[j]).getBytes();
    hsdata.addRecord(abyte0[j], 0, abyte0[j].length);
    } else
    for(int k = 0; k < 5; k++)
    abyte0[k] = hsdata.getRecord(k + 1);
    String s = "";
    for(int l = 0; l < abyte0[k].length; l++)
    s = s + (char)abyte0[k][l] + "";
    ai[k] = Integer.parseInt(s);
    catch(RecordStoreException recordstoreexception)
    db("problem with initialising highscore data\n" + recordstoreexception);
    return ai;
    private void setHighScores()
    byte abyte0[][] = new byte[5][6];
    try
    hsdata = RecordStore.openRecordStore("MobileGalaga", true);
    for(int i = 0; i < 5; i++)
    abyte0[i] = Integer.toString(highscore[i]).getBytes();
    hsdata.setRecord(i + 1, abyte0[i], 0, abyte0[i].length);
    catch(RecordStoreException recordstoreexception)
    db("problem with setting highscore data\n" + recordstoreexception);
    private String getScoreStr(int i)
    templen = 6 - (i + "").length();
    tempstr = "";
    for(int j = 0; j < templen; j++)
    tempstr = tempstr + "0";
    return tempstr + i;
    public static void db(String s)
    System.out.println(s);
    public static void db(int i)
    System.out.println(i + "");
    private Display display;
    private Command exitCommand;
    private Command playCommand;
    private Command quitCommand;
    private Command againCommand;
    private Command nullCommand;
    private MainScreen mainscreen;
    private TitleScreen titlescreen;
    private ScoreScreen scorescreen;
    private static int WIDTH;
    private static int HEIGHT;
    private static int CENTERW;
    private static int CENTERH;
    private boolean runner;
    private Thread th;
    private Random rand;
    private static final int RED = 0xff0000;
    private static final int ORANGE = 0xff9100;
    private static final int YELLOW = 0xffff00;
    private static final int WHITE = 0xffffff;
    private static final int BLACK = 0;
    private static final int BLUE = 0x160291;
    private static Image alienimg[] = new Image[2];
    private static Image explosionimg[] = new Image[3];
    private static Image playerimg;
    private static Image logoimg;
    private static int imgH;
    private static int imgW;
    private static int pimgH;
    private static int pimgW;
    private static int edgeH;
    private static int edgeV;
    private static int pedgeH;
    private static int pedgeV;
    private static final Font fs = Font.getFont(64, 0, 8);
    private static final Font fl = Font.getFont(64, 1, 16);
    private static final int sposX[] = {
    16, 28, 40, 52, 4, 16, 28, 40, 52, 64,
    4, 16, 28, 40, 52, 64
    private static final int sposY[] = {
    14, 14, 14, 14, 26, 26, 26, 26, 26, 26,
    38, 38, 38, 38, 38, 38
    private static final int LOOP = 0;
    private static final int ONCE = 1;
    private static final int HOLD = 2;
    private static final int move_none[] = {
    0
    private static final int alien_dx_right[] = {
    1, 1, 1, 1, 1, 1, 1, 1
    private static final int alien_dy_right[] = {
    0, 0, 1, 1, 0, 0, -1, -1
    private static final int alien_dx_left[] = {
    -1, -1, -1, -1, -1, -1, -1, -1
    private static final int alien_dy_left[] = {
    0, 0, -1, -1, 0, 0, 1, 1
    private static final int alien_dx_flyright[] = {
    1, 1, 1, 0, -1, -1, -1, -1, -1, 0,
    1, 1, 2, 3, 4, 5, 6
    private static final int alien_dy_flyright[] = {
    0, -1, -1, -1, -1, -1, 0, 1, 1, 1,
    1, 1, 2, 3, 4, 5, 6
    private static final int alien_dx_flyleft[] = {
    -1, -1, -1, 0, 1, 1, 1, 1, 1, 0,
    -1, -1, -2, -3, -4, -5, -6
    private static final int alien_dy_flyleft[] = {
    0, -1, -1, -1, -1, -1, 0, 1, 1, 1,
    1, 1, 2, 3, 4, 5, 6
    private static final int slen;
    private static final int ailen;
    private static final int packlen;
    private static int pmode[];
    private static int x[];
    private static int y[];
    private static int dx[][];
    private static int dy[][];
    private static int dxcount[];
    private static int dycount[];
    private static int frame[];
    private static boolean flying[];
    private static boolean dead[];
    private static boolean exploding[];
    private static int lastx;
    private static int lasty;
    private static int fly;
    private static int packX[];
    private static int packY[];
    private static int packdx[];
    private static int packdy[];
    private static int packcount;
    private static int framecount = 3;
    private static int px;
    private static int py;
    private static int plastx;
    private static int score;
    private static String scorestr;
    private static int lives;
    private static int killed;
    private static boolean playerdead;
    private static int explodeframe;
    private static int playerpause;
    private static int rank;
    private static boolean playerLeft;
    private static boolean playerRight;
    private static boolean laser;
    private static int laserx;
    private static int lasery;
    private static RecordStore hsdata;
    private static int highscore[] = new int[5];
    private static boolean showmessage;
    private static boolean showscores;
    private static boolean gameover;
    private static boolean wavecomplete;
    private static int messagepause;
    private static String msg;
    private static int difficulty;
    private static int wave;
    private static String tempstr;
    private static int templen;
    static
    slen = sposX.length;
    ailen = alien_dx_flyright.length;
    packlen = alien_dx_right.length;
    pmode = new int[slen];
    x = new int[slen];
    y = new int[slen];
    dx = new int[slen][ailen];
    dy = new int[slen][ailen];
    dxcount = new int[slen];
    dycount = new int[slen];
    frame = new int[slen];
    flying = new boolean[slen];
    dead = new boolean[slen];
    exploding = new boolean[slen];
    packX = new int[slen];
    packY = new int[slen];
    packdx = new int[packlen];
    packdy = new int[packlen];
    ----END OF CODE ----------------

    hi sorry if it's too big! i hope i can explain this very well (you know i only got this code in the net), if you try to run the program in emulator, the and lunch it will it will first display the title screen and if you hit the pressed key 5 it will display help,
    so my problem is how to move UP and DOWN and also if i pressed the fire button it will continue to fire. here is the code.
    //Code for the Left,Right,UP and Down movement and also the fire
    public void keyPressed(int i)
    int j = getGameAction(i);
    if(j == 2)
    MobileGalaga.playerLeft = true; //this is ok
    else
    if(j == 5)
    MobileGalaga.playerRight = true; //this is ok
    else
    if(j==1)
    MobileGalaga.playerUp = true; //i add this only, this has a problem
    else
    if(j==6)
    MobileGalaga.playerDown = true; //i add this only, this has a problem
    else
    if(j == 8)
    fireLaser(); //for the release of fire
    //for the release of key pressed
    public void keyReleased(int i)
    int j = getGameAction(i);
    if(j == 2)
    MobileGalaga.playerLeft = false;
    else
    if(j == 5)
    MobileGalaga.playerRight = false;
    //Update the position base on key pressed
    private void updatePos()
    if(playerLeft)
    updatePlayerPos(-5);
    else
    if(playerUp)
    updatePlayerPos1(-4);
    else
    if(playerDown)
    updatePlayerPos1(4);
    else
    if(playerRight)
    updatePlayerPos(5);
    fly = Math.abs(rand.nextInt() % difficulty);
    if(fly < slen && !flying[fly] && !dead[fly])
    if(x[fly] < CENTERW)
    setDX(fly, alien_dx_flyright, 2);
    setDY(fly, alien_dy_flyright, 2);
    } else
    setDX(fly, alien_dx_flyleft, 2);
    setDY(fly, alien_dy_flyleft, 2);
    flying[fly] = true;
    for(int i = 0; i < slen; i++)
    if(!dead)
    if(!flying[i])
    if(x[i] + edgeH + dx[i][dxcount[i]] > WIDTH)
    changePackDir(alien_dx_left, alien_dy_left);
    if((x[i] - edgeH) + dx[i][dxcount[i]] < 0)
    changePackDir(alien_dx_right, alien_dy_right);
    } else
    if(y[i] + edgeV + dy[i][dycount[i]] > HEIGHT)
    x[i] = packX[i];
    y[i] = packY[i];
    flying[i] = false;
    setDX(i, packdx, 0);
    setDY(i, packdy, 0);
    if(!playerdead && y[i] <= py + pedgeV && y[i] >= py - pedgeV && x[i] <= px + pedgeH && x[i] >= px - pedgeH)
    playerHit();
    if(laser && lasery <= y[i] + edgeV && lasery >= y[i] - edgeV && laserx <= x[i] + edgeH && laserx >= x[i] - edgeH)
    alienHit(i);
    for(int j = 0; j < slen; j++)
    if(!dead[j])
    if(framecount == 3)
    frame[j] = frame[j] + 1 < 2 ? 1 : 0;
    lastx = x[j];
    lasty = y[j];
    x[j] += dx[j][dxcount[j]];
    y[j] += dy[j][dycount[j]];
    if(pmode[j] == 0)
    dxcount[j] = dxcount[j] + 1 < dx[j].length ? dxcount[j] + 1 : 0;
    dycount[j] = dycount[j] + 1 < dy[j].length ? dycount[j] + 1 : 0;
    } else
    if(pmode[j] == 2)
    dxcount[j] = dxcount[j] + 1 < dx[j].length ? dxcount[j] + 1 : dxcount[j];
    dycount[j] = dycount[j] + 1 < dy[j].length ? dycount[j] + 1 : dycount[j];
    packX[j] += packdx[packcount];
    packY[j] += packdy[packcount];
    packcount = packcount + 1 < packlen ? packcount + 1 : 0;
    framecount = framecount + 1 < 4 ? framecount + 1 : 0;
    if(laser)
    lasery -= 6;
    if(lasery < 0 )
    laser = false;
    // this will move the object UP,DOWN,Left and Right
    private void updatePlayerPos(int i)
    plastx = px;
    px += i;
    if(px + pedgeH > WIDTH || px - pedgeH < 0)
    px = plastx;
    private void updatePlayerPos1(int i)
    plastx = py;
    py += i;
    if(px + pedgeV > HEIGHT || px - pedgeV < 0)
    px = plastx;
    // This will fire, if you hit the fire button
    private void fireLaser()
    if(!laser)
    laser = true;
    laserx = px;
    lasery = py;
    sorry if it's too long i just want too explain this. if anyone like to see this and run so that you can see it also, i can send an email.
    thanks,
    alek

  • Can anybody help me to build an interface that can work with this code

    please help me to build an interface that can work with this code
    import java.util.Map;
    import java.util.HashMap;
    import java.util.Iterator;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.io.BufferedReader;
    import java.io.FileReader;
    public class Translate
    public static void main(String [] args) throws IOException
    if (args.length != 2)
    System.err.println("usage: Translate wordmapfile textfile");
    System.exit(1);
    try
    HashMap words = ReadHashMapFromFile(args[0]);
    System.out.println(ProcessFile(words, args[1]));
    catch (Exception e)
    e.printStackTrace();
    // static helper methods
    * Reads a file into a HashMap. The file should contain lines of the format
    * "key\tvalue\n"
    * @returns a hashmap of the given file
    @SuppressWarnings("unchecked")
    private static HashMap ReadHashMapFromFile(String filename) throws FileNotFoundException, IOException
    BufferedReader in = null;
    HashMap map = null;
    try
    in = new BufferedReader(new FileReader(filename));
    String line;
    map = new HashMap();
    while ((line = in.readLine()) != null)
    String[] fields = line.split("
    t", 2);
    if (fields.length != 2) continue; //just ignore "invalid" lines
    map.put(fields[0], fields[1]);
    finally
    if(in!=null) in.close(); //may throw IOException
    return(map); //returning a reference to local variable is safe in java (unlike C/C++)
    * Process the given file
    * @returns String contains the whole file.
    private static String ProcessFile(Map words, String filename) throws FileNotFoundException, IOException
    BufferedReader in = null;
    StringBuffer out = null;
    try
    in = new BufferedReader(new FileReader(filename));
    out = new StringBuffer();
    String line = null;
    while( (line=in.readLine()) != null )
    out.append(SearchAndReplaceWordsInText(words, line)+"\n");
    finally
    if(in!=null) in.close(); //may throw IOException
    return out.toString();
    * Replaces all occurrences in text of each key in words with it's value.
    * @returns String
    private static String SearchAndReplaceWordsInText(Map words, String text)
    Iterator it = words.keySet().iterator();
    while( it.hasNext() )
    String key = (String)it.next();
    text = text.replaceAll("\\b"key"
    b", (String)words.get(key));
    return text;
    * @returns: s with the first letter capitalized
    String capitalize(String s)
    return s.substring(0,0).toUpperCase() + s.substring(1);
    }... here's the head of my pirate_words_map.txt
    hello               ahoy
    hi                    yo-ho-ho
    pardon me       avast
    excuse me       arrr
    yes                 aye
    my                 me
    friend             me bucko
    sir                  matey
    madam           proud beauty
    miss comely    wench
    where             whar
    is                    be
    are                  be
    am                  be
    the                  th'
    you                 ye
    your                yer
    tell                be tellin'

    please help me i don t know how to go about this.my teacher ask me to build an interface that work with the code .
    Here is the interface i just build
    import java.util.Map;
    import java.util.HashMap;
    import java.util.Iterator;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.io.BufferedReader;
    import java.io.FileReader;
    import java.awt.*;
    import javax.swing.*;
    public class boy extends JFrame
    JTextArea englishtxt;
    JLabel head,privatetxtwords;
    JButton translateengtoprivatewords;
    Container c1;
    public boy()
            super("HAKIMADE");
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setBackground(Color.white);
            setLocationRelativeTo(null);
            c1 = getContentPane();
             head = new JLabel(" English to private talk Translator");
             englishtxt = new JTextArea("Type your text here", 10,50);
             translateengtoprivatewords = new JButton("Translate");
             privatetxtwords = new JLabel();
            JPanel headlabel = new JPanel();
            headlabel.setLayout(new FlowLayout(FlowLayout.CENTER));
            headlabel.add(head);
            JPanel englishtxtpanel = new JPanel();
            englishtxtpanel.setLayout(new FlowLayout(FlowLayout.CENTER,10,40));
            englishtxtpanel.add(englishtxt);
             JPanel panel1 = new JPanel();
             panel1.setLayout(new BorderLayout());
             panel1.add(headlabel,BorderLayout.NORTH);
             panel1.add(englishtxtpanel,BorderLayout.CENTER);
            JPanel translateengtoprivatewordspanel = new JPanel();
            translateengtoprivatewordspanel.setLayout(new FlowLayout(FlowLayout.CENTER,10,40));
            translateengtoprivatewordspanel.add(translateengtoprivatewords);
             JPanel panel2 = new JPanel();
             panel2.setLayout(new BorderLayout());
             panel2.add(translateengtoprivatewordspanel,BorderLayout.NORTH);
             panel2.add(privatetxtwords,BorderLayout.CENTER);
             JPanel mainpanel = new JPanel();
             mainpanel.setLayout(new BorderLayout());
             mainpanel.add(panel1,BorderLayout.NORTH);
             mainpanel.add(panel2,BorderLayout.CENTER);
             c1.add(panel1, BorderLayout.NORTH);
             c1.add(panel2);
    public static void main(final String args[])
            boy  mp = new boy();
             mp.setVisible(true);
    }..............here is the code,please make this interface work with the code
    public class Translate
    public static void main(String [] args) throws IOException
    if (args.length != 2)
    System.err.println("usage: Translate wordmapfile textfile");
    System.exit(1);
    try
    HashMap words = ReadHashMapFromFile(args[0]);
    System.out.println(ProcessFile(words, args[1]));
    catch (Exception e)
    e.printStackTrace();
    // static helper methods
    * Reads a file into a HashMap. The file should contain lines of the format
    * "key\tvalue\n"
    * @returns a hashmap of the given file
    @SuppressWarnings("unchecked")
    private static HashMap ReadHashMapFromFile(String filename) throws FileNotFoundException, IOException
    BufferedReader in = null;
    HashMap map = null;
    try
    in = new BufferedReader(new FileReader(filename));
    String line;
    map = new HashMap();
    while ((line = in.readLine()) != null)
    String[] fields = line.split("
    t", 2);
    if (fields.length != 2) continue; //just ignore "invalid" lines
    map.put(fields[0], fields[1]);
    finally
    if(in!=null) in.close(); //may throw IOException
    return(map); //returning a reference to local variable is safe in java (unlike C/C++)
    * Process the given file
    * @returns String contains the whole file.
    private static String ProcessFile(Map words, String filename) throws FileNotFoundException, IOException
    BufferedReader in = null;
    StringBuffer out = null;
    try
    in = new BufferedReader(new FileReader(filename));
    out = new StringBuffer();
    String line = null;
    while( (line=in.readLine()) != null )
    out.append(SearchAndReplaceWordsInText(words, line)+"\n");
    finally
    if(in!=null) in.close(); //may throw IOException
    return out.toString();
    * Replaces all occurrences in text of each key in words with it's value.
    * @returns String
    private static String SearchAndReplaceWordsInText(Map words, String text)
    Iterator it = words.keySet().iterator();
    while( it.hasNext() )
    String key = (String)it.next();
    text = text.replaceAll("\\b"key"
    b", (String)words.get(key));
    return text;
    * @returns: s with the first letter capitalized
    String capitalize(String s)
    return s.substring(0,0).toUpperCase() + s.substring(1);
    }... here's the head of my pirate_words_map.txt
    hello               ahoy
    hi                    yo-ho-ho
    pardon me       avast
    excuse me       arrr
    yes                 aye
    my                 me
    friend             me bucko
    sir                  matey
    madam           proud beauty
    miss comely    wench
    where             whar
    is                    be
    are                  be
    am                  be
    the                  th'
    you                 ye
    your                yer
    tell                be tellin'

  • Noob needs help with this code...

    Hi,
    I found this code in a nice tutorial and I wanna make slight
    adjustments to the code.
    Unfortunately my Action Script skills are very limited... ;)
    This is the code for a 'sliding menue', depending on which
    button u pressed it will 'slide' to the appropriate picture.
    Here's the code:
    var currentPosition:Number = large_pics.pic1._x;
    var startFlag:Boolean = false;
    menuSlide = function (input:MovieClip) {
    if (startFlag == false) {
    startFlag = true;
    var finalDestination:Number = input._x;
    var distanceMoved:Number = 0;
    var distanceToMove:Number =
    Math.abs(finalDestination-currentPosition);
    var finalSpeed:Number = .2;
    var currentSpeed:Number = 0;
    var dir:Number = 1;
    if (currentPosition<=finalDestination) {
    dir = -1;
    } else if (currentPosition>finalDestination) {
    dir = 1;
    this.onEnterFrame = function() {
    currentSpeed =
    Math.round((distanceToMove-distanceMoved+1)*finalSpeed);
    distanceMoved += currentSpeed;
    large_pics._x += dir*currentSpeed;
    if (Math.abs(distanceMoved-distanceToMove)<=1) {
    large_pics._x =
    mask_pics._x-currentPosition+dir*distanceToMove;
    currentPosition = input._x;
    startFlag = false;
    delete this.onEnterFrame;
    b1.onRelease = function() {
    menuSlide(large_pics.pic1);
    b2.onRelease = function() {
    menuSlide(large_pics.pic2);
    b3.onRelease = function() {
    menuSlide(large_pics.pic3);
    b4.onRelease = function() {
    menuSlide(large_pics.pic4);
    I need to adjust five things in this code...
    (1) I want this menue to slide vertically not horizontally.
    I changed the 'x' values in the code to 'y' which I thought
    would make it move vertically, but it doesn't work...
    (2) Is it possible that, whatever the distance is, the
    "sliding" time is always 2.2 sec ?
    (3) I need to implement code that after the final position is
    reached, the timeline jumps to a certain movieclip to a certain
    label - depending on what button was pressed of course...
    I tried to implement this code for button number two...
    b2.onRelease = function() {
    menuSlide(large_pics.pic2);
    if (currentPosition = finalDestination) {
    this.large_pics.pic2.gotoAndPlay("s1");
    --> sliding still works but it doesn't jump to the
    appropriate label...
    (4) I wanna add 'Next' & 'Previous' buttons to the slide
    show - what would be the code in this case scenario ?
    My first thought was something like that Flash checks which
    'pic' movieclip it is showing right now (pic1, pic2, pic3 etc.) and
    depending on what button u pressed u go to the y value of movieclip
    'picX + 1' (Next button) or 'picX - 1' (Previous button)...
    Is that possible ?
    (5) After implementing the Next & Previous buttons I need
    to make sure that when it reached the last pic movieclip it will
    not go further on the y value - because there is no more pic
    movieclip.
    Options are to either slide back to movieclip 'pic1' or
    simply do nothing any more on the next button...
    I know this is probably Kindergarten for you, but I have only
    slight ideas how to do this and no code knowledge to back it up...
    haha
    Thanx a lot for your help in advance !
    Always a pleasure to learn from u guys... ;)
    Mike

    Hi,
    I made some progress with the code thanx to the help of
    Simon, but there are still 2 things that need to be addressed...
    (1) I want the sliding time always to be 2.2 sec...
    here's my approach to it - just a theory but it might work:
    we need a speed that changes dynamically depending on the
    distance we have to travel...
    I don't know if that applies for Action Scrip but I recall
    from 6th grade, that...
    speed = distance / time
    --> we got the time (which is always 2.2 sec)
    --> we got the disctance
    (currentposition-finaldestination)
    --> this should automatically change the speed to the
    appropriate value
    Unfortunately I have no clue how the action script would look
    like (like I said my action script skills are very limited)...
    (2) Also, one other thing I need that is not implemented yet,
    is that when the final destination is reached it jumps to a certain
    label inside a certain movieclip - every time different for each
    button pressed - something like:
    if (currentPosition = finalDestination) {
    this.large_pics.pic2.gotoAndPlay("s1");
    that statement just doesn't work when I put it right under
    the function for each button...
    Thanx again for taking the time !!!
    Mike

  • Help needed in this code

    Hi guys, I need help in debugging this code I made, which is a GUI minesweeper. Its extremely buggy...I particularly need help fixing the actionListener part of the code as everytime I press a button on the GUI, an exception occurs.
    help please!
    package minesweeperGUI;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class MinesweeperGUI implements ActionListener
         //Declaration of attributes
         static int length = 0;
         JMenuItem menuItemNew = new JMenuItem();
         JRadioButtonMenuItem rbEasy = new JRadioButtonMenuItem();
         JRadioButtonMenuItem rbHard = new JRadioButtonMenuItem();
         JMenuItem menuItemExit = new JMenuItem();
         JButton buttonReset = new JButton();
         JButton buttonGrid[][] = null;
         JFrame frame = new JFrame();
         int getBombsTotal = 0;
         JLabel setBombsLabel = new JLabel();
         int a = 0;
         int b = 0;     
         //No constructor created. Uses default constructor
         //Create the menu bar
         public JMenuBar newMenuBar()
              //Sets up the menubar
              JMenuBar menuBar = new JMenuBar();
              //Sets up the Game menu with choice of new, grid size, and exit
              JMenu menu = new JMenu ("Game");
              menuBar.add (menu);
              menuItemNew = new JMenuItem ("New");
              menuItemNew.addActionListener (this);
              menu.add (menuItemNew);
              menu.addSeparator();
              //Sets up sub-menu for grid size with choice of easy and hard radio buttons
              JMenu subMenu = new JMenu ("Grid Size");
              rbEasy = new JRadioButtonMenuItem ("Easy: 5x5 grid");
              rbEasy.addActionListener (this);
              subMenu.add (rbEasy);
              rbHard = new JRadioButtonMenuItem ("Hard: 10x10 grid");
              rbHard.addActionListener (this);
              subMenu.add (rbHard);
              menu.add (subMenu);
              menu.addSeparator();
              menuItemExit = new JMenuItem ("Exit");
              menuItemExit.addActionListener (this);
              menu.add (menuItemExit);
              return menuBar;
         //Setting up of Bomb Grid
         public int [][] setGrid (int length)
              int grid[][] = null;
              grid = new int[length][length];
              for (int i = 0; i < length; i++)
                   for (int j = 0; j < length; j++)
                        grid[i][j] = ((int)Math.round(Math.random() * 10))% 2;
              return grid;     
         //Setting up of the of the graphical bomb grid
         public JButton[][] setButtonGrid (int length)
              JButton buttonGrid[][] = null;
              buttonGrid = new JButton[length][length];
              for (int i = 0; i < length; i++)
                   for (int j = 0; j < length; j++)
                        buttonGrid[i][j] = new JButton();
              return buttonGrid;
         //Setting up of a way to count the total number of bombs in the bomb grid
         public int getBombsTotal (int length, int setGrid[][])
              int bombsTotal = 0;
              for (int i = 0; i < length; i++)
                   for (int j = 0; j < length; j++)
                        if (setGrid[i][j] == 1)
                             bombsTotal += 1;
              return bombsTotal;
         //Create a label for number of bombs left
         public JLabel setBombsLabel (int getBombsTotal)
              JLabel bombsLabel = new JLabel(String.valueOf (getBombsTotal) + " Bombs Left");
              return bombsLabel;
         //Setting up a way to count the number of bombs around a button
         public String setBombs (int length, int setGrid[][], int x, int y)
              int bombs[][] = new int[length][length];
              String bombsString = null;
              for (int i = 0; i < length; i++)
                   for (int j = 0; j < length; j++)
                        if (i == 0 && j == 0)
                             bombs[i][j] = setGrid[i][j+1] + setGrid[i+1][j] +
                                  setGrid[i+1][j+1];
                        else if (i ==0 && j == (length - 1))
                             bombs[i][j] = setGrid[i][j-1] + setGrid[i+1][j-1] +
                                  setGrid[i+1][j];
                        else if (i == (length - 1) && j == 0)
                             bombs[i][j] = setGrid[i-1][j] + setGrid[i-1][j+1] +
                                  setGrid[i][j+1];
                        else if (i == (length - 1) && j == (length - 1))
                             bombs[i][j] = setGrid[i-1][j-1] + setGrid[i-1][j] +
                                  setGrid[i][j-1];
                        else if (i == 0 && j != 0 && j != (length - 1))
                             bombs[i][j] = setGrid[i][j-1] + setGrid[i][j+1] +
                                  setGrid[i+1][j-1] + setGrid[i+1][j] +
                                  setGrid[i+1][j+1];
                        else if (i == (length - 1) && j != 0 && j != (length - 1))
                             bombs[i][j] = setGrid[i-1][j-1] + setGrid[i-1][j] +
                                  setGrid[i-1][j+1] + setGrid[i][j-1] +
                                  setGrid[i][j+1];
                        else if (i != 0 && i != (length - 1) && j == 0)
                             bombs[i][j] = setGrid[i-1][j] + setGrid[i-1][j+1] +
                                  setGrid[i][j+1] + setGrid[i+1][j] +
                                  setGrid[i+1][j+1];
                        else if (i != 0 && i != (length - 1) && j == (length - 1))
                             bombs[i][j] = setGrid[i-1][j-1] + setGrid[i-1][j] +
                                  setGrid[i][j-1] + setGrid[i+1][j-1] +
                                  setGrid[i+1][j];
                        else
                             bombs[i][j] = setGrid[i-1][j-1] + setGrid[i-1][j] +
                                  setGrid[i-1][j+1] + setGrid[i][j-1] +
                                  setGrid[i][j+1] + setGrid[i+1][j-1] +
                                  setGrid[i+1][j] + setGrid[i+1][j+1];
              bombsString = String.valueOf (bombs[x][y]);
              return bombsString;
         //create the panel for the bombs label and reset button
         public JPanel newTopPanel(int length)
              int setGridNew [][] = null;
              setGridNew = new int[length][length];
              int getBombsTotalNew = 0;
              JLabel setBombsLabelNew = new JLabel();
              setGridNew = setGrid (length);
              getBombsTotalNew = getBombsTotal (length, setGridNew);
              setBombsLabelNew = setBombsLabel (getBombsTotalNew);
              JPanel topPanel = new JPanel ();
              topPanel.setLayout (new BorderLayout (50,50));
              JLabel bombsLabel = new JLabel ();
              bombsLabel = setBombsLabelNew;     
              topPanel.add (bombsLabel, BorderLayout.WEST);
              buttonReset = new JButton("Reset");
              buttonReset.addActionListener (this);
              topPanel.add (buttonReset, BorderLayout.CENTER);
              return topPanel;
         //create the panel for the play grids
         public JPanel newBottomPanel(int length)
              JButton setButtonGridNew[][] = null;
              setButtonGridNew = new JButton [length][length];
              setButtonGridNew = setButtonGrid (length);
              JPanel bottomPanel = new JPanel ();
              bottomPanel.setLayout (new GridLayout (length, length));
              buttonGrid = new JButton[length][length];          
              for (a = 0; a < length; a++)
                   for (b = 0; b < length; b++)
                        buttonGrid[a] = setButtonGridNew[a][b];
                        buttonGrid[a][b].addActionListener (this);
                        bottomPanel.add (buttonGrid[a][b]);
              return bottomPanel;
         //Overiding of abstract method actionPerformed
         public void actionPerformed(ActionEvent e)
              if (e.getSource() == menuItemNew)
                   launchFrame(length);
              else if (e.getSource() == menuItemExit)
                   frame.setVisible (false);
                   System.exit(0);
              else if (e.getSource() == rbEasy)
                   length = 5;
                   launchFrame(length);
              else if (e.getSource() == rbHard)
                   length = 10;
                   launchFrame(length);     
              else if (e.getSource() == buttonReset)
                   launchFrame(length);
              else if (e.getSource() == buttonGrid[a][b])
                   int setGridNew [][] = null;
                   setGridNew = new int[length][length];               
                   JButton bombButton [][] = null;
                   bombButton = new JButton [length][length];
                   String bombString [][] = null;
                   bombString = new String[length][length];
                   setGridNew = setGrid (length);               
                   bombString[a][b] = setBombs (length, setGridNew, a, b);
                   bombButton[a][b] = new JButton (bombString[a][b]);
                   if (setGridNew[a][b] == 0)
                        buttonGrid[a][b] = bombButton[a][b];
                        getBombsTotal--;
                        JLabel setBombsLabelNew = new JLabel();
                        setBombsLabelNew = setBombsLabel (getBombsTotal);
                   else if (setGridNew[a][b] == 1 )
                        buttonGrid[a][b] = new JButton("x");
                        JOptionPane.showMessageDialog (null, "Game Over. You hit a Bomb!");
                        System.exit(0);     
         //create the content pane
         public Container newContentPane(int length)
              JPanel topPanel = new JPanel();
              JPanel bottomPanel = new JPanel();          
              topPanel = newTopPanel(length);
              bottomPanel = newBottomPanel (length);
              JPanel contentPane = new JPanel();
              contentPane.setOpaque (true);
              contentPane.setLayout (new BorderLayout(50,50));
              contentPane.add (topPanel, BorderLayout.NORTH);
              contentPane.add (bottomPanel, BorderLayout.CENTER);
              return contentPane;
         public void launchFrame (int length)
              //Makes sure we have nice window decorations
              JFrame.setDefaultLookAndFeelDecorated(true);          
              //Sets up the top-level window     
              frame = new JFrame ("Minesweeper");
              //Exits program when the closed button is clicked
              frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
              JMenuBar menuBar = new JMenuBar();
              Container contentPane = new Container();
              menuBar = newMenuBar();
              contentPane = newContentPane (length);
              //Sets up the menu bar and content pane
              frame.setJMenuBar (menuBar);
              frame.setContentPane (contentPane);
              //Displays the window
              frame.pack();
              frame.setVisible (true);
         public static void main (String args[])
              //Default length is 5
              length = 5;
              MinesweeperGUI minesweeper = new MinesweeperGUI();
              minesweeper.launchFrame(length);

    hi, thanks. that removed the exception; although now the buttons action listener won't work :(
    here is the revised code:
    To anyone out there, can you guys run this code and help me debug it?
    I'm really desperate as this is a school project of mine and the deadline is 7 hours away. I have already been working on it for 3 days, but the program is still very buggy.
    thanks!
    /* Oliver Ian C. Wee 04-80112
    * CS12 MHRU
    * Machine Problem 2
    package minesweeperGUI;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class MinesweeperGUI implements ActionListener
         //Declaration of attributes
         static int length = 0;
         JMenuItem menuItemNew = new JMenuItem();
         JRadioButtonMenuItem rbEasy = new JRadioButtonMenuItem();
         JRadioButtonMenuItem rbHard = new JRadioButtonMenuItem();
         JMenuItem menuItemExit = new JMenuItem();
         JButton buttonReset = new JButton();
         JButton buttonGrid[][] = null;
         JFrame frame = new JFrame();
         int getBombsTotal = 0;
         JLabel setBombsLabel = new JLabel();
         int a = 0;
         int b = 0;
         //No constructor created. Uses default constructor
         //Create the menu bar
         public JMenuBar newMenuBar()
              //Sets up the menubar
              JMenuBar menuBar = new JMenuBar();
              //Sets up the Game menu with choice of new, grid size, and exit
              JMenu menu = new JMenu ("Game");
              menuBar.add (menu);
              menuItemNew = new JMenuItem ("New");
              menuItemNew.addActionListener (this);
              menu.add (menuItemNew);
              menu.addSeparator();
              //Sets up sub-menu for grid size with choice of easy and hard radio buttons
              JMenu subMenu = new JMenu ("Grid Size");
              ButtonGroup bg = new ButtonGroup();
              rbEasy = new JRadioButtonMenuItem ("Easy: 5x5 grid");
              bg.add (rbEasy);
              rbEasy.addActionListener (this);
              subMenu.add (rbEasy);
              rbHard = new JRadioButtonMenuItem ("Hard: 10x10 grid");
              bg.add (rbHard);
              rbHard.addActionListener (this);
              subMenu.add (rbHard);
              menu.add (subMenu);
              menu.addSeparator();
              menuItemExit = new JMenuItem ("Exit");
              menuItemExit.addActionListener (this);
              menu.add (menuItemExit);
              return menuBar;
         //Setting up of Bomb Grid
         public int [][] setGrid (int length)
              int grid[][] = null;
              grid = new int[length][length];
              for (int i = 0; i < length; i++)
                   for (int j = 0; j < length; j++)
                        grid[i][j] = ((int)Math.round(Math.random() * 10))% 2;
              return grid;     
         //Setting up of the of the graphical bomb grid
         public JButton[][] setButtonGrid (int length)
              JButton buttonGrid[][] = null;
              buttonGrid = new JButton[length][length];
              for (int i = 0; i < length; i++)
                   for (int j = 0; j < length; j++)
                        buttonGrid[i][j] = new JButton();
              return buttonGrid;
         //Setting up of a way to count the total number of bombs in the bomb grid
         public int getBombsTotal (int length, int setGrid[][])
              int bombsTotal = 0;
              for (int i = 0; i < length; i++)
                   for (int j = 0; j < length; j++)
                        if (setGrid[i][j] == 1)
                             bombsTotal += 1;
              return bombsTotal;
         //Create a label for number of bombs left
         public JLabel setBombsLabel (int getBombsTotal)
              JLabel bombsLabel = new JLabel("  " +String.valueOf (getBombsTotal) + " Bombs Left");
              return bombsLabel;
         //Setting up a way to count the number of bombs around a button
         public String setBombs (int length, int setGrid[][], int x, int y)
              int bombs[][] = new int[length][length];
              String bombsString = null;
              for (int i = 0; i < length; i++)
                   for (int j = 0; j < length; j++)
                        if (i == 0 && j == 0)
                             bombs[i][j] = setGrid[i][j+1] + setGrid[i+1][j] +
                                  setGrid[i+1][j+1];
                        else if (i ==0 && j == (length - 1))
                             bombs[i][j] = setGrid[i][j-1] + setGrid[i+1][j-1] +
                                  setGrid[i+1][j];
                        else if (i == (length - 1) && j == 0)
                             bombs[i][j] = setGrid[i-1][j] + setGrid[i-1][j+1] +
                                  setGrid[i][j+1];
                        else if (i == (length - 1) && j == (length - 1))
                             bombs[i][j] = setGrid[i-1][j-1] + setGrid[i-1][j] +
                                  setGrid[i][j-1];
                        else if (i == 0 && j != 0 && j != (length - 1))
                             bombs[i][j] = setGrid[i][j-1] + setGrid[i][j+1] +
                                  setGrid[i+1][j-1] + setGrid[i+1][j] +
                                  setGrid[i+1][j+1];
                        else if (i == (length - 1) && j != 0 && j != (length - 1))
                             bombs[i][j] = setGrid[i-1][j-1] + setGrid[i-1][j] +
                                  setGrid[i-1][j+1] + setGrid[i][j-1] +
                                  setGrid[i][j+1];
                        else if (i != 0 && i != (length - 1) && j == 0)
                             bombs[i][j] = setGrid[i-1][j] + setGrid[i-1][j+1] +
                                  setGrid[i][j+1] + setGrid[i+1][j] +
                                  setGrid[i+1][j+1];
                        else if (i != 0 && i != (length - 1) && j == (length - 1))
                             bombs[i][j] = setGrid[i-1][j-1] + setGrid[i-1][j] +
                                  setGrid[i][j-1] + setGrid[i+1][j-1] +
                                  setGrid[i+1][j];
                        else
                             bombs[i][j] = setGrid[i-1][j-1] + setGrid[i-1][j] +
                                  setGrid[i-1][j+1] + setGrid[i][j-1] +
                                  setGrid[i][j+1] + setGrid[i+1][j-1] +
                                  setGrid[i+1][j] + setGrid[i+1][j+1];
              bombsString = String.valueOf (bombs[x][y]);
              return bombsString;
         //create the panel for the bombs label and reset button
         public JPanel newTopPanel(int length)
              int setGridNew [][] = null;
              setGridNew = new int[length][length];
              int getBombsTotalNew = 0;
              JLabel setBombsLabelNew = new JLabel();
              setGridNew = setGrid (length);
              getBombsTotalNew = getBombsTotal (length, setGridNew);
              setBombsLabelNew = setBombsLabel (getBombsTotalNew);
              JPanel topPanel = new JPanel ();
              topPanel.setLayout (new BorderLayout (20,20));
              JLabel bombsLabel = new JLabel ();
              bombsLabel = setBombsLabelNew;     
              topPanel.add (bombsLabel, BorderLayout.WEST);
              buttonReset = new JButton("Reset");
              buttonReset.addActionListener (this);
              topPanel.add (buttonReset, BorderLayout.CENTER);
              return topPanel;
         //create the panel for the play grids
         public JPanel newBottomPanel(int length)
              JButton setButtonGridNew[][] = null;
              setButtonGridNew = new JButton [length][length];
              setButtonGridNew = setButtonGrid (length);
              JPanel bottomPanel = new JPanel ();
              bottomPanel.setLayout (new GridLayout (length, length));
              buttonGrid = new JButton[length][length];          
              for (int i = 0; i < length; i++)
                   for (int j = 0; j < length; j++)
                        buttonGrid[i][j] = setButtonGridNew[i][j];
                        buttonGrid[i][j].addActionListener (this);
                        bottomPanel.add (buttonGrid[i][j]);
              return bottomPanel;
         //Overiding of abstract method actionPerformed
         public void actionPerformed(ActionEvent e)
              if (e.getSource() == menuItemNew)
                   closeFrame();
                   launchFrame(length);
              else if (e.getSource() == menuItemExit)
                   frame.setVisible (false);
                   System.exit(0);
              else if (e.getSource() == rbEasy)
                   closeFrame();
                   length = 5;
                   launchFrame(length);
              else if (e.getSource() == rbHard)
                   closeFrame();
                   length = 10;
                   launchFrame(length);     
              else if (e.getSource() == buttonReset)
                   closeFrame();
                   launchFrame(length);
              else if (e.getSource() == buttonGrid[a])
                   int setGridNew [][] = null;
                   setGridNew = new int[length][length];               
                   JButton bombButton [][] = null;
                   bombButton = new JButton [length][length];
                   String bombString [][] = null;
                   bombString = new String[length][length];
                   setGridNew = setGrid (length);               
                   for (int i = 0; i < length; i++)
                        for (int j = 0; j < length; j++)
                             bombString[i][j] = setBombs (length, setGridNew, i, j);
                             bombButton[i][j] = new JButton (bombString[i][j]);
                   if (setGridNew[a][b] == 0)
                        buttonGrid[a][b] = bombButton[a][b];
                        getBombsTotal--;
                        JLabel setBombsLabelNew = new JLabel();
                        setBombsLabelNew = setBombsLabel (" " String.valueOf (getBombsTotal) " Bombs Left");
                   else if (setGridNew[a][b] == 1 )
                        buttonGrid[a][b] = new JButton("x");
                        JOptionPane.showMessageDialog (null, "Game Over. You hit a Bomb!");
                        System.exit(0);     
         //create the content pane
         public Container newContentPane(int length)
              JPanel topPanel = new JPanel();
              JPanel bottomPanel = new JPanel();          
              topPanel = newTopPanel(length);
              bottomPanel = newBottomPanel (length);
              JPanel contentPane = new JPanel();
              contentPane.setOpaque (true);
              contentPane.setLayout (new BorderLayout(5,5));
              contentPane.add (topPanel, BorderLayout.NORTH);
              contentPane.add (bottomPanel, BorderLayout.CENTER);
              return contentPane;
         public void closeFrame ()
              frame = new JFrame ("Minesweeper");
              frame.dispose();
         public void launchFrame (int length)
              //Makes sure we have nice window decorations
              JFrame.setDefaultLookAndFeelDecorated(true);          
              //Sets up the top-level window     
              frame = new JFrame ("Minesweeper");
              //Exits program when the closed button is clicked
              frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
              JMenuBar menuBar = new JMenuBar();
              Container contentPane = new Container();
              menuBar = newMenuBar();
              contentPane = newContentPane (length);
              //Sets up the menu bar and content pane
              frame.setJMenuBar (menuBar);
              frame.setContentPane (contentPane);
              //Displays the window
              frame.pack();
              frame.setVisible (true);
         public static void main (String args[])
              //Default length is 5
              length = 5;
              MinesweeperGUI minesweeper = new MinesweeperGUI();
              minesweeper.launchFrame(length);

  • Can anybody help me to troubleshoot this code

    According to this code i must get the same number as o/p. But shift and add seems not functioning well.Can anybody help me to troubleshoot

    Hello Pushpa,
    Thank you for contacting National Instruments.
    Which code are you specifying
    Just make your problem clearly and elaborated
    you can send me your code & If you might want to contact the developer of your application, contact - [email protected]
    Have a great day.
    Regards~
    Mathews
    [email protected]

  • Help on upgrading this code to Java 5

    Hi guys,
    I was trying to upgrading the following code to comply with Java 5 using generics, but I failed. Hope somebody here can help me out of this.
    This is the original code:
    import java.util.*;
    public class TestJava5{
        public static void main(String [] args){
            TestJava5 t = new TestJava5();
            Collection strs = t.getAll(String.class);
            for(Iterator i = strs.iterator(); i.hasNext();){
                System.out.println(i.next());
        private Collection getAll(Class c){
            Collection rs = new ArrayList ();
            if(String.class.equals(c)){
                rs.add("str1");
                rs.add("str2");
            }else if(StringBuffer.class.equals(c)){
                rs.add(new StringBuffer("buffer1"));
                rs.add(new StringBuffer("buffer2"));
            return rs;
    }and this is the code I tried to use generics, but obviously, I cannot add a String or StringBuffer into a Collection<T>.
    import java.util.*;
    public class TestJava5{
        public static void main(String [] args){
            TestJava5 t = new TestJava5();
            Collection<String> strs = t.getAll(String.class);
            for(String str:strs){
                System.out.println(str);
        private <T> Collection<T> getAll(Class<T> c){
            Collection<T> rs = new ArrayList<T>();
            if(String.class.equals(c)){
                rs.add("str1");
                rs.add("str2");
            }else if(URI.class.equals(c)){
                rs.add(new StringBuffer("buffer1"));
                rs.add(new StringBuffer("buffer2"));
            return rs;
    }

    Actually, now I've looked at it, it's even worse than that!
    You create a collection with type T, but this type is not fixed at compile type (by definition, obviously). So when you come to add something to the collection (either a String or a StringBuffer), the compiler cannot guarantee that your collection is of the correct type.
    This code is really on a hiding to nothing, I would suggest. But... the following should relieve your immediate compilation problems. However, it is likely to cause further problems when trying to use the returned collection:
      private <T> Collection<?> getAll2(Class<T> c) {
        if (String.class.equals(c)) {
          Collection<String> rs = new ArrayList<String>();
          rs.add("str1");
          rs.add("str2");
          return rs;
        } else if (URI.class.equals(c)) {
          Collection<StringBuffer> rs = new ArrayList<StringBuffer>();
          rs.add(new StringBuffer("buffer1"));
          rs.add(new StringBuffer("buffer2"));
          return rs;
        } else {
          return null;  // or something else like new ArrayList<Object>()
      }

  • Help me with this code..

    need help with this code... i am new to java programming.. and having difficulties with the code below...
    import java.awt.*;
    import javax.swing.*;
    import java.net.*;
    public class DisplayImage extends JApplet
         public void init()
              int[] imageData = {0x47,0x49,0x46,0x38,0x39,0x61,0x38,0x00,0x12,0x00,0xF3,0x00,0x00,0xFB,0x0B,0x0E,0xFF,0x24,0x00,0xFF,0x3C,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0x7B,0xFF,0x00,0x1E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x2C,0x00,0x00,0x00,0x00,0x38,0x00,0x12,0x00,0x00,0x04,0x68,0x10,0xC8,0x49,0xAB,0xBD,0x38,0xEB,0xCD,0xBB,0x0E,0x5E,0x26,0x84,0x64,0x69,0x9E,0xE6,0xA0,0x0E,0xD5,0xEA,0x4E,0xEE,0x4A,0xBD,0xA8,0x2A,0xD9,0x30,0xCB,0xE1,0x00,0xCE,0x93,0xBC,0x9F,0x6E,0x13,0x1C,0xF6,0x8C,0xA7,0x62,0x47,0x99,0x43,0xDD,0x8C,0x31,0x64,0x73,0xFA,0xAC,0xC9,0xA8,0x3F,0xEA,0x71,0x26,0x2D,0x65,0xB9,0x96,0xAC,0xEF,0x9B,0xEA,0x6E,0x5B,0xD2,0xA8,0x53,0x0B,0x6E,0x67,0xC8,0x44,0xA8,0x4E,0x88,0x14,0xCB,0x93,0xF3,0xFB,0xD9,0x3D,0x85,0x2F,0xAF,0x5C,0x64,0x82,0x80,0x6B,0x16,0x04,0x85,0x88,0x6B,0x05,0x89,0x12,0x11,0x00,0x3B};
              ImageIcon icon = null;
              try
                     icon = ImageIcon(ImageDate[]);
              catch(IOException e)
                   System.out.println("Failed to create URL:\n" + e);
                   return;
              loadImage(image);
              int imageWidth = icon.getIconWidth();     // Get icon width
              int imageHeight = icon.getIconHeight();     // and its height
              resize(imageWidth,imageHeight);          // Set applet size to fit the image
              //Create panel a showing the image
              ImagePanel imagePanel = new ImagePanel(icon.getImage());
              getContentPane().add(imagePanel);     // Add the panel to the content pane
         // Class representing a panel displaying an image
         class ImagePanel extends JPanel
              public ImagePanel(Image image)
                   this.image = image;
              public void paint(Graphics g)
                   g.drawImage(image, 0, 0, this);     // Display the image
         Image image;                         // The image
    }Thanks in advance...
    Uzair

    yeah true.... its not that i need someone to write the code.. just cos this code is giving me some problems thought i could get code from others...
    i noticed the extra bracket ending the init().. but thats not what i have problem with....
    It is with how to use ImageIcon(byte[])
    it is something that i need to use this thing in particular... as i am asked to do....

  • Help edit this code

    Hi I got this code of the net which displays a calendar and when a date
    is selected from the calendar it is displayed in the textfield.
    At the moment if nothing is selected from the calendar it displays the first of the month in the textField.
    I want the calendar to work in such a way that if nothing is selected from the calendar then no changes are made to the textfield.
    Can someone help me out?
    Thanks alot
    import javax.swing.*;
    import javax.swing.border.*;
    import java.awt.event.*;
    import java.awt.*;
    import java.util.Date;
    import java.util.Calendar;
    * dialog to allow user to select a date and return
    * a java.util.Date object
    * Creation date: (2/5/00 10:57:04 AM)
    public class DateChooser extends JDialog implements ActionListener {
         //TODO: submit to resource bundle for internationalization
         private String[] months = {"Jan","Feb", "Mar","Apr", "May","June","July","Aug","Sept","Oct","Nov","Dec"};
         private JButton[] days = null;
         private JLabel monthLabel = null;
         private Calendar calendar = null;
         private JPanel mainPanel = null;
    * DateChooser constructor comment.
    public DateChooser() {
         super();
         this.setModal(true);
         initialize();
    * deal with all the buttons that may be pressed
    * Creation date: (2/5/00 11:36:11 AM)
    * @param e java.awt.event.ActionEvent
    public void actionPerformed(ActionEvent e) {
         String text;
         if (e.getActionCommand().equals("D")){
              //return a date
              text = ((JButton) e.getSource()).getText();
              if (text.length() > 0){
                   this.returnDate(text);
              } else {
                   Toolkit.getDefaultToolkit().beep();
         } else {
              this.roll(e.getActionCommand());
    * repaint the window with the supplied calendar date
    * Creation date: (2/5/00 11:04:03 AM)
    * @param d java.util.Date
    private void caption() {
         Calendar cal = this.getCalendar();
         int startPos;
         int currentMonth = cal.get(Calendar.MONTH);
         //for painting ease, quick display
         mainPanel.setVisible(false);
         //set month
         monthLabel.setText(months[cal.get(Calendar.MONTH)] + " " + cal.get(Calendar.YEAR));
         //set to first day
         cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), 1);
         //now work the day labels
         startPos = cal.get(Calendar.DAY_OF_WEEK);
         for (int i = startPos - 1; i < days.length; i++) {
              days.setText(String.valueOf(cal.get(Calendar.DATE)));
              cal.roll(Calendar.DATE, true);
              if (cal.get(Calendar.DATE) == 1) {
                   //clear remaining labels going forward
                   for (int j = i + 1; j < days.length; j++) {
                        days[j].setText("");
                   break;
         //work first week
         for (int h = 0; h < startPos - 1; h++) {
              if (cal.get(Calendar.DATE) > 25 ) {
                   days[h].setText(String.valueOf(cal.get(Calendar.DATE)));
                   cal.roll(Calendar.DATE, true);
              } else {
                   days[h].setText("");
         this.setCalendar(cal);
         mainPanel.setVisible(true);
    * Insert the method's description here.
    * Creation date: (2/5/00 1:12:24 PM)
    * @return java.util.Calendar
    public java.util.Calendar getCalendar() {
         if (this.calendar == null){
              calendar = Calendar.getInstance();
         return calendar;
    * set up the layout and look of the dialog
    * but don't do any data yet.
    * Creation date: (2/5/00 11:02:37 AM)
    private void initialize() {
         JButton jb;
         /* layout:
         North panel: month + year display
         Center Panel: buttons for the days, 5 by 7 grid
         South Panel: navigation buttons */
         mainPanel = new JPanel();
         JPanel northPanel = new JPanel();
         JPanel centerPanel = new JPanel();
         JPanel southPanel = new JPanel();
         //widgets
         //NORTH
         monthLabel = new JLabel(months[9] + " 1953");
         northPanel.setLayout(new FlowLayout());
         northPanel.add(monthLabel);
         //CENTER
         centerPanel.setLayout(new GridLayout(5,7));
         days = new JButton[35];
         for (int i = 0; i <35; i++){
              jb = new JButton(String.valueOf(i));
              jb.setSize(25,25);
              jb.setBorder(new EmptyBorder(1,1,1,1));
              jb.setFocusPainted(false);
              jb.setActionCommand("D");
              jb.addActionListener(this);
              days[i] = jb;
              centerPanel.add(jb);
         //SOUTH
         southPanel.setLayout(new FlowLayout());
         southPanel.add(this.makeButton("<<"));
         southPanel.add(this.makeButton("<"));
         southPanel.add(this.makeButton(">"));
         southPanel.add(this.makeButton(">>"));
         mainPanel.setLayout(new BorderLayout());
         mainPanel.add(northPanel, "North");
         mainPanel.add(centerPanel,"Center");
         mainPanel.add(southPanel, "South");
         this.getContentPane().add(mainPanel);
         this.setSize(150,150);
         caption();
    * for testing only.
    * Creation date: (2/5/00 11:19:35 AM)
    * @param args java.lang.String[]
    public static void main(String[] args) {
         try{
         UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
         } catch (Exception e){}
         final DateChooser dc = new DateChooser();
         JFrame jf = new JFrame();
         jf.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
         JPanel jp = new JPanel();
         final JTextField jff = new JTextField("The date field will hold the result.");
         JButton jb = new JButton("...");
         jb.addActionListener(new ActionListener(){
              public void actionPerformed(ActionEvent e){
                   dc.show();
    java.text.DateFormat df = java.text.DateFormat.getDateInstance(java.text.DateFormat.MEDIUM);
    System.out.println(df.format(new java.util.Date()));
                   jff.setText("" + df.format(dc.getCalendar().getTime()));
         jp.add(jff);
         jp.add(jb);
         jf.getContentPane().add(jp);
         jf.setSize(300,300);
         jf.show();
         //set up location of the dialog
         dc.setLocationRelativeTo(jb);
    * return a button to the control Panel
    * Creation date: (2/5/00 10:57:59 AM)
    * @return java.lang.String
    private JButton makeButton(String caption) {
         JButton jb = new JButton(caption);
         jb.setSize(25,25);
         jb.setBorder(new EmptyBorder(1,4,1,4));
         jb.setFocusPainted(false);
         jb.setActionCommand(caption);
         jb.addActionListener(this);
         return jb;
    * roll the calendar to the day
    * then hide the dialog
    * Creation date: (2/5/00 11:40:31 AM)
    * @param day java.lang.String
    private void returnDate(String day) {
         this.getCalendar().set(this.getCalendar().get(Calendar.YEAR),this.getCalendar().get(Calendar.MONTH),Integer.parseInt(day));
         this.setVisible(false);
    * which way to roll the calendar
    * Creation date: (2/5/00 11:46:42 AM)
    * @param direction java.lang.String
    private void roll(String direction) {
         int field;
         if (direction.equals(">>")) calendar.roll(Calendar.YEAR,true);
         if (direction.equals(">")) calendar.roll(Calendar.MONTH,true);
         if (direction.equals("<<")) calendar.roll(Calendar.YEAR,false);
         if (direction.equals("<")) calendar.roll(Calendar.MONTH,false);
         caption();
    * Insert the method's description here.
    * Creation date: (2/5/00 1:12:24 PM)
    * @param newCalendar java.util.Calendar
    public void setCalendar(java.util.Calendar newCalendar) {
         calendar = newCalendar;

    I don't give a stuff bout your prob... the formatting just pissed me off, thats all!
    import javax.swing.*;
    import javax.swing.border.*;
    import java.awt.event.*;
    import java.awt.*;
    import java.util.Date;
    import java.util.Calendar;
    * dialog to allow user to select a date and return
    * a java.util.Date object
    * Creation date: (2/5/00 10:57:04 AM)
    public class DateChooser extends JDialog implements ActionListener {
    //TODO: submit to resource bundle for internationalization
    private String[] months = {"Jan","Feb", "Mar","Apr", "May","June","July","Aug","Sept","Oct","Nov","Dec"};
    private JButton[] days = null;
    private JLabel monthLabel = null;
    private Calendar calendar = null;
    private JPanel mainPanel = null;
    * DateChooser constructor comment.
    public DateChooser() {
    super();
    this.setModal(true);
    initialize();
    * deal with all the buttons that may be pressed
    * Creation date: (2/5/00 11:36:11 AM)
    * @param e java.awt.event.ActionEvent
    public void actionPerformed(ActionEvent e) {
    String text;
    if (e.getActionCommand().equals("D")){
    //return a date
    text = ((JButton) e.getSource()).getText();
    if (text.length() > 0){
    this.returnDate(text);
    } else {
    Toolkit.getDefaultToolkit().beep();
    } else {
    this.roll(e.getActionCommand());
    * repaint the window with the supplied calendar date
    * Creation date: (2/5/00 11:04:03 AM)
    * @param d java.util.Date
    private void caption() {
    Calendar cal = this.getCalendar();
    int startPos;
    int currentMonth = cal.get(Calendar.MONTH);
    //for painting ease, quick display
    mainPanel.setVisible(false);
    //set month
    monthLabel.setText(months[cal.get(Calendar.MONTH)] + " " + cal.get(Calendar.YEAR));
    //set to first day
    cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), 1);
    //now work the day labels
    startPos = cal.get(Calendar.DAY_OF_WEEK);
    for (int i = startPos - 1; i < days.length; i++) {
    days.setText(String.valueOf(cal.get(Calendar.DATE)));
    cal.roll(Calendar.DATE, true);
    if (cal.get(Calendar.DATE) == 1) {
    //clear remaining labels going forward
    for (int j = i + 1; j < days.length; j++) {
    days[j].setText("");
    break;
    //work first week
    for (int h = 0; h < startPos - 1; h++) {
    if (cal.get(Calendar.DATE) > 25 ) {
    days[h].setText(String.valueOf(cal.get(Calendar.DATE)));
    cal.roll(Calendar.DATE, true);
    } else {
    days[h].setText("");
    this.setCalendar(cal);
    mainPanel.setVisible(true);
    * Insert the method's description here.
    * Creation date: (2/5/00 1:12:24 PM)
    * @return java.util.Calendar
    public java.util.Calendar getCalendar() {
    if (this.calendar == null){
    calendar = Calendar.getInstance();
    return calendar;
    * set up the layout and look of the dialog
    * but don't do any data yet.
    * Creation date: (2/5/00 11:02:37 AM)
    private void initialize() {
    JButton jb;
    /* layout:
    North panel: month + year display
    Center Panel: buttons for the days, 5 by 7 grid
    South Panel: navigation buttons */
    mainPanel = new JPanel();
    JPanel northPanel = new JPanel();
    JPanel centerPanel = new JPanel();
    JPanel southPanel = new JPanel();
    //widgets
    //NORTH
    monthLabel = new JLabel(months[9] + " 1953");
    northPanel.setLayout(new FlowLayout());
    northPanel.add(monthLabel);
    //CENTER
    centerPanel.setLayout(new GridLayout(5,7));
    days = new JButton[35];
    for (int i = 0; i <35; i++){
    jb = new JButton(String.valueOf(i));
    jb.setSize(25,25);
    jb.setBorder(new EmptyBorder(1,1,1,1));
    jb.setFocusPainted(false);
    jb.setActionCommand("D");
    jb.addActionListener(this);
    days = jb;
    centerPanel.add(jb);
    //SOUTH
    southPanel.setLayout(new FlowLayout());
    southPanel.add(this.makeButton("<<"));
    southPanel.add(this.makeButton("<"));
    southPanel.add(this.makeButton(">"));
    southPanel.add(this.makeButton(">>"));
    mainPanel.setLayout(new BorderLayout());
    mainPanel.add(northPanel, "North");
    mainPanel.add(centerPanel,"Center");
    mainPanel.add(southPanel, "South");
    this.getContentPane().add(mainPanel);
    this.setSize(150,150);
    caption();
    * for testing only.
    * Creation date: (2/5/00 11:19:35 AM)
    * @param args java.lang.String[]
    public static void main(String[] args) {
    try{
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e){}
    final DateChooser dc = new DateChooser();
    JFrame jf = new JFrame();
    jf.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    JPanel jp = new JPanel();
    final JTextField jff = new JTextField("The date field will hold the result.");
    JButton jb = new JButton("...");
    jb.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e){
    dc.show();
    java.text.DateFormat df = java.text.DateFormat.getDateInstance(java.text.DateFormat.MEDIUM);
    System.out.println(df.format(new java.util.Date()));
    jff.setText("" + df.format(dc.getCalendar().getTime()));
    jp.add(jff);
    jp.add(jb);
    jf.getContentPane().add(jp);
    jf.setSize(300,300);
    jf.show();
    //set up location of the dialog
    dc.setLocationRelativeTo(jb);
    * return a button to the control Panel
    * Creation date: (2/5/00 10:57:59 AM)
    * @return java.lang.String
    private JButton makeButton(String caption) {
    JButton jb = new JButton(caption);
    jb.setSize(25,25);
    jb.setBorder(new EmptyBorder(1,4,1,4));
    jb.setFocusPainted(false);
    jb.setActionCommand(caption);
    jb.addActionListener(this);
    return jb;
    * roll the calendar to the day
    * then hide the dialog
    * Creation date: (2/5/00 11:40:31 AM)
    * @param day java.lang.String
    private void returnDate(String day) {
    this.getCalendar().set(this.getCalendar().get(Calendar.YEAR),this.getCalendar().get(Calendar.MONTH),Integer.parseInt(day));
    this.setVisible(false);
    * which way to roll the calendar
    * Creation date: (2/5/00 11:46:42 AM)
    * @param direction java.lang.String
    private void roll(String direction) {
    int field;
    if (direction.equals(">>")) calendar.roll(Calendar.YEAR,true);
    if (direction.equals(">")) calendar.roll(Calendar.MONTH,true);
    if (direction.equals("<<")) calendar.roll(Calendar.YEAR,false);
    if (direction.equals("<")) calendar.roll(Calendar.MONTH,false);
    caption();
    * Insert the method's description here.
    * Creation date: (2/5/00 1:12:24 PM)
    * @param newCalendar java.util.Calendar
    public void setCalendar(java.util.Calendar newCalendar) {
    calendar = newCalendar;
    }

  • Help edit this code pliz

    Hi I got this code of the net which displays a calendar and when a date
    is selected from the calendar it is displayed in the textfield.
    At the moment if nothing is selected from the calendar it displays the first of the month in the textField.
    I want the calendar to work in such a way that if nothing is selected from the calendar then no changes are made to the textfield.
    Can someone help me out?
    Well the thing to look at is the main method.
    the main method:
    jb.addActionListener(new ActionListener(){
              public void actionPerformed(ActionEvent e){
                   dc.show();
                   jff.setText("" + dc.getCalendar().getTime());     
    The component works by exposing a Calendar object,
    which has been initialized to the first of the month.
    I think to change this, you would need to wrap the Calendar in
    a new method of Datechooser, like getDateText(). It
    would have code like
    return this.dateTextString;
    The DateChooser's actionPerformed method would need to
    update the dateTextString variable that this new
    method would expose...
    I don't have time to do this... can someone do this for me....pliz
    Thanks alot
    import javax.swing.*;
    import javax.swing.border.*;
    import java.awt.event.*;
    import java.awt.*;
    import java.util.Date;
    import java.util.Calendar;
    * dialog to allow user to select a date and return
    * a java.util.Date object
    * Creation date: (2/5/00 10:57:04 AM)
    public class DateChooser extends JDialog implements ActionListener {
    //TODO: submit to resource bundle for internationalization
    private String[] months = {"Jan","Feb", "Mar","Apr", "May","June","July","Aug","Sept","Oct","Nov","Dec"};
    private JButton[] days = null;
    private JLabel monthLabel = null;
    private Calendar calendar = null;
    private JPanel mainPanel = null;
    * DateChooser constructor comment.
    public DateChooser() {
    super();
    this.setModal(true);
    initialize();
    * deal with all the buttons that may be pressed
    * Creation date: (2/5/00 11:36:11 AM)
    * @param e java.awt.event.ActionEvent
    public void actionPerformed(ActionEvent e) {
    String text;
    if (e.getActionCommand().equals("D")){
    //return a date
    text = ((JButton) e.getSource()).getText();
    if (text.length() > 0){
    this.returnDate(text);
    } else {
    Toolkit.getDefaultToolkit().beep();
    } else {
    this.roll(e.getActionCommand());
    * repaint the window with the supplied calendar date
    * Creation date: (2/5/00 11:04:03 AM)
    * @param d java.util.Date
    private void caption() {
    Calendar cal = this.getCalendar();
    int startPos;
    int currentMonth = cal.get(Calendar.MONTH);
    //for painting ease, quick display
    mainPanel.setVisible(false);
    //set month
    monthLabel.setText(months[cal.get(Calendar.MONTH)] + " " + cal.get(Calendar.YEAR));
    //set to first day
    cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), 1);
    //now work the day labels
    startPos = cal.get(Calendar.DAY_OF_WEEK);
    for (int i = startPos - 1; i < days.length; i++) {
    days.setText(String.valueOf(cal.get(Calendar.DATE)));
    cal.roll(Calendar.DATE, true);
    if (cal.get(Calendar.DATE) == 1) {
    //clear remaining labels going forward
    for (int j = i + 1; j < days.length; j++) {
    days[j].setText("");
    break;
    //work first week
    for (int h = 0; h < startPos - 1; h++) {
    if (cal.get(Calendar.DATE) > 25 ) {
    days[h].setText(String.valueOf(cal.get(Calendar.DATE)));
    cal.roll(Calendar.DATE, true);
    } else {
    days[h].setText("");
    this.setCalendar(cal);
    mainPanel.setVisible(true);
    * Insert the method's description here.
    * Creation date: (2/5/00 1:12:24 PM)
    * @return java.util.Calendar
    public java.util.Calendar getCalendar() {
    if (this.calendar == null){
    calendar = Calendar.getInstance();
    return calendar;
    * set up the layout and look of the dialog
    * but don't do any data yet.
    * Creation date: (2/5/00 11:02:37 AM)
    private void initialize() {
    JButton jb;
    /* layout:
    North panel: month + year display
    Center Panel: buttons for the days, 5 by 7 grid
    South Panel: navigation buttons */
    mainPanel = new JPanel();
    JPanel northPanel = new JPanel();
    JPanel centerPanel = new JPanel();
    JPanel southPanel = new JPanel();
    //widgets
    //NORTH
    monthLabel = new JLabel(months[9] + " 1953");
    northPanel.setLayout(new FlowLayout());
    northPanel.add(monthLabel);
    //CENTER
    centerPanel.setLayout(new GridLayout(5,7));
    days = new JButton[35];
    for (int i = 0; i <35; i++){
    jb = new JButton(String.valueOf(i));
    jb.setSize(25,25);
    jb.setBorder(new EmptyBorder(1,1,1,1));
    jb.setFocusPainted(false);
    jb.setActionCommand("D");
    jb.addActionListener(this);
    days = jb;
    centerPanel.add(jb);
    //SOUTH
    southPanel.setLayout(new FlowLayout());
    southPanel.add(this.makeButton("<<"));
    southPanel.add(this.makeButton("<"));
    southPanel.add(this.makeButton(">"));
    southPanel.add(this.makeButton(">>"));
    mainPanel.setLayout(new BorderLayout());
    mainPanel.add(northPanel, "North");
    mainPanel.add(centerPanel,"Center");
    mainPanel.add(southPanel, "South");
    this.getContentPane().add(mainPanel);
    this.setSize(150,150);
    caption();
    * for testing only.
    * Creation date: (2/5/00 11:19:35 AM)
    * @param args java.lang.String[]
    public static void main(String[] args) {
    try{
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e){}
    final DateChooser dc = new DateChooser();
    JFrame jf = new JFrame();
    jf.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    JPanel jp = new JPanel();
    final JTextField jff = new JTextField("The date field will hold the result.");
    JButton jb = new JButton("...");
    jb.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e){
    dc.show();
    java.text.DateFormat df = java.text.DateFormat.getDateInstance(java.text.DateFormat.MEDIUM);
    System.out.println(df.format(new java.util.Date()));
    jff.setText("" + df.format(dc.getCalendar().getTime()));
    jp.add(jff);
    jp.add(jb);
    jf.getContentPane().add(jp);
    jf.setSize(300,300);
    jf.show();
    //set up location of the dialog
    dc.setLocationRelativeTo(jb);
    * return a button to the control Panel
    * Creation date: (2/5/00 10:57:59 AM)
    * @return java.lang.String
    private JButton makeButton(String caption) {
    JButton jb = new JButton(caption);
    jb.setSize(25,25);
    jb.setBorder(new EmptyBorder(1,4,1,4));
    jb.setFocusPainted(false);
    jb.setActionCommand(caption);
    jb.addActionListener(this);
    return jb;
    * roll the calendar to the day
    * then hide the dialog
    * Creation date: (2/5/00 11:40:31 AM)
    * @param day java.lang.String
    private void returnDate(String day) {
    this.getCalendar().set(this.getCalendar().get(Calendar.YEAR),this.getCalendar().get(Calendar.MONTH),Integer.parseInt(day));
    this.setVisible(false);
    * which way to roll the calendar
    * Creation date: (2/5/00 11:46:42 AM)
    * @param direction java.lang.String
    private void roll(String direction) {
    int field;
    if (direction.equals(">>")) calendar.roll(Calendar.YEAR,true);
    if (direction.equals(">")) calendar.roll(Calendar.MONTH,true);
    if (direction.equals("<<")) calendar.roll(Calendar.YEAR,false);
    if (direction.equals("<")) calendar.roll(Calendar.MONTH,false);
    caption();
    * Insert the method's description here.
    * Creation date: (2/5/00 1:12:24 PM)
    * @param newCalendar java.util.Calendar
    public void setCalendar(java.util.Calendar newCalendar) {
    calendar = newCalendar;

    there are 2 errors in ur code which i removed and run the application.I dont understand really what is ur task??the text filed shows this text "The date field will hold the result." if calender is not selected.here is ur code.now withour errors
    import javax.swing.*;
    import javax.swing.border.*;
    import java.awt.event.*;
    import java.awt.*;
    import java.util.Date;
    import java.util.Calendar;
    * dialog to allow user to select a date and return
    * a java.util.Date object
    * Creation date: (2/5/00 10:57:04 AM)
    public class DateChooser extends JDialog implements ActionListener {
    //TODO: submit to resource bundle for internationalization
    private String[] months = {"Jan","Feb", "Mar","Apr", "May","June","July","Aug","Sept","Oct","Nov","Dec"};
    private JButton[] days = null;
    private JLabel monthLabel = null;
    private Calendar calendar = null;
    private JPanel mainPanel = null;
    * DateChooser constructor comment.
    public DateChooser() {
    super();
    this.setModal(true);
    initialize();
    * deal with all the buttons that may be pressed
    * Creation date: (2/5/00 11:36:11 AM)
    * @param e java.awt.event.ActionEvent
    public void actionPerformed(ActionEvent e) {
    String text;
    if (e.getActionCommand().equals("D")){
    //return a date
    text = ((JButton) e.getSource()).getText();
    if (text.length() > 0){
    this.returnDate(text);
    } else {
    Toolkit.getDefaultToolkit().beep();
    } else {
    this.roll(e.getActionCommand());
    * repaint the window with the supplied calendar date
    * Creation date: (2/5/00 11:04:03 AM)
    * @param d java.util.Date
    private void caption() {
    Calendar cal = this.getCalendar();
    int startPos;
    int currentMonth = cal.get(Calendar.MONTH);
    //for painting ease, quick display
    mainPanel.setVisible(false);
    //set month
    monthLabel.setText(months[cal.get(Calendar.MONTH)] + " " + cal.get(Calendar.YEAR));
    //set to first day
    cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), 1);
    //now work the day labels
    startPos = cal.get(Calendar.DAY_OF_WEEK);
    for (int i = startPos - 1; i < days.length; i++) {
    days.setText(String.valueOf(cal.get(Calendar.DATE)));
    cal.roll(Calendar.DATE, true);
    if (cal.get(Calendar.DATE) == 1) {
    //clear remaining labels going forward
    for (int j = i + 1; j < days.length; j++) {
    days[j].setText("");
    break;
    //work first week
    for (int h = 0; h < startPos - 1; h++) {
    if (cal.get(Calendar.DATE) > 25 ) {
    days[h].setText(String.valueOf(cal.get(Calendar.DATE)));
    cal.roll(Calendar.DATE, true);
    } else {
    days[h].setText("");
    this.setCalendar(cal);
    mainPanel.setVisible(true);
    * Insert the method's description here.
    * Creation date: (2/5/00 1:12:24 PM)
    * @return java.util.Calendar
    public java.util.Calendar getCalendar() {
    if (this.calendar == null){
    calendar = Calendar.getInstance();
    return calendar;
    * set up the layout and look of the dialog
    * but don't do any data yet.
    * Creation date: (2/5/00 11:02:37 AM)
    private void initialize() {
    JButton jb;
    /* layout:
    North panel: month + year display
    Center Panel: buttons for the days, 5 by 7 grid
    South Panel: navigation buttons */
    mainPanel = new JPanel();
    JPanel northPanel = new JPanel();
    JPanel centerPanel = new JPanel();
    JPanel southPanel = new JPanel();
    //widgets
    //NORTH
    monthLabel = new JLabel(months[9] + " 1953");
    northPanel.setLayout(new FlowLayout());
    northPanel.add(monthLabel);
    //CENTER
    centerPanel.setLayout(new GridLayout(5,7));
    days = new JButton[35];
    for (int i = 0; i <35; i++){
    jb = new JButton(String.valueOf(i));
    jb.setSize(25,25);
    jb.setBorder(new EmptyBorder(1,1,1,1));
    jb.setFocusPainted(false);
    jb.setActionCommand("D");
    jb.addActionListener(this);
    days[i] = jb;
    centerPanel.add(jb);
    //SOUTH
    southPanel.setLayout(new FlowLayout());
    southPanel.add(this.makeButton("<<"));
    southPanel.add(this.makeButton("<"));
    southPanel.add(this.makeButton(">"));
    southPanel.add(this.makeButton(">>"));
    mainPanel.setLayout(new BorderLayout());
    mainPanel.add(northPanel, "North");
    mainPanel.add(centerPanel,"Center");
    mainPanel.add(southPanel, "South");
    this.getContentPane().add(mainPanel);
    this.setSize(150,150);
    caption();
    * for testing only.
    * Creation date: (2/5/00 11:19:35 AM)
    * @param args java.lang.String[]
    public static void main(String[] args) {
    try{
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e){}
    final DateChooser dc = new DateChooser();
    JFrame jf = new JFrame();
    jf.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    JPanel jp = new JPanel();
    final JTextField jff = new JTextField("The date field will hold the result.");
    JButton jb = new JButton("...");
    jb.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e){
    dc.show();
    java.text.DateFormat df = java.text.DateFormat.getDateInstance(java.text.DateFormat.MEDIUM);
    System.out.println(df.format(new java.util.Date()));
    jff.setText("" + df.format(dc.getCalendar().getTime()));
    jp.add(jff);
    jp.add(jb);
    jf.getContentPane().add(jp);
    jf.setSize(300,300);
    jf.show();
    //set up location of the dialog
    dc.setLocationRelativeTo(jb);
    * return a button to the control Panel
    * Creation date: (2/5/00 10:57:59 AM)
    * @return java.lang.String
    private JButton makeButton(String caption) {
    JButton jb = new JButton(caption);
    jb.setSize(25,25);
    jb.setBorder(new EmptyBorder(1,4,1,4));
    jb.setFocusPainted(false);
    jb.setActionCommand(caption);
    jb.addActionListener(this);
    return jb;
    * roll the calendar to the day
    * then hide the dialog
    * Creation date: (2/5/00 11:40:31 AM)
    * @param day java.lang.String
    private void returnDate(String day) {
    this.getCalendar().set(this.getCalendar().get(Calendar.YEAR),this.getCalendar().get(Calendar.MONTH),Integer.parseInt(day));
    this.setVisible(false);
    * which way to roll the calendar
    * Creation date: (2/5/00 11:46:42 AM)
    * @param direction java.lang.String
    private void roll(String direction) {
    int field;
    if (direction.equals(">>")) calendar.roll(Calendar.YEAR,true);
    if (direction.equals(">")) calendar.roll(Calendar.MONTH,true);
    if (direction.equals("<<")) calendar.roll(Calendar.YEAR,false);
    if (direction.equals("<")) calendar.roll(Calendar.MONTH,false);
    caption();
    * Insert the method's description here.
    * Creation date: (2/5/00 1:12:24 PM)
    * @param newCalendar java.util.Calendar
    public void setCalendar(java.util.Calendar newCalendar) {
    calendar = newCalendar;

Maybe you are looking for

  • Extension manager cc install fails with error code 15

    Been trying to install Extension Manager cc, but keep getting a failed install with an error code 15, and the following error log: Exit Code: 15 Please see specific errors below for troubleshooting. For example, ERROR: -------------------------------

  • HT1526 trash from my  segate external hard disk.But i am unable to empty my trash box ,getting an error(Error code -36)how to trash?

    I had moved some folder to trash from my  segate external hard disk.But i am unable to empty my trash box ,getting an error:The Finder can't complete the operation because some data in "" can't be read or written. (Error code -36): pls advise,how to

  • 11g B2B & Webcache Reverse Proxy

    Hi all, I'm currently trying to setup an 11g test instance similar to our current 10g instance. Currently we have an Oracle Webcache reverse proxy in our DMZ and infrastructure & mid-tier server running on our internal network. B2B is running via mod

  • Cost center change of Profit Center

    Hi, We wish to change the profit center of a cost center.  I know that all postings going forward will use the new profit center and any historical postings to the cost center will remain on the old profit center. However is there a way to move all t

  • Anybody can help me about WPA Connection?

    Hi Everyone,I've one lenovo G550 notebook and i use Pardus via OS(for informatin visit:www.pardus.org.tr) but i have a problem with wpa connections.I'm connect and getting ip but I'm not connect to internet. I give you some output on terminal.I hope