Newbie help needed w/Graphics class!

Hi everyone,
I'm stuck on something I know is very simple to do, but I can't seem to find the right combination. I have a derived class that draws a circle using the graphics class. I'm getting compilation errors when I try to set the color and draw the circle. I have looked thru these forums as well as the API. Below is my code. Any pointers would be highly appreciated!
import java.awt.Graphics;
public class SmartCircle extends SmartShape
SmartCircle(int first, int second, int third, Color c)
super(first, second, third, c);
public void draw(Graphics g)
setColor(Color c);
fillOval(first, second, size, size);
}

Here is SmartShape. It is located in the same directory as SmartCircle, so therefore doesn't need to be imported, correct?
public abstract class SmartShape
//define instance variables
protected int positionX, positionY, size;
protected Color theColor;
public SmartShape()
     //initialize variables
     positionX = 20;
     positionY = 20;
     theColor = Color.white;
public SmartShape(int first, int second, int third, Color c)
     if (first >= 0)
     positionX = first;
     else
     positionX = 0;
     if (second >= 0)
     positionY = second;
     else
     positionY = 0;
     if (third >= 0)
     size = third;
     else
     size = 0;
     theColor = c;
public abstract void draw(Graphics g);
Hope that helps!
Melissa

Similar Messages

  • Java newbie help: Need to change a graphic on screen

    Hello everyone. I'm a long time C/C++ programmer, and I've been thrust into the Java world when I inherited an incomplete project. If something I mention later on sounds stupid, it's probably because it came that way, or I'm trying to force it into what I know from old experience.
    FWIW, the project is being developed with Netbeans.
    What I'm after is how to change a graphic object onscreen from within the code, vs. with a device such as a mouse. I'm trying to emulate an LED indicator.
    What I've done so far is to try using the enable state, and defining GIFs to display. That didn't work.
    I've switched gears a bit, and tried something similar with the selected property, but that will only work if I hit the item with my mouse and click. Also, the item is defined as a jToggleButton.
    In general terms, what do I need to do to set this up for the displayed item to change without device input? I've been reading stuff about Buttons, ToggleButtons, Graphics, Images, and Icons, and I'm waaaaaay lost right now.
    To add to the frustration is that I've done something similar with Visual C++, and that worked as intended. Harumph.
    Help?!?

    FWIW, the project is being developed with Netbeans.
    In case you don't know, you can use any editor to develop java code.
    What I'm after is how to change a graphic object onscreen from within the code, vs. with a device such as a mouse. I'm trying to emulate an LED indicator.
    What I've done so far is to try using the enable state, and defining GIFs to display. That didn't work.
    What happend?
    I've switched gears a bit, and tried something similar with the selected property, but that will only work if I hit the item with my mouse and click. Also, the item is defined as a jToggleButton.
    Is this not what you wanted?

  • Urgent Help Needed: ATI Graphics Card install

    Hello All.... I am in need of some urgent help..
    I am trying to install a new graphics card - the ATI Radeon 9600 SE. I currently have a Voodoo3 card. I followed all of the instructions step by step, but when I plug the monitor to the Radeon card and boot up, I do not get any display. I have tried everything I can think of, and yet - I am sure the card is secured in place and the monitor is plug into the card.
    Can anyone help me on this one.. ATI's support is, well - lacking..
    Here is some info on my pc:
    MCI motherboard
    AMD Athlon(tm) XP 2000+ 1.7 GHz
    768 MB
    AMIINT - 10 Version 1.00, 07/10/02
    Could the problem be with switching from a regular PCI card to an AGP card???

    Quote
    Originally posted by southmike
    okay i'll bite what are omega drivers,
    how are they different from cat4.2 drivers
    i was suprised that the voodoo 3 would work in a AMD64 mobo...
    whoops....just read the rest of the post :lol:
    BTW is there an external power connector that needs to be plugged in?

  • Newbie help needed with Applet

    I am having a problem with the following Applet. I have highlighted it in bold.
    How can I ensure that all of the conditions are met regardless of the order they are inserted on the graph,within the program?
    At the moment I have to do them in the exact order they are in the code in order to get the "Winner" message.
    Also if I insert an image at any time at the point if(x >= 290 && x <= 350 && y >= 290 && y <= 350) I also receive the "Winner" message. I realise this happens because it is the last line of code in this statement.
    However I am very new to this and dont know how to fix it. Indeed I dont even know if this is the correct way to do this.
    Hope this makes sense.
    Any help would be very much appreciated
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    public class MyDraughts extends Applet implements MouseListener,ActionListener,
                   MouseMotionListener{
                        public MyDraughts(){
                             points = new ArrayList();
                             pawncount = 0;
                             pawncount1 = 14;
                             message = "";
                             message1 = "";
                             title = new Font ("Arial", Font.BOLD, 18);
         private Point square1, square2, square3, square4, square5, square6, square7,square8,square9,
         square10,square11,square12,square13,square14,square15,square16,square17,square18,square19,
         square20,square21,square22,square23,square24,square25,square26,square27,square28,square29,
         square30,square31,square32,mouse;
         private int select;
         private Image pawn;
         private Point icon;
         private ArrayList points;
         private int x;
         private int y;
         private int pawncount;
         private int pawncount1,pawncount2;
         private Button undoButton;
         private String message,message1;
         private Font title;
         public void init(){
              setBackground(new Color(210,255,210));
              this.addMouseMotionListener(this);
              this.addMouseListener(this);
              select = 0;
              square1=new Point(50,10);
              square2=new Point(130,10);
              square3=new Point(210,10);
              square4=new Point(290,10);
              square5=new Point(10,50);
              square6=new Point(90,50);
              square7=new Point(170,50);
              square8=new Point(250,50);
              square9=new Point(50,90);
              square10=new Point(130,90);
              square11=new Point(210,90);
              square12=new Point(290,90);
              square13=new Point(10,130);
              square14=new Point(90,130);
              square15=new Point(170,130);
              square16=new Point(250,130);
              square17=new Point(50,170);
              square18=new Point(130,170);
              square19=new Point(210,170);
              square20=new Point(290,170);
              square21=new Point(10,210);
              square22=new Point(90,210);
              square23=new Point(170,210);
              square24=new Point(250,210);
              square25=new Point(50,250);
              square26=new Point(130,250);
              square27=new Point(210,250);
              square28=new Point(290,250);
              square29=new Point(10,290);
              square30=new Point(90,290);
              square31=new Point(170,290);
              square32=new Point(250,290);
              undoButton = new Button("Undo");
    add(undoButton);
    undoButton.addActionListener(this);
              mouse= new Point();
              icon = new Point();
              pawn = getImage(getCodeBase(), "pawn.gif");
    public void actionPerformed(ActionEvent actionevent){
    if(actionevent.getSource() == undoButton){
    int a = points.size();
    int b = a - 1;
    points.remove(b);
    a = points.size();
    repaint();
    public void paint (Graphics g){
         drawBox(g);
         g.fillRect(square1.x, square1.y,40,40);
         g.fillRect(square2.x, square2.y,40,40);
         g.fillRect(square3.x, square3.y,40,40);
         g.fillRect(square4.x, square4.y,40,40);
         g.fillRect(square5.x, square5.y,40,40);
         g.fillRect(square6.x, square6.y,40,40);
         g.fillRect(square7.x, square7.y,40,40);
         g.fillRect(square8.x, square8.y,40,40);
         g.fillRect(square9.x, square9.y,40,40);
         g.fillRect(square10.x, square10.y,40,40);
         g.fillRect(square11.x, square11.y,40,40);
         g.fillRect(square12.x, square12.y,40,40);
         g.fillRect(square13.x, square13.y,40,40);
         g.fillRect(square14.x, square14.y,40,40);
         g.fillRect(square15.x, square15.y,40,40);
         g.fillRect(square16.x, square16.y,40,40);
         g.fillRect(square17.x, square17.y,40,40);
         g.fillRect(square18.x, square18.y,40,40);
         g.fillRect(square19.x, square19.y,40,40);
         g.fillRect(square20.x, square20.y,40,40);
         g.fillRect(square21.x, square21.y,40,40);
         g.fillRect(square22.x, square22.y,40,40);
         g.fillRect(square23.x, square23.y,40,40);
         g.fillRect(square24.x, square24.y,40,40);
         g.fillRect(square25.x, square25.y,40,40);
         g.fillRect(square26.x, square26.y,40,40);
         g.fillRect(square27.x, square27.y,40,40);
         g.fillRect(square28.x, square28.y,40,40);
         g.fillRect(square29.x, square29.y,40,40);
         g.fillRect(square30.x, square30.y,40,40);
         g.fillRect(square31.x, square31.y,40,40);
         g.fillRect(square32.x, square32.y,40,40);
         g.setFont(title);
         g.drawString(message, 350, 300);
         g.drawString(message1, 350, 320);
         for(int i = 0; i < points.size(); i++){
    icon = (Point)points.get(i);
    g.drawImage(pawn, icon.x, icon.y, 25, 25, this);
         g.drawImage(pawn,175,135,25,25,this);
         g.drawImage(pawn,135,175,25,25,this);
         g.setFont(title);
         g.drawString("Click A Square To Place A Pawn", 350, 50);
    public void mouseDragged(MouseEvent e){}
    public void mouseMoved(MouseEvent e){}
    //require for the interface
    public void mousePressed(MouseEvent mouseevent){
    setBackground(new Color(210,255,210));
    x = mouseevent.getX();
    y = mouseevent.getY();
    if(x > 19 && x < 312 && y > 19 && y < 312){
    pawncount = pawncount + 1;
    points.add(mouseevent.getPoint());
    if(pawncount > pawncount1){
    setBackground(Color.red);
    message = "Too Many Pawns!You can only place 14";
    message1 = "Hit restart to play again";
    pawncount1 = 14;
    if(x >= 10 && x <= 50 && y >= 290 && y <= 330){
    setBackground(Color.red);
    message = "A Pawn Can't be placed here";
    pawncount = 15;
    if(x >= 50 && x <= 90 && y >= 250 && y <= 290){
    setBackground(Color.red);
    message = "A Pawn Can't be placed here";
    pawncount = 15;
    if(x >= 90 && x <= 130 && y >= 210 && y <= 250){
    setBackground(Color.red);
    message = "A Pawn Can't be placed here";
    pawncount = 15;
    //This is the solution for the puzzle
    if(x >= 90 && x <= 130 && y >= 10 && y <= 50);
    if(x >= 250 && x <= 290 && y >= 10 && y <= 50);
    if(x >= 90 && x <= 130 && y >= 50 && y <= 90);
    if(x >= 170 && x <= 210 && y >= 50 && y <= 90);
    if(x >= 10 && x <= 50 && y >= 90 && y <= 130);
    if(x >= 50 && x <= 90 && y >= 90 && y <= 130);
    if(x >= 250 && x <= 290 && y >= 130 && y <= 170);
    if(x >= 50 && x <= 90 && y >= 170 && y <= 210);
    if(x >= 210 && x <= 250 && y >= 210 && y <= 250);
    if(x >= 290 && x <= 350 && y >= 210 && y <= 250);
    if(x >= 10 && x <= 50 && y >= 250 && y <= 290);
    if(x >= 130 && x <= 170 && y >= 250 && y <= 290);
    if(x >= 210 && x <= 250 && y >= 290 && y <= 350);
    if(x >= 290 && x <= 350 && y >= 290 && y <= 350){
    setBackground(Color.green);
    message = "Winner";
    pawncount = 14;
    repaint();
    //required for the interface
    public void mouseClicked(MouseEvent event){}
    public void mouseReleased(MouseEvent event){}
    public void mouseEntered(MouseEvent event){}
    public void mouseExited(MouseEvent event){}
    public void drawBox(Graphics g){
         for(int i=10;i<=350;i+=40){
    g.drawLine(i,10,i,330);
    g.drawLine(10,i,330,i);
    }

    Since your code is heavilly dependant on which square is clicked on I'd define a class extending JComponent to represent a square. You can make this an inner class, which would simplify access to other squares etc. Then lay these out in your JPanel, and each will have it's own paint method which will paint it with or without a pawn.
    At the same time you add all these as a two dimensional array for logical access. Each square has (or is) it's own mouseListener so that you can let awt figure out which you clicked on.
    private static final int CELL_SIZE=50;
    private static final int BOARD_SIZE= 8;
    private class Square extends JComponent implements MouseListener {
        public boolean hasPawn;
        private Square(int row, int col) {
             Rectangle where = new Rectangle(col * CELL_SIZE, row * CELL_SIZE,
    CELL_SIZE, CELL_SIZE);
            setBounds(where);
           addMousListener(this);
       public void addPawn() {
         if(!hasPawn) {
           hasPawn = true;
           repaint();
      public void paint(Graphics g) {
    } // end of inner class
    Square[][]board = new Square[BOARD_SIZE][BOARD_SIZE];}

  • Help Needed - 2 graphics cards

    I just bought a Radeon ATI 1900 G5 edition online for my PowerMac G5. I already have a GeForce 7800GT as the primary card but I thought the new card would double the performance. I also thought installation would be as simple as popping in the new card. Obviously I should've done my homework a little better.
    Each card seems to need the extra power connection from the motherboard, but as far as I can tell, there is only one power cord.
    What to do?
    I run FCP5, Photoshop, and AfterEffects and I want as much graphics horse-power as the G5 will give me.
    Is it possible to have both of these cards installed?
    Advisable?
    If so, how do I do it? Can one of them run without the external power cord? I assume I would use slots 1 and 3?
    Please shed some light for me. I feel silly for having bought the card as it seems it may not help my situation. The customer service guy gave me the impression it was going to work fine.
    Anyway, please give me some feedback soon if possible as I'm anxious to try out the new set-up.
    Many thanks
    S

    So you're saying that two graphics cards would in no
    way boost performance in graphics apps like PS, AE,
    or FCP?
    Some PCs use multiple graphics cards with SLI to increase performance, but Macs do not support this.
    That the only reason people use multiple
    cards is to have many monitors?
    Correct (at least for a Mac).
    I thought the extra VRAM would help with my rendering
    and real-time effects, no?
    The extra VRAM is on a different card, and without SLI to connect the cards, there is no way it can be used.
    Ever heard of anyone somehow using two cards?
    Not two high power cards,
    Do they make a splitter for the power connection?
    No. You would have to make your own. It wouldn't be too hard to splice two power cables.
    Or is it risky to have two cards running for power reasons?
    The total power consumption would probably be OK, but only slot 1 is rated for high power cards, and the auxiliary power was only planned for one card
    Or could the NVIDIA run without the power connection from slot 3?
    No. It can't even do that in slot 1, which provides a lot more power than slot 3.
    I have no other PCI cards in there so I would run two
    if there was any benefit to be had.
    With no other cards, there is probably enough power, but it is spread over the low power slots 2, 3, and 4.
    But I am only using two 23" monitors so maybe there isn't.
    The extra card would just be using power and producing heat.

  • Help needed with collection classes

    Howdie all,
    I'm new to Java, and for the most part, I can do it.
    I'm stuck on how to do the following:
    I have to write a program that simulates a deck of cards, including shuffling (involving cards are re-collected), dealing cards. I have to create 52 objects of the card class. The only things that I can use involve some of the collection classes (arrays, dynamic lists, vectors, dictionaries), queues/stacks
    I dont know:
    ** what to use. should i use a dyn list or a vector
    **how the heck would i shuffle the cards?
    ** for dealing the cards, i figued i would just use a loop to draw a set of cards (face and suit)
    i am not asking for code on how to do it (though pseudo-code/alogorithm may help). i just dont know where to start..i am totally stuck.
    thanks a bunch!

    I would suggest you to use the LinkedList class for the deck representation.
    To create the cards you could use
    for i = 0 to 51
    new Card(i);
    In Card constructor do something like
    int colour = i/13+1; // (1-4, one for each colour)
    int value = i%13+1; // (1-13, ace-king)
    To shuffle you could
    for i = 0 to 100
    j = radom(52)
    k = random(52)
    swap(card#j, card#k)
    This will swap 2 random cards 100 times.
    To draw cards
    Card c = cards.remove(0)
    or
    Card c = cards.remove(radom(cards.size()))
    In the later, the shuffle part is not really needed.
    thought about this some more and now i have another
    question:
    when using a dyn linked library, i am not even sure
    how to create the 52 objects. previously when doing
    project like this, i just used a random function to
    generate the cards, and used switch statements for the
    non-numbered cards and for the suite. how would i do
    accomplish this when using a collection class?
    Howdie all,
    I'm new to Java, and for the most part, I can do it.
    I'm stuck on how to do the following:
    I have to write a program that simulates a deck of
    cards, including shuffling (involving cards are
    re-collected), dealing cards. I have to create 52
    objects of the card class. The only things that Ican
    use involve some of the collection classes (arrays,
    dynamic lists, vectors, dictionaries),queues/stacks
    I dont know:
    ** what to use. should i use a dyn list or avector
    **how the heck would i shuffle the cards?
    ** for dealing the cards, i figued i would just usea
    loop to draw a set of cards (face and suit)
    i am not asking for code on how to do it (though
    pseudo-code/alogorithm may help). i just dont know
    where to start..i am totally stuck.
    thanks a bunch!

  • Help needed regarding Scanner class

    hello
    i'm really desperate for help, i'll mention that this is homework,but i need a small guidance.
    i need to code a calculator,we need to use the Scanner class to break the expression to tokens(we CANNOT use other classes).
    my main problem is about getting those tokens from the input string.
    i tried breaking a string to tokens for hours but just couldnt do it.
    a legal expression is something like:
    xyzavbx1111+log(abc11*(2+5))+sin(4.5)
    iilegal is : xx333aaaa111+2 or log()+2
    where the alphanumerics are variables(sequence of letters followed by numbers)
    i managed to get the tokens out of a string that looks like that:
    String expression = "ax11111+32/3+4*2^2"
    by doing:
    _token = new Scanner(expression);
    while(hasNext(_token)) getNextToken(_token,"\\d+(\\.\\d+)?|(\\+)|(\\-)|(\\*)|(\\/)|(\\^)|([a-zA-Z]+(\\d+));
    public static boolean hasNext(Scanner s) {
    return s.hasNext();
    public static String getNextToken(Scanner s,String str) {
    return s.findInLine(str);
    but i can't get the tokens when i have sin ,cos or log in the expression
    either it just ignores it or i'm looping infinitely.
    my question is how can i make the regular expression include the sin log and cos?
    I also know that when i'll use the "matches" method ,i'll be able to spot illegal arguments like 5//2+ because it doesnt match the pattern.
    so any help conecrning the regular expression would be great thanks alot.

    thx , but i already got it,after trying tons of combinations
    i'll post the format i used in case someone will find this thread in the future ,while looking for something similar
    the format is:
    "(\\s)|(log)|(sin)|(cos)|(\\d+(\\.\\d+)?)|(\\+)"+
    "|(\\-)|(\\*)|(\\/)|(\\^)|([a-zA-Z]+(\\d+))|(\\()|(\\))|(\\s)";
    which includes white spaces between arguments and operators

  • Creating GUI window. Newbie help needed

    Hey all this is the first time i am building a GUI box for school. Can you kind of help me out here. I think i am doing this all wrong. Can you point me in the direction of setting up a Blank box just so i can then play with it from there trying to add JButtons, JLabels and all that other stuff. This is what i was trying and i know its way wrong.. haha thanks
    import java.io.*;
    import javax.swing.*;
    public class LetterProgram
    public LetterProgram
    setTitle("Letter Conversion Program");
    setSize(100,50);
    setVisible(True);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    }

    import javax.swing.*;
    public class MyJFrame extends JFrame {
      private int returnCode = 0;
      public MyJFrame () {
      public MyJFrame (String title) {
        super (title);
      protected void frameInit() {
        super.frameInit();
        setDefaultCloseOperation(EXIT_ON_CLOSE);
    }You should start from here.
    put every thing u want into ExitableJFrame's constructor.
    You will need a main method to creat a JFrame.
    and then setVisiable(true); some sort of stuff there.
    GOOD LUCK

  • Help needed, corrupted graphics all system

    Hello
    I need help, I have a mac pro 2008, and since some time I am experiencing corrupted graphics all over the system. The computer starts operating properly, suddenly, and looks like when I start using graphics intensice application, such as after effects, I get graphics corrupted on finder, pictures, the programs etc to a point where not even thumbnails show up properly. Restarting solves the problem however not for long.
    Now I now this theoretically and the most obvious answer "is the graphic card" however I have changed the whole computer, different mac, different and new graphics card and I get the same problem. Even the RAM is different however the problem persist. The only thing that was carried from the older mac was the hard drives. The OS is the latest version of 10.10 and this problem was also with the earlier 2 versions, mountain lion and Mavericks.
    Please look at the screenshots I am providing, evidently this is a software issue otherwise it would have been fixed after I changed mac.
    Anybody has any idea what the problem could be?
    Any help would be appreciated.

    Yes, but the thing is that those corrupter graphics also make it onto a video that I do, for example. so its not a screen issue, you see what I mean? like 2 days ago I was making a video in after effects and premiere and those corrupted issues made it onto the rendered video, the pixelated things.

  • Newbie help needed.  Looking to circle options on a form.

    Hey Guys,
    I'm a total beginner at this, but we've been mapping out forms and I need to know how to be able to "circle" different options on a form.
    I think the best way to do this is to have a button which makes a circle object visible or hidden.  Currently I've figured out how to set an object as hidden and make it appear on button click, but not make it go back to hidden if the button is clicked again.  Many times its just a yes/no type case, but sometimes there are cases where I have multiple options where only one can be selected and I would like to be able to click and circle the appropriate type.
    An example:
    How many cylinders does your vehicle have:
         4     6     8
    and I would like to make it so if you click the 4 it will circle the 4 and make sure the 6 and 8 are not circled.
    Any help would be appreciated.

    How about this case:
    There are three different cases that could be true, 4 cylinders, 6 cylinders and 8 cylinders.  I have created the 4, 6 and 8 as buttons, and created three circle objects as cyl4, cyl6 and cyl8.  I want it so that when 4 is clicked it displays the circle object cyl4 and makes the others hidden, unless cyl4 is already visible then it will just make all three objects hidden.  So far I have this code on each button click, modified for which objects should be set to visible on each one:
    topmostSubform.Page1.Span[41].Fourcyl::click - (JavaScript, client)
    if (cylinder == 4){
        xfa.form.topmostSubform.Page1.cyl4.presence="hidden"
        xfa.form.topmostSubform.Page1.cyl6.presence="hidden"
        xfa.form.topmostSubform.Page1.cyl8.presence="hidden"
        cylinder.value = 0
    else{
        xfa.form.topmostSubform.Page1.cyl4.presence="visible"
        xfa.form.topmostSubform.Page1.cyl6.presence="hidden"
        xfa.form.topmostSubform.Page1.cyl8.presence="hidden"
        cylinder.value = 4
    Where cylinder is just a control variable.  It's probably something simple that I'm missing, any help would be appreciated.
    Thanks

  • Newbie - help needed with array and dictionary objects

    Hi all
    Please see the code below. I've posted this code in another thread however the original issue was resolved and this is now a new issue I'm having although centered around the same code.
    The issue is that I'm populating an array with dictionary objects. each dictionary object has a key and it's value is another array of custom objects.
    I've found that the code runs without error and I end up with my array as I'm expecting however all of the dictionary objects are the same.
    I assume it's something to do with pointers and/or re-using the same objects but i'm new to obj-c and pointers so i am a bit lost.
    Any help again is very much appreciated.
    // Open the database connection and retrieve minimal information for all objects.
    - (void)initializeDatabase {
    NSMutableArray *authorArray = [[NSMutableArray alloc] init];
    self.authors = authorArray;
    [authorArray release];
    // The database is stored in the application bundle.
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *path = [documentsDirectory stringByAppendingPathComponent:@"books.sql"];
    // Open the database. The database was prepared outside the application.
    if (sqlite3_open([path UTF8String], &database) == SQLITE_OK) {
    // Get the primary key for all books.
    const char *sql = "SELECT id, author FROM author";
    sqlite3_stmt *statement;
    // Preparing a statement compiles the SQL query into a byte-code program in the SQLite library.
    // The third parameter is either the length of the SQL string or -1 to read up to the first null terminator.
    if (sqlite3preparev2(database, sql, -1, &statement, NULL) == SQLITE_OK) {
    // We "step" through the results - once for each row.
    // We start with Letter A...we're building an A - Z grouping
    NSString *letter = @"A";
    NSMutableArray *tempauthors = [[NSMutableArray alloc] init];
    while (sqlite3_step(statement) == SQLITE_ROW) {
    author *author = [[author alloc] init];
    author.primaryKey = sqlite3columnint(statement, 0);
    author.title = [NSString stringWithUTF8String:(char *)sqlite3columntext(statement, 0)];
    // FOLLOWING WAS LEFT OVER FROM ORIGINAL COMMENTS IN SQLBooks example....
    // We avoid the alloc-init-autorelease pattern here because we are in a tight loop and
    // autorelease is slightly more expensive than release. This design choice has nothing to do with
    // actual memory management - at the end of this block of code, all the book objects allocated
    // here will be in memory regardless of whether we use autorelease or release, because they are
    // retained by the books array.
    // if the author starts with the Letter we currently have, add it to the temp array
    if ([[author.title substringToIndex:1] compare:letter] == NSOrderedSame){
    [tempauthors addObject:author];
    } // if this is different letter, then we need to deal with that too...
    else {
    // create a dictionary to store the current tempauthors array in...
    NSDictionary *tempDictionary = [NSDictionary dictionaryWithObject:tempauthors forKey:@"authors"];
    // add the dictionary to our appDelegate-level array
    [authors addObject:tempDictionary];
    // now prepare for the next loop...
    // set the new letter...
    letter = [author.title substringToIndex:1];
    // remove all of the previous authors so we don't duplicate...
    [tempauthors removeAllObjects];
    // add the current author as this was the one that didn't match the Letter and so
    // never went into the previous array...
    [tempauthors addObject:author];
    // release ready for the next loop...
    [author release];
    // clear up the remaining authors that weren't picked up and saved in the "else" statement above...
    if (tempauthors.count > 0){
    NSDictionary *tempDictionary = [NSDictionary dictionaryWithObject:tempauthors forKey:@"authors"];
    [authors addObject:tempDictionary];
    else {
    printf("Failed preparing statement %s
    ", sqlite3_errmsg(database));
    // "Finalize" the statement - releases the resources associated with the statement.
    sqlite3_finalize(statement);
    } else {
    // Even though the open failed, call close to properly clean up resources.
    sqlite3_close(database);
    NSAssert1(0, @"Failed to open database with message '%s'.", sqlite3_errmsg(database));
    // Additional error handling, as appropriate...
    Message was edited by: dotnetter

    Ok, so I know what the issue is now...I just don't know enough to be able to resolve it!
    it's the tempAuthors objects.
    It's an NSMutableArray which is create on the line before the start of the WHILE loop.
    Having looked through the debugger, I can see that each dictionary object is created (with different codes which I assume are memory addresses) so all is well there. However, on each iteration of the loop in the middle there is an IF...ELSE... statement which in the ELSE section is clearing all objects from the tempAuthors array and beginning to repopulate it again.
    Looking at the containing dictionary objects in the debugger I can see that the tempAuthors object that each contains has the same code (again, I'm assuming this is a memory address) - so if I understand correctly, it's the same object...I assumed that when I created the dictionary using the dictionWithObject call that I would be passing in a copy of the object, but it's referencing back to the object which I then go on to change.
    Assuming the above is correct, I've tried several "stabs in the dark" at fixing it.
    I've tried relasing the tempAuthors object within the ELSE and initialising it again via an alloc...init - but this didn't work and again looking through the debugger it looks as though it was confused as to which object it was supposed to be using on the following iteration of the WHILE loop (it tried to access the released object).
    Having read a little more about memory management can someone tell me if I'm correct in saying that the above is because the tempAuthors object is declare outside the scope of the WHILE loop yet I then try to re-instantiate it within the loop (does that make sense???).
    Sorry for the long post...the more I can understand the process the less I can hopefully stop relying on others for help so much.
    I am continuing to read up on memory management etc but just not there yet.
    Regards
    Wayne

  • Newbie - Help needed starting with Threads

    Hi Friends,
    I have a class which extends thread and all it does is displays its name and then goes to sleep. So, I have this in my run method:
    public void run() {
            System.out.println("Name: "+name);
            try{
                 Thread.sleep(1000);
            }catch(Exception e){
              e.printStackTrace();
        }Now I have a tester class which created objects of these class and they should keep running until the user explicitly stops the program. So, I have this in my tester class:
    Thread one = new MyClass("one");
    Thread one = new MyClass("two");
    one.start();
    two.start();They run fine for one time but how can i make them run continously?? Any help will be appreciated.
    Thanks

    Micks80 wrote:
    I tried to add that while loop but it throws IllegalStateException because I guess you cannot call the start method more then once...
    So any other ways to accomplish this???As suggested in reply #1 put the while loop inside the run method of the Runnable.
    Also it is better for MyClass to implement Runnable rather than extending Thread. It is always better to implement Runnable than extend Thread.

  • Help needed with SimpleDateFormat class

    I am trying to do this:
    try {
    SimpleDateFormat df = new SimpleDateFormat("MM/dd/yyyy");
    expirationDate = df.parse(expirationDateStr);
    }catch (ParseException e)
    The problem I am having is it takes in dates like 15/6/2004 and converts it into 3/6/2005. Doesn't java provide validation for that? Do I need to do the validation myself for months and dates?
    Your help is appreciated. Thanks!

    Cool Thank you..That worked..

  • Help Need in Graphical Mapping.

    Hi
    Can you do help for mapping between my file structure to BAPI structure..this is auctully  file would call BAPI for 1: N(file having various headers and line items, each header and associated line items would able to call BAPI in target side).
    Now i am just trying to do test using following map...but following error came when i am checking in IM. But when i am doing test this map in MM editor using Duplicate subtree it is working fine.
    <b>ERROR: Mapping program Message Mapping MM_request | urn:testing does not match the interface mapping. The number or frequencies of source or target messages for the message mapping are not identical to the number or frequencies of source or target interfaces.</b>
    I thought some where i made wrong..!but it is difficult to find out for me! i dint find any wrong in my mapping.
    map like this:
    Sourcefilestructure:       TargetBAPI
    Messages (1:1)            Message(1:1)
    Message1(1:1)             Message1(1:1)
      MT_Request(1:1)  
       Recordset(0:U) -->     BAPI_INCOMINGINVOICE(0:U)
        HDR   (0:1)            HeaderData(1:1)
         Filed(0:1)   -->       filed1(0:1)
         Field(0:1)   -->       field2(0:2)  
                    HDR--->   GLACCOUNTDATA(0:1)
         LINEITEM(0:U)--->      item(0:U)    
           field1(0:1) --->       field(0:1)
           field2(0:1) --->       field2(0:1)
    Thanks,
    Regards
    Sankar!
    Message was edited by: Sankar

    Hi,
    You have this error message when inside your Interface Mapping you uses occurences which are NOT these one defined in your Message Mapping.
    In your Message Mapping, look at tab "Message" and keep in mind the occurence.
    Then in your Interface Mapping, do the same action and compare both occurence.
    Mickael
    Message was edited by: Mickael Huchet

  • NEWBIE - Help Needed Please!

    Hi - I am new to iMovie and have iMovie '08. I need to create a project as follows. I am trying to recreate some movies that when played will look like a Trade Test Transmission with music. Viz:
    The movie needs to be a static caption that lasts for about 1 hour
    That caption exists as as a .jpg file.
    I need to play an hour's worth of music with that caption
    I can import the picture and add music but I cannot work out how to make the picture stay on screen for 1 hour - is there a simple way of doing this?
    Sorry for such an easy question - iMovie is about the only Apple Software I have never used!
    Christian

    .. The maximum length it will allow me to enter seems to be 60 seconds. ...
    oops, you're right!
    I'm an old iM user, vers. ≤6 allowed longer durations than 60secs..
    the '4 sec increment' is defined in iM's prefs, you'll find there a slider, but it offers 10sec max. ...-
    soooo, 60x paste/copy, OR using iMHD6 ...
    Plan B)
    import your pic into iPhoto; create a slideshow containing just that single pic... set duration to 3600secs.. add music .. export 'movie' ...

Maybe you are looking for

  • Is it possible to sort text/imessages in alphabetical order??

    Is it possible to sort text/iMessages into alphabetical order instead of just by date??  Would be great to have the option to sort by different filters or even to initiate a search of a particular subject/word or persons name.

  • Problems with my Samsung Galaxy S3

    The last couple of days my signal strength has been almost non-existent. Used to have 4-5 bars pretty much everywhere I go but now only getting 1-2 at best and no service at all at my house. Signal strength sitting at my desk fluctuates to a low of -

  • [Solved] dwb can't display HTML5 videos

    Hello, I have discovered dwb, which really interests me as a lightweight alternative to massive browsers such as Chromium. However, I don't use Flash (bleeehhhh), and I've discovered that I could not display HTML5 videos (only with dwb, that is, beca

  • E-mail Subject Line

    I am using LC8 and I have created a form with a submit button for e-mail. I used the regular button instead of the e-mail from the previous posts that I have read. I have it set to "mailto:" so the user filling out the form will need to enter the e-m

  • How to install two monitors--

    -HP pavilion h8xt, two acer monitors (w. both vga and dvi  and also an add'l dvi   plug on the graphics card. Monitors came with a double ended dvi cord. Can I plug one monitor into the dvi of the graphic card and the other monitor  into the other dv