Please people help me with this project ( the bag of fruits)

hey everyone, i have a assignment that due next Monday and i have some troubles solving it its about a bag of fruits where we can put items grab items get items and so on. this site where the applet for this application is exist http://courses.cs.vt.edu/~csonline/SE/Lessons/OOP/index.html this is my code
public class Bag{
String fruits[];
int bagSize;
public Bag () //constructor
String[] newFruits = new String[8];
bagSize=0;
private boolean isEmpty () {
if (bagSize == 0) {
return
true;
return false;
private boolean isFull(){
if ( bagSize== fruits.length-1){
return true;
return false;
private int totalItems () {
return bagSize;
private boolean emptyBag (){
return bagSize ==0 ;
private boolean hasItem ( Object item ) {
for ( int i =0 ; i<= bagSize-1 ; i++)
if ( i == 0)
return false;
return true;
     public boolean putItem(String pItem){
     if(isFull() == true)
     return
     false;
     else
     fruits[bagSize] = pItem;
     return true;
i will appreciate any help from you, thanks

madridimoot wrote:
my problem is that i have some missing methods like grabItem , putItem, getItem. and when i run the program it told me out of boundYes I can see from your code that you're having trouble with array indexes; if bagSize == 0 your bag is empty and where your bagSize == 8 (the size of the array) your bag is full. You have to add another fruit item at index position bagSize (and increment it afterwards). Deleting an element is a bit more trouble when you want to use an array. Also your method emptyBag() is redundant because it's functionally equivalent to the isEmpty() method. An array is quite a clumsy data structure for a bag of things. A List would've been better.
kind regards,
Jos

Similar Messages

  • HT1494 hi....i  cant continuously play my music with my ipod nano....i tried a lot with the settings for wake time but still it is pausing the music path.Please anybody help me with this issue

    hi....i  cant continuously play my music with my ipod nano....i tried a lot with the settings for wake time but still it is pausing the music path.Please anybody help me with this issue

    Is this your problem?
    iPod nano (6th generation): Music stops when display turns off
    B-rock

  • Please! help me with this wrong code, where is mistake

    please! help me with this wrong code, where is mistake?
    import java.util.Stack;
    public class KnightsTour {
    Vars locs[];
    private int size, max=1, d=0, board[][];
    public KnightsTour(int x,int y, int newSize)
         size=newSize;
         locs=new Vars[size*size+1];
         for(int n=1;n<=size*size;n++)
              locs[n]=new Vars();
         board=new int[size+1][size+1];
         for(int n=1;n<=size;n++)
              for(int n2=1;n2<=size;n2++)
                   board[n][n2]=0;
         locs[max].x=x;
         locs[max].y=y;
         locs[max].d=1;
         board[x][y]=max;
         max++;
    class Vars{
         int x;
         int y;
         int d;
    public void GO()
         int n=0;
         while(max<=size*size)
              n++;
              d++;
              if(d>8)
                   max--;
                   board[locs[max].x][locs[max].y]=0;
                   d=locs[max].d+1;
              move();
         printBoard();
    public void move()
         int x=locs[max-1].x, y=locs[max-1].y;
         switch(d)
         case 1:x--;y-=2;break;
         case 2:x++;y-=2;break;
         case 3:x+=2;y--;break;
         case 4:x+=2;y++;break;
         case 5:x++;y+=2;break;
         case 6:x--;y+=2;break;
         case 7:x-=2;y++;break;
         case 8:x-=2;y--;break;
         //System.out.println(" X: "+x+" Y: "+y+" |"+max);
         if((x<1)||(x>size)||(y<1)||(y>size)){}
         else if(board[x][y]!=0){}
         else
              locs[max].x=x;
              locs[max].y=y;
              locs[max].d=d;
              board[x][y]=max;
              max++;
              d=0;
              //printBoard();
    public void printBoard()
         for(int n=1;n<=size;n++)
              for(int n2=1;n2<=size;n2++)
                   if(board[n2][n]<10)
                        System.out.print(board[n2][n]+" ");
                   else
                        System.out.print(board[n2][n]+" ");
              System.out.println();
         //System.out.println();
         System.out.println();
         public static void main (String[]args){
              KnightsTour k = new KnightsTour(1,1,8);
         }

    public class KnightsTour {
        Vars locs[];
        private int size,  max = 1,  d = 0,  board[][];
        public static void main (String[] args) {
            KnightsTour k = new KnightsTour (1, 1, 8);
            k.GO ();
        public KnightsTour (int x, int y, int newSize) {
            size = newSize;
            locs = new Vars[size * size + 1];
            for (int n = 1; n <= size * size; n++) {
                locs[n] = new Vars ();
            board = new int[size + 1][size + 1];
            for (int n = 1; n <= size; n++) {
                for (int n2 = 1; n2 <= size; n2++) {
                    board[n][n2] = 0;
            locs[max].x = x;
            locs[max].y = y;
            locs[max].d = 1;
            board[x][y] = max;
            max++;
        class Vars {
            int x;
            int y;
            int d;
        public void GO () {
            int n = 0;
            while (max <= size * size) {
                n++;
                d++;
                if (d > 8) {
                    max--;
                    board[locs[max].x][locs[max].y] = 0;
                    d = locs[max].d + 1;
                move ();
            printBoard ();
        public void move () {
            int x = locs[max - 1].x, y = locs[max - 1].y;
            switch (d) {
                case 1:
                    x--;
                    y -= 2;
                    break;
                case 2:
                    x++;
                    y -= 2;
                    break;
                case 3:
                    x += 2;
                    y--;
                    break;
                case 4:
                    x += 2;
                    y++;
                    break;
                case 5:
                    x++;
                    y += 2;
                    break;
                case 6:
                    x--;
                    y += 2;
                    break;
                case 7:
                    x -= 2;
                    y++;
                    break;
                case 8:
                    x -= 2;
                    y--;
                    break;
    //System.out.println(" X: "x" Y: "y" |"+max);
            if ((x < 1) || (x > size) || (y < 1) || (y > size)) {
            } else if (board[x][y] != 0) {
            } else {
                locs[max].x = x;
                locs[max].y = y;
                locs[max].d = d;
                board[x][y] = max;
                max++;
                d = 0;
    //printBoard();
        public void printBoard () {
            for (int n = 1; n <= size; n++) {
                for (int n2 = 1; n2 <= size; n2++) {
                    if (board[n2][n] < 10) {
                        System.out.print (board[n2][n] + " ");
                    } else {
                        System.out.print (board[n2][n] + " ");
                System.out.println ();
    //System.out.println();
            System.out.println ();
    }formatting ftw.
    If you call GO () you get in an infinite loop. max gets decreased, and it loops while max is smaller then or equal to size * size. Is your looping logic correct ?

  • CAN SOMEONE HELP ME WITH THIS ISSUE; the attempt to burn a disc failed. an unknown error occurred 4221

    CAN SOMEONE HELP WITH THIS ISSUE:
    THE ATTEMPT TO BURN A DISC FAILED. AN UNKNOWN ERROR OCCURRED (4221)

    Microsoft Windows XP Professional Service Pack 3 (Build 2600)
    IBM 18308TU
    iTunes 10.6.3.25
    QuickTime 7.7.2
    FairPlay 1.14.43
    Apple Application Support 2.1.9
    iPod Updater Library 10.0d2
    CD Driver 2.2.0.1
    CD Driver DLL 2.1.1.1
    Apple Mobile Device 5.2.0.6
    Apple Mobile Device Driver 1.59.0.0
    Bonjour 3.0.0.10 (333.10)
    Gracenote SDK 1.9.6.502
    Gracenote MusicID 1.9.6.115
    Gracenote Submit 1.9.6.143
    Gracenote DSP 1.9.6.45
    iTunes Serial Number 0012A7CC0B5F78F0
    Current user is an administrator.
    The current local date and time is 2012-08-12 22:04:05.
    iTunes is not running in safe mode.
    WebKit accelerated compositing is disabled.
    HDCP is not supported.
    Core Media is not supported. (16005)
    Video Display Information
    ATI MOBILITY RADEON 7500
    **** External Plug-ins Information ****
    No external plug-ins installed.
    Genius ID: 2e39627a5d03e3456e051c0b031fabab
    iPodService 10.6.3.25 is currently running.
    iTunesHelper 10.6.3.25 is currently running.
    Apple Mobile Device service 3.3.0.0 is currently running.
    **** CD/DVD Drive Tests ****
    No drivers in LowerFilters.
    UpperFilters: GEARAspiWDM (2.2.0.1),
    D: MATSHITA DVD-RAM UJ-842, Rev RB01
    Audio CD in drive.
    Found 11 songs on CD, playing time 41:38 on Audio CD.
    Track 1, start time 00:02:00
    Track 2, start time 04:00:20
    Track 3, start time 08:00:35
    Track 4, start time 11:08:15
    Track 5, start time 14:14:50
    Track 6, start time 19:11:15
    Track 7, start time 22:28:38
    Track 8, start time 25:48:38
    Track 9, start time 29:54:28
    Track 10, start time 34:03:35
    Track 11, start time 38:03:25
    Audio CD reading succeeded.
    Get drive speed succeeded.
    The drive CDR speeds are:   4 8 12 16 24.
    The drive CDRW speeds are:   4.
    The drive DVDR speeds are:   4.
    The drive DVDRW speeds are:   4.
    The last failed audio CD burn had error code 4221(0x0000107d). It happened on drive D: MATSHITA DVD-RAM UJ-842 on CDR media at speed 24X.

  • Can some one help me with this project

    This project will simulate the behavior of an Integrity Subsystem in validating the data in a database.
    More specifically, assume there are 2 tables, A and B, in a given database. Table A has 4 integer
    attributes names a, b, c, d and table B has 4 integer attributes named e, f, g, h.
    Your program is to input up to 20 integrity rules as discussed below, and store them in some internal
    format of your choosing. Then enter up to 15 tuples for each table. For each tuple, check it against all the
    applicable integrity rules and print out an error message for each rule that is violated. If no rules are
    violated then print a message saying all it well and enter that tuple into the database. Do not enter a tuple
    into a database if any rule is violated for that tuple.
    There are 3 different types of integrity rules: Primary key, Foreign key, and Attribute.
    The formats for the rules are given below:
    Primary key: rule#, P, tablename, attribute name
    1 A or B a,b,c,d,e,f,g, or h
    The meaning of this rule is that the specified attribute name of the specified table is the
    primary key of that table.
    Foreign key: rule#, F, tablename, attribute name, tablename, attributename
    2 A or B a,b,c,d,e,f,g, or h A or B a,b,c,d,e,f,g, or h
    The meaning of this rule is that the first attribute name and tablename is a foreign key
    referencing the second attribute name and tablename.
    Attribute: rule#, A, tablename, attribute name, low value, high value
    3 A or B a,b,c,d,e,f,g, or h 0-9999 0-9999
    The meaning of this rule is that the attribute name in the specified table always have a value lying
    in the range of low value to high value inclusive.
    Your program should implement at least the following 10 rules
    Rules:
    1 P A b
    2 F A d B g
    3 A A a 10 20
    4 A B h 8 9000
    5 P B g
    6 A B g 0 100
    7 F A c B h
    8 A A b 10 30
    9 A B e 0 80
    10 A A a 8 30
    Page 2 of 3
    The following data is provided for your convenience to test the correctness of your program. Remember I
    will use these data and some other new data for the testing.
    Tuples: (Insert in this order)
    A 8 32 30 50
    A 10 20 30 40
    B 5 20 50 100
    B 8 30 40 200
    A 10 20 100 50
    A 10 22 100 40
    A 8 32 30 40
    B 30 40 50 60
    B 80 2000 0 0
    A 9 25 200 50
    A 12 25 60 50
    B 0 0 0 100
    A 10 10 10 10
    A 20 20 200 40
    A 0 0 0 0
    B 0 0 0 0
    B 50 50 50 50
    Specifications:
    1. You can just represent the provided 10 rules and new rules created by yourself in some
    internal data structures. Or you can store the rules in a text file and then read it one by one.
    2. The test data must be stored in a text file �tuples.txt� in which each line has one tuple and
    field items are separated by one or more blank spaces (not comma, or colons).
    3. Bring a project report at the beginning of the class on the due date. The project report
    should have a summary on how you finish the project. For examples, you should discuss
    some key data structures you chosen to store the rules and tuples, how you check the invalid
    tuples and insert valid tuples, and so on. I hope that after reading the report, I should get some
    ideas how you finish the project even without reading the source code.
    4. Also you should print out source code and include in the report. In addition, you need to
    copy the execution output results. I give a sample expected output for your reference. You
    can change it in any way but just make sure it is clear to read for users.
    Sample Outputs (for simplicity only three rules used in this example):
    Integrity Rules (total 3):
    1 P A b
    2 F A d B g
    3 A A a 10 20
    Tuples: (Insert in this order)
    T1: A 8 32 30 50
    Page 3 of 3
    T2: A 10 20 30 40
    T3: B 5 20 50 100
    T4: A 8 25 40 100
    Results:
    T1 is invalid (against rule 3), discard it!
    T2 is valid, insert to DB
    T3 is valid, insert to DB
    T4 is invalid (against rule 1), discard it!
    Summary:
    2 tuples (T2, T3) are inserted to DB
    2 tuples (T1, T4) are discarded
    5. Bring a floppy disk containing the source code and the project report word file. It should
    only have one directory named as your �Firstname.Lastname� For example, if your name is
    John Johnson, the directory name should be �John.Johnson� in the root (your wku email
    should be [email protected] also in most cases).
    Create a subdirectory �Report� to store the report word file. The report name can be
    �CS543_Project_2_Report�. Then create another directory named as �Code� to keep all the
    necessary files to run the program without any further configuration (including �tuples.txt�).
    6. Submit a zip file which contains all the files in your floppy disk to the �Digital Drop Box�.
    The zip file name must be �Firstname.Lastname.zip�. For example, if your name is John
    Johnson, the directory name should be �John.Johnson.zip�. So if I unzip the file, I should get
    exactly same files as the floppy disk.
    7. Follow closely �Program Scoring Rubric For CS Dept� and �Writing/Documentation
    Scoring Rubric for CS Dept�. Your project grading will be based on these two guidelines.
    At least, your code should have a perfect and consistent format style and include sufficient
    comments (generally > 20%) which explain possible confusions clearly. Also always try to
    use constant variables to denote numbers. For example, if you created 20 rules in total, you
    can define a constant variable such as in C++ �#define TOTAL_INTEGRITY_RULES 20�.

    So what is your question?
    People here are not generally inclined to read your homework, and then read your mind to find out what's giving you trouble.
    If you're absolutely lost and have no clue where to start, you should speak to you instructor or engage the services of a private tutor. These forums are simply not an effective venue for that kind of help.
    Otherwise, take your best shot, do as much as you can do, and then post specific questions about the specific bits that are giving you trouble. Be as thorough and precise as possible about what you're trying to do and what didn't work. Copy/paste the complete text of any error messages. Add println statements to your code and include comments like "I expected it to print xyz here but it printed abc".

  • Please someone help me with this or other wise im gonna return my ipod

    please a little help here. i've been trying this since last night and still i cant figure it out. my music videos don't have any sound at all. i've chequed the volume and the settings and still cant hear anything its driving me crazy!!

    Quicktime, Quicktime Pro and iTunes don't convert "muxed" ( muxed means multiplexed where the audio and video are stored on the same track) video files properly. It only plays the video and not the audio.
    See:iPod plays video but not audio.
    You need a 3rd party converter to convert the file with both audio and video.
    Search this forum for recommendations, but beware of spammers trying to sell you their own product.

  • 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

  • Please somebody help me with this

    1.1 modify the application so that:
    i) Information about any foreign key constraints for the selected table is displayed eg as
    additional labels in the table editor window, or in a separate dialog window.
    You can choose how you wish to display this information.
    ii) An Update button is added for each text field in the display, which will attempt to update the corresponding field in the database table, from the current data in the textfield. The following code will retrieve the current value from a JTextField object:
    String newValue = textfieldName.getText();
    The following code will convert the string to a number:
    int newNumber = Integer.parseInt(newValue);
    Remember, an attempt to update a row in a table may fail if eg it tries to alter a
    foreign key to a value not currently recorded for any corresponding primary key
    that the foreign key refers to.
    An attempt to set a foreign key field to 'null' should always be successful.
    If the update attempt fails, the value in the displayed text field should revert to its
    original state, to maintain consistency with the database.
    import java.io.*;
    import java.sql.*;
    import java.util.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import oracle.jdbc.driver.*;
    * class JdbcCW
    * demonstration of Java client connecting to an Oracle DBMS
    * @author put your name here
    * @date December 2002
    public class JdbcCW extends JFrame{
    static String url = "jdbc:oracle:thin:@localhost:1521:orcl";
    static String initialquery = "select table_name from user_tables";
    static String nullstring = "null";
    private String user;
    private String pass;
    private Connection conn;
    private Statement stmt;
    private ResultSet results;
    private JComboBox tableChooser;
    private JButton editButton;
    private JButton exitButton;
    private JButton detailsButton;
    private JPanel panel1;
    private JPanel panel2;
    private String selectedTable;
    private Container cp;
    public static void main(String[] args) throws SQLException {
    JdbcCW demo = new JdbcCW();
    demo.show();
    * JdbcCW constructor method
    public JdbcCW() throws SQLException {
    super("Java/Oracle coursework");
    addWindowListener (new WindowAdapter() {
    public void windowClosing (WindowEvent evt) {
    System.exit(0);
    try {
    user =
    JOptionPane.showInputDialog("enter oracle username eg ops$c9999999");
    pass = JOptionPane.showInputDialog("enter oracle password eg 29feb80");
    if ( user.length() == 0 || pass.length() == 0)
    throw new Exception("no user name and/or password");
    DriverManager.registerDriver (new OracleDriver());
    conn = DriverManager.getConnection(url, user, pass);
    if (conn != null)
    System.out.println("Connected");
    catch (Exception e ) {
    e.printStackTrace();
    System.exit(0); // problems - abandon ship
    // now we can access tables in the database
    stmt = conn.createStatement();
    results = stmt.executeQuery(initialquery);
    boolean anyRecords = results.next();
    if ( ! anyRecords ) {
    JOptionPane.showMessageDialog (this, "No Tables in the database");
    System.exit(0);
    tableChooser = new JComboBox();
    do
    tableChooser.addItem(results.getString(1));
    while (results.next() ) ;
    selectedTable = (String) tableChooser.getSelectedItem();
    tableChooser.addActionListener (new ActionListener () {
    public void actionPerformed (ActionEvent evt) {
         changeTable();
    editButton = new JButton("Edit");
    editButton.addActionListener(new ActionListener () {
    public void actionPerformed(ActionEvent evt) {
         runEdit();
    exitButton = new JButton("Exit");
    exitButton.addActionListener(new ActionListener () {
    public void actionPerformed(ActionEvent evt) {
    System.exit(0);
    panel1 = new JPanel(); // panels have flow layout
    JLabel label1 = new JLabel("Choose Table");
    panel1.add(label1);
    panel1.add(tableChooser);
    panel2 = new JPanel();
    panel2.add(editButton);
    panel2.add(exitButton);
    cp = getContentPane();
    cp.add(panel1,BorderLayout.NORTH);
    cp.add(panel2,BorderLayout.SOUTH);
    setSize(300,200);
    setLocation(100,100);
    private void changeTable() {
    selectedTable = (String) tableChooser.getSelectedItem();
    * method runEdit runs a query to determine the structure of the
    * selected table in order to customise the table editor window
    private void runEdit() {
    System.out.println("Selected Table " + selectedTable);
    String query = "select column_name,data_type from user_tab_columns " +
         "where table_name = '" + selectedTable + "'";
    try {
         results = stmt.executeQuery(query);
    } catch (java.sql.SQLException e) {
         System.out.println("SQL Exception on query " + query);
         return;
    JdbcEdit tableEditor = new JdbcEdit(this,selectedTable,results);
    tableEditor.show();
    public ResultSet makeQuery(String query) {
         ResultSet results;
         try {
         results = stmt.executeQuery(query);
         } catch (SQLException e) {
         System.out.println("Query Failed " + query);
         return null;
         return results;
    } // end class JdbcGen
    * class JdbcEdit
    * oracle table editing dialog window
    * @author put your name here as well
    * @date December 2002
    class JdbcEdit extends JDialog {
    private JdbcCW parent;
    private Container cp;
    private Vector columnNames;
    private Vector dataTypes;
    private Vector editFields;
    private Vector rows;
    private int noOfColumns;
    private int currentRow = 0;
    * JdbcEdit constructor method
    * the parameter true makes the dialog window modal -
    * the parent frame is inactive as long as this window is displayed
    public JdbcEdit (JdbcCW parent, String tableName, ResultSet results) {
         super(parent,"table editor " + tableName, true);
         this.parent = parent;
    columnNames = new Vector();
    dataTypes = new Vector();
         editFields = new Vector();
         JPanel mainPanel = new JPanel();
         mainPanel.setLayout(new BoxLayout(mainPanel,BoxLayout.Y_AXIS));
    // boxLayout - components are added to mainPanel in a vertical stack
         try {
         boolean anyRecords = results.next();
         if ( ! anyRecords ) {
              JOptionPane.showMessageDialog (this, "No Detail for " +
                             tableName+ " in the database");
              return;
         do {
              String columnName = results.getString(1);
              String dataType = results.getString(2);
              System.out.println("Row " + columnName + " Type " + dataType);
              JPanel editPanel = new JPanel();
              JLabel colNameLabel = new JLabel(columnName);
              JTextField dataField = new JTextField(20);
              editPanel.add(colNameLabel);
              editPanel.add(dataField);
    // this would be a good place to add an Update button
              mainPanel.add(editPanel);
    // now store the columnName, dataType and data text field
    // in vectors so other methods can access them
    // at this point in time the text field is empty
              columnNames.add(columnName);
              dataTypes.add(dataType);
         editFields.add(dataField);
         }while (results.next() ) ;
         } catch (java.sql.SQLException e) {
         System.out.println("SQL Exception on query ");
         return;
    // get the data from the Oracle table and put the first
    // row of data in the text fields in the dialog window
         populateData(tableName);
    // find out which column(s) are part of the primary key and make these
    // textfields non-editable so the values can't be changed
    findPKConstraints(tableName);
    // this would be a good place to discover any foreign key constraints
         JPanel buttonsPanel = new JPanel();
         JButton exitButton = new JButton("Exit");
         exitButton.addActionListener(new ActionListener () {
         public void actionPerformed(ActionEvent evt) {
              closeWindow();
         JButton nextButton = new JButton("Next");
         nextButton.addActionListener(new ActionListener () {
         public void actionPerformed(ActionEvent evt) {
              showRow(true);
         JButton prevButton = new JButton("Prev");
         prevButton.addActionListener(new ActionListener () {
         public void actionPerformed(ActionEvent evt) {
              showRow(false);
         buttonsPanel.add(exitButton);
         buttonsPanel.add(nextButton);
         buttonsPanel.add(prevButton);
    cp = getContentPane();
         cp.add(mainPanel,BorderLayout.CENTER);
         cp.add(buttonsPanel,BorderLayout.SOUTH);
         pack();
    private void closeWindow() {
         dispose();
    private void populateData(String tableName) {
    int noOfColumns;
    // have to access the Statement object in the parent frame
         ResultSet tableData = parent.makeQuery("select * from " + tableName);
         try {
         boolean anyRecords = tableData.next();
         if ( ! anyRecords ) {
              JOptionPane.showMessageDialog (this, "No data in " +
                             tableName);
              return;
         rows = new Vector();
    noOfColumns = columnNames.size();
         do {
              String [] row = new String[noOfColumns];
              for (int i = 0; i < noOfColumns; i++) {        
              row[i] = tableData.getString(i+1);
              rows.add(row);
         } while (tableData.next() ) ;
         } catch (java.sql.SQLException e) {
         System.out.println("SQL Exception on query ");
         return;
    // Put the first row of data from the table into the test fields;
         String [] rowData = (String[]) rows.get(0);
         for (int i = 0; i < noOfColumns; i++) {
    // get the reference to a text field in the dialog window
    JTextField textField = (JTextField) editFields.get(i);
    // vector editFields holds a reference to each JTextField
    // in the visible dialog window
    // hence the next line of code puts the data retrieved from
    // the table into the relevant text field in the GUI interface
         textField.setText(rowData);
    // method showRow updates the textfields in the GUI interface
    // with the next row of data from the table ( if next is true)
    // or with the previous row of data from the table ( if next is false)
    private void showRow(boolean next) {
    if ( rows == null ) {
    System.out.println("table is empty");
         getToolkit().beep();
         return;
         if (next && currentRow < rows.size() - 1) {
         currentRow++;
         } else if (!next && currentRow > 0) {
         currentRow--;
         } else {
         System.out.println("No Next/Prev row " + currentRow);
         getToolkit().beep();
         return;
         String [] rowData = (String[]) rows.get(currentRow);
    int noOfAttributes = dataTypes.size();
         for (int i = 0; i < noOfAttributes; i++) {
         JTextField textField = (JTextField) editFields.get(i);
         textField.setText(rowData[i]);
    private void findPKConstraints(String tableName){
         String PK_ConstraintName = "none";
         String pkquery =
    "select owner,constraint_name from user_constraints " +
         "where table_name = '" + tableName + "' and constraint_type = 'P'";
    // have to access the Statement object in the parent frame
         ResultSet results = parent.makeQuery(pkquery);
         try {
         boolean anyRecords = results.next();
         if ( ! anyRecords ) {
              // if none just return - but print a debug message
              System.out.println("No primary key constraint found");
              return;
         } else {
              // There should only be one
              System.out.println("Owner = " + results.getString(1) +
                        " name = " + results.getString(2));
              PK_ConstraintName = results.getString(2);
              // Now find out which columns
              pkquery =
    "select Column_name, position from user_cons_columns"
              + " where constraint_name = '" + PK_ConstraintName
              + "'";
    // have to access the Statement object in the parent frame
              results = parent.makeQuery(pkquery);
              anyRecords = results.next();
              if ( ! anyRecords ) {
              // if none just return - but there must be at least one
              System.out.println("no columns found");
              return;
              } else {
              do {
                   System.out.println
    ("Name " + results.getString(1) +
                   " position " + results.getString(2))
                   int position = Integer.parseInt(results.getString(2));
                   JTextField primarykey =
    (JTextField)editFields.get(position - 1);
                   primarykey.setEditable(false);
              } while (results.next());
         } catch (java.sql.SQLException e) {
         System.out.println("SQL Exception on query " + pkquery);
         return;

    You're pretty optimistic if you think anyone is going to answer that. There are three very good reasons not to (each is good enough by themselves!).
    1. IT'S YOUR HOMEWORK, IT DOESN'T EVEN LOOK AS THOUGH YOU'VE TRIED. WE HELP WITH PROBLEMS, NOT PROVIDE SOLUTIONS, ESPECIALLY FOR HOMEWORK.
    2. Format your code. Use [ code] and [ /code] (without the spaces). And if you've used 'i' as an index variable, [ i] will result in switching to italics mode. Use 'j' as your index variable.
    3. Don't post your whole program, only the parts you're having trouble with (mostly not relevant for this question, as you don't seem to have trouble with any particular area)

  • Please anyone help me with this

    Hi guys, Check this out:
    http://www.large-online.nl/partnerimg/4/436794.jpg
    How do you remove the letter in photoshop cs5? I wanted it removed while maintaining the hair.
    please explain me step by step. thank you!

    Yes it is not my image, you are right, I am sorry...
    I've decided not to continue this idea. So, case closed.
    Thank you to all of you, take care and best wishes
    cheers
    me

  • Please People Help Me With All Your Heart

    itunes want get my ipod like the source plane doesnt pop up can someone help me please i'm trying to put my new songs on my ipod please i will really appriated please

    try downloading that at apple web site
    i usually use that to detect my ipod if it cannot be detected
    by itunes then restore it
    ipod getting undetected was sometime cause by corrupted software
    if ipod updater failed to detect your ipod try bringing it to an apple service center

  • I am using Iphone 4... how to delete the updates in the app store icon? I dont want my updates to be there anymore.. pls help me with this.. the history in updates under the app store... thanks.

    I'm using Iphone 4. how to delete the stuff in UPDATES section from the app store icon pls??????

    The only way to do that is to delete the apps on your phone or update the apps.

  • HT1365 Hi can anyone help with this issue regarding my wireless magic mouse? When im on google chrome and scrolling down the page i always have youtube running in the background but the audio cuts/spits/pops can anyone help me with this?

    Hi can anyone help with this issue regarding my wireless magic mouse? When im on google chrome and scrolling down the page i always have youtube running in the background but the audio cuts/spits/pops can anyone help me with this?

    The figures you mention only make sense on your intranet.  Are you still using the same wireless router.  The verizon one is somewhat limited as far as max wireless-n performace.  For one thing it only has a 2.4 radio.   I like many people who wanted wireless-n performance before they even added a wireless-n gigabit router, have my own handling my wireless-n network.

  • I want to install xp on my MacBook Pro with i5 processor, but that creates the partition and restart the computer just stays in the following message: The Setup is inspecting your hardware configuration of your computer, someone can help me with this ?

    I want to install xp on my MacBook Pro with i5 processor, but that creates the partition and restart the computer just stays in the following message: The Setup is inspecting your hardware configuration of your computer, someone can help me with this ?

    The answer has not changed since your last post here https://discussions.apple.com/thread/3230576?tstart=0
    There are no XP or Vista drivers for the new Apple computer hardware. Apple stopped XP and Vista support. http://support.apple.com/kb/HT4410.

  • I bought a movie the movie Godzilla 2014 recently but it didn't show up in my library. I went check the itunes store and it wants me to buy it again. Please help me with this problem.

    I just bought this movie "Godzilla 2014" but it won't show in my Movie Library. I closed my Itunes and put it back on again but still won't show up. I checked my purchased list and it shows that I recently bought the movie but when I checked the itunes store it wants to buy the movie again. Please help me with this right away Apple.

    Apple Store Customer Service at 1-800-676-2775 or visit online Help for more information.
    To contact product and tech support: Contacting Apple for support and service - this includes
    international calling numbers..
    For Mac App Store: Apple - Support - Mac App Store.
    For iTunes: Apple - Support - iTunes.

  • "It is formatted incorrectly, or is not a format that iBooks can open". Can anyone help me with this message of a book that I purchased on iBooks, read, highlighted in the book and now I can't open it anymore. Please help!!!

    "It is formatted incorrectly, or is not a format that iBooks can open". Can anyone help me with this message of a book that I purchased on iBooks, read, highlighted in the book and now I can't open it anymore. Please help!!!

    Mine does the same thing occasionally, is your phone jailbroken? Sometimes it will work if you delete the book and reinstall it or put your phone into airplane mode then turn it back off.

Maybe you are looking for