New to java - glitch in my program/game? should be a simple fix :)

hey everyone, I'm a student who's new to java programming :) It's is also the first programming language that I'm learning. I know the basics, but nothing very complicated.
I'm making a pong-like game, in an applet.
As I was making the paddle and using a mouselistener to make it move vertically, I came across this problem, the paddle will move vertically with the mouse's position, but one end of my paddle will grow abnormally (I want it to stay the same size as it moves up and down)
Here's my code: (I'm not using most of the mouselistener and keylistener classes yet, so you can ignore them. I'm guessing the problem is probably in one of the last classes, at the bottom)
ypaddle is the variable used for getting the co-ordinates of the mouse and transferring them to the paddle itself
// The "Ping" class.
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
*Ping
public class Ping extends Applet
    implements KeyListener, MouseListener, MouseMotionListener
    int width, height, x, ypaddle;
    Graphics g;
    char move;
     *Initializes variables
    public void init ()
        resize (700, 500);
        setBackground (Color.white);
        addKeyListener (this);
        addMouseListener (this);
        addMouseMotionListener(this);
    public void keyPressed (KeyEvent e)
    public void keyReleased (KeyEvent e)
    public void keyTyped (KeyEvent e)
    public void mouseEntered (MouseEvent e)
    public void mouseExited (MouseEvent e)
    public void mousePressed (MouseEvent e)
    public void mouseReleased (MouseEvent e)
    public void mouseClicked (MouseEvent e)
    public void mouseMoved (MouseEvent e)
        ypaddle = e.getY ();
        repaint();
    public void mouseDragged (MouseEvent e)
    public void paint (Graphics g)
        paddle (g, ypaddle);
     * Creates the paddle for hitting the ball
     *@param    y   value used to move the paddle vertically
    public void paddle (Graphics g, int y)
        g.fillRect (10, 10+y, 15, 60+y);
} // Ping classI'm totally stumped, I've tried for 2 hours to find the problem, and I have a feeling it's something very simple that I'm passing over...
If you have any questions about the variables or other things, please ask!
And one last little quick question, is there a way I can restrict the movement of the paddle between two Y values? (i.e not higher than y=10 or lower than y=100)
Thanks in advance :)

soundweave wrote:
I'm not exactly sure how to find out, Eh?
You wrote this code:
g.fillRect (10, 10+y, 15, 60+y);Do you understand what fillRect does? If I call fillRect(10, 20, 30, 40) where will that rectangle be drawn? If you don't know how to answer that, I don't see how you could have written that line of code.
but here's some pictures of what happens ( I put in 0 and 80 as the y values in each picture, and left the code window open so you can see )I don't need to see them.
Y at 0: [http://i731.photobucket.com/albums/ww314/len56/Untitled.jpg?t=1263077701|http://i731.photobucket.com/albums/ww314/len56/Untitled.jpg?t=1263077701]
Y at 80: [http://i731.photobucket.com/albums/ww314/len56/Untitled2.jpg?t=1263077625|http://i731.photobucket.com/albums/ww314/len56/Untitled2.jpg?t=1263077625]
So, given that the first one comes from fillRect(10, 10, 15, 60), (you get where that comes from I hope) and the second comes from fillRect(10, 90, 15, 150) (that too), does that not suggest that something is wrong with the numbers you're passing to fillRect? And since you have read the docs for fillRect and know what it does and what each of its parameters represents (right?), does it not suggest exactly what is wrong with those numbers?

Similar Messages

  • New to Java...Tough program to write I think...

    Alright, I have a problem. I have never coded in java before, but a teacher wants a program written that is too much for html/php/VB to handel, and a friend suggestion I use java.
    my problem is that I have never coded in Java before, but supposidly because its object oriented, the language should make the program easier to write.
    The program is a "Group Generator"
    Anyway, here is what the teacher wants:
    Step 1) Program Asks user how many students are in his class, and how many students he wants in each group
    Step 2) Program Asks user the names of all X students
    Step 3) Program makes a list of every combination of groups that can be made out of these X people (never repeating 2 people in a group)
    Step 4) Program outputs results
    Here is a quick example because I know its confusing
    10 kids in my class, groups of 2
    Group Set 1:
    1: AB
    2: CD
    3: EF
    4: GH
    5: IJ
    Group Set 2:
    1: AC
    2: BD
    3: GF
    4: IH
    5: EJ
    and the program would keep finding sets of unique grounds...but A will never be grouped with B again, or C again...so the ammount of group sets is actually quite low.
    Anway, this isnt for a grade or anything, its just something some teacher wants and I think would help teachers a bit in forming unique grounds of kids....
    Any input or ideas would be GREATLY appriciated :-)

    Alright, I have a problem. I have never coded in java
    before, but a teacher wants a program written that is
    too much for html/php/VB to handel, and a friend
    suggestion I use java.HTML is markup, so it won't be of much use. However, PHP, VB, and a host of other languages can handle this easily. Write it using the language with which you are comfortable.
    If you want to learn Java, however, here are some good resources...
    Your First Cup of Java - http://java.sun.com/docs/books/tutorial/getStarted/cupojava/index.html
    Essentials, Part 1, Lesson 1: Compiling & Running a Simple Program - http://java.sun.com/developer/onlineTraining/Programming/BasicJava1/compile.html
    The Java Tutorial - A practical guide for programmers - http://java.sun.com/docs/books/tutorial/
    New to Java Center - http://java.sun.com/learning/new2java/index.html
    How To Think Like A Computer Scientist - http://www.ibiblio.org/obp/thinkCSjav/
    Introduction to Computer Science using Java - http://chortle.ccsu.ctstateu.edu/CS151/cs151java.html
    The Java Developers Almanac 1.4 - http://javaalmanac.com/
    JavaRanch: a friendly place for Java greenhorns - http://www.javaranch.com/
    jGuru - http://www.jguru.com
    Object-Oriented Programming Concepts - http://java.sun.com/docs/books/tutorial/java/concepts/
    Object-oriented language basics - http://www.javaworld.com/javaworld/jw-04-2001/jw-0406-java101.html
    Don't Fear the OOP - http://sepwww.stanford.edu/sep/josman/oop/oop1.htm
    Books:
    Bert Bates and Kathy Sierra's Head First Java - http://www.amazon.com/exec/obidos/tg/detail/-/0596004656?v=glance
    Bruce Eckel's Thinking in Java (Free online) - http://mindview.net/Books/DownloadSites
    Joshua Bloch's Effective Java - http://www.amazon.co.uk/exec/obidos/Author=Bloch,%20Josh
    Java Design: Building Better Apps and Applets (2nd Edition) - http://www.amazon.com/exec/obidos/tg/detail/-/0139111816/qid=1101309882/sr=8-7/ref=sr_8_xs_ap_i7_xgl14/104-6417153-1511164?v=glance&s=books&n=507846

  • New to Java, want to create a game any help appreciated.

    I just downloaded java Studio. I would like to create Java games. Not sure where to start.. Do i need more programs? Any info would be of great help thanks....

    Hey,
    If you want to know which software you need to program java games (or any other java application for that matter), I'm guessing you don't have much experience using java.
    First, to answer your question, Studio will certainly do to create java. But even notepad will suffice. The only thing you really need to have is a SDK, you can get it from the Sun site.
    Second, You should ask yourself if java is the language to program in. Java is well suited for developing games. But it is also a very powerful general purpose language, so it can be very overwhelming. Maybe you should think of the alternatives?
    Flash: Has much better browser support than applets, so if you want to make an online game, this is probably a better choice. Don't be afraid of the possibilities in flash, unless you want to do 3d. You don't want do to 3d yet.
    PHP: if your game is text based, you might want to program it in PHP. It is mostly used for multi-user-"dungeons"(fill that in as you want).
    If you really want to learn how to program in java, I suggest you don't start on your game just yet. Try this PDF for starters: http://www.mindview.net/Books/TIJ/. The java tutorial is also pretty good, but cover the basics first: http://java.sun.com/docs/books/tutorial/ . I also suggest you don't start programming in an IDE(for you: Sun studio) until you start working with multiple classes. I suggest JEdit for "basic"(it has a million features, don't worry) programming. Later you can start to learn Sun Studio (Or Eclipse, if I can lodge in my preference), but be careful: these programs are excellent, and will spare you hours of work, but only if you spend (a lot) of time on how to use them properly.
    As a final thought: the web is your friend. There are tons of good resources on the web for developing games, and lots of them focus on java. A good place for info is http://www.gamedev.net/, lots of articles, and helpful hints on choosing language, tile games, etc... Another specific one is http://www.brackeen.com/javagamebook/. It has working code for a tile-based game, and it even has a software 3d engine. It also has good for for detecting mouse and keyboard actions. Get more experience before you start with these ones, though.
    Good luck!

  • What's new in Java 5 & 6 (Experience programming coming back)

    All -
    I've been away from Java for a year in the wonderful world of dynamic languages (ruby and python) but I've had 6+ years of Java coding experience. I've heard that Java 5 & 6 have added some pretty cool features like better for loops, block like structures, etc. I've been told that Java is starting to introduce features which give it a more "flexible" feel, similar to a dynamic language.
    Anyway, for someone coming back, can anyone give me a quick list of the new WOW features in Java 5 & 6 that I should be looking to use?
    Thanks,
    Drew

    Heh, not new but was a bit hopeful the the forum
    environment had changed in the last yearMaybe if less people came and posted open-ended vague questions that they should have started looking with Google for information about so they could ask more specific questions.....
    I mean I don't know. It was a dream I had once. Everyone was very nice here. People used google. Nobody pleaded for "teh codes". People used PreparedStatement. People stopped crossposting. Lazy students stopped lying.
    It was amazing.

  • Problem compiling program... Should be a simple fix!!!

    Exception in thread "main" java.lang.NoClassDefFoundError: Paint
    While trying to compile with the command 'java Paint fig.svg 300' (the following two are parameters) I get the error above.
    Paint is a user defined class with an empty constuct.
    The code compiles and works properly in Eclipse.
    import java.io.FileWriter;
    import java.util.Random;
    import java.io.PrintWriter;
    class Paint{
               static String fileWrite = "";
              private String setColor;
             public Paint( )
             private void open(int dimen, int dimen2)
                    fileWrite = "<svg xmlns=\"http://www.w3.org/2000/svg\"" +
                                   "xmlns:xlink=\"http://www.w3.org/1999/xlink\"" +
                                   "width=\"" + dimen + "%\"" +
                                   "height=\"" + dimen2 + "%\"" +
                                   "viewBox=\"0 0 150 150\"" +
                                   "version=\"1.0\">" +
                                   "<g>";
              private static String random255()
                   Random generator = new Random();
                   int s = generator.nextInt(256);
                   String s1 = Integer.toHexString(s);
                   return s1;
              private void setColor(String string)
                   this.setColor = string;
              private void rect(int i, int j, int k, int l)
                   fileWrite = fileWrite + "<rect x=\"" + i + "\"  y=\"" + j +
                   "\"  height=\"" + k + "\" width=\"" + l + "\" fill=\"" +
                   setColor + "/>";
              private void close()
                   fileWrite = fileWrite +  "</g>" + "</svg>";
        public static void main(String [] args)throws Exception{
            FileWriter fileWriter = new FileWriter( args[0] );
            PrintWriter out = new PrintWriter( fileWriter );
            int dimen = Integer.parseInt( args[1] );
            Paint paint = new Paint();
            paint.open(dimen,dimen);
            dimen = dimen / 2;
            int originX = dimen, originY = dimen;
            for(; dimen > 0; dimen = dimen - 3){
               String red = random255();
               String green = random255();
               String blue = random255();
               paint.setColor( "#" + red + green + blue );
               paint.rect(originX-dimen,originY-dimen,dimen*2,dimen*2);
            paint.close();
            out.print(fileWrite);
            out.close();
         }{code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    I like that reaction Edward :-) But it is strange that someone can write that many lines of Java code without knowing that you need to compile first before trying to execute.

  • New to Java and need help with this program..please!

    I'd really appreciate any helpful comments about this program assignment that I have to turn in a week from Friday. I'm taking a class one night a week and completely new to Java. I'd ask my professor for help, but we can't call him during the week and he never answers e-mails. He didn't tell us how to call from other classes yet, and I just can't get the darn thing to do what I want it to do!
    The assignment requirements are:
    1. Change a card game application that draws two cards
    and the higher card wins, to a Blackjack application
    2. Include a new class called Hand
    3. The Hand class should record the number of draws
    4. The application should prompt for a number of draws
    5. The game is played against the Dealer
    6. The dealer always draws a card if the dealer's hand total is <= 17
    7. Prompt the player after each hand if he wants to quit
    8. Display the total games won by the dealer and total and the total games wond by the player after each hand
    9. Display all of the dealer's and player's cards at the
    end of each hand
    10. Player has the option of drawing an additional card after the first two cards
    11. The Ace can have a value of 11 or 1
    (Even though it's not called for in the requirements, I would like to be able to let the Ace have a value of 1 or an 11)
    The following is my code with some comments about a few things that are driving me nuts:
    import java.util.*;
    import javax.swing.*;
    import java.text.*;
    public class CardDeck
    public CardDeck()
    deck = new Card[52];
    fill();
    shuffle();
    public void fill()
    int i;
    int j;
    for (i = 1; i <= 13; i++)
    for (j = 1; j <= 4; j++)
    deck[4 * (i - 1) + j - 1] = new Card(i, j);
    cards = 52;
    public void shuffle()
    int next;
    for (next = 0; next < cards - 1; next++)
    int rand = (int)(Math.random()*(next+1));
    Card temp = deck[next];
    deck[next] = deck[rand];
    deck[rand] = temp;
    public final Card draw()
    if (cards == 0)
    return null;
    cards--;
    return deck[cards];
    public int changeValue()
    int val = 0;
    boolean ace = false;
    int cds;
    for (int i = 0; i < cards; i++)
    if (cardValue > 10)
    cardValue = 10;
    if (cardValue ==1)     {
    ace = true;
    val = val + cardValue;
    if ( ace = true && val + 10 <= 21 )
    val = val + 10;
    return val;
    public static void main(String[] args)
    CardDeck d = new CardDeck();
    int x = 3;
    int i;
    int wins = 1;
    int playerTotal = 1;
    do {
    Card dealer = (d.draw());
    /**I've tried everything I can think of to call the ChangeValue() method after I draw the card, but nothing is working for me.**/
    System.out.println("Dealer draws: " + dealer);
    do {
    dealer = (d.draw());
    System.out.println(" " + dealer);
    }while (dealer.rank() <= 17);
    Card mine = d.draw();
    System.out.println("\t\t\t\t Player draws: "
    + mine);
    mine = d.draw();
    System.out.println("\t\t\t\t\t\t" + mine);
    do{
    String input = JOptionPane.showInputDialog
    ("Would you like a card? ");
    if(input.equalsIgnoreCase("yes"))
         mine = d.draw();
    System.out.println("\t\t\t\t\t\t" + mine);
         playerTotal++;
         else if(input.equalsIgnoreCase("no"))
    System.out.println("\t\t\t\t Player stands");
         else
    System.out.println("\t\tInvalid input.
    Please try again.");
    I don't know how to go about making and calling a method or class that will combine the total cards delt to the player and the total cards delt to the dealer. The rank() method only seems to give me the last cards drawn to compare with when I try to do the tests.**/
    if ((dealer.rank() > mine.rank())
    && (dealer.rank() <= 21)
    || (mine.rank() > 21)
    && (dealer.rank() < 22)
    || ((dealer.rank() == 21)
    && (mine.rank() == 21))
    || ((mine.rank() > 21)
    && (dealer.rank() <= 21)))
    System.out.println("Dealer wins");
    wins++;
         else
    System.out.println("I win!");
    break;
    } while (playerTotal <= 1);
    String stop = JOptionPane.showInputDialog
    ("Would you like to play again? ");
    if (stop.equalsIgnoreCase("no"))
    break;
    if (rounds == 5)
    System.out.println("Player wins " +
    (CardDeck.rounds - wins) + "rounds");
    } while (rounds <= 5);
    private Card[] deck;
    private int cards;
    public static int rounds = 1;
    public int cardValue;
    /**When I try to compile this nested class, I get an error message saying I need a brace here and at the end of the program. I don't know if any of this code would work because I've tried adding braces and still can't compile it.**/
    class Hand()
    static int r = 1;
    public Hand() { CardDeck.rounds = r; }
    public int getRounds() { return r++; }
    final class Card
    public static final int ACE = 1;
    public static final int JACK = 11;
    public static final int QUEEN = 12;
    public static final int KING = 13;
    public static final int CLUBS = 1;
    public static final int DIAMONDS = 2;
    public static final int HEARTS = 3;
    public static final int SPADES = 4;
    public Card(int v, int s)
    value = v;
    suit = s;
    public int getValue() { return value; }
    public int getSuit() { return suit;  }
    public int rank()
    if (value == 1)
    return 4 * 13 + suit;
    else
    return 4 * (value - 1) + suit;
    /**This works, but I'm confused. How is this method called? Does it call itself?**/
    public String toString()
    String v;
    String s;
    if (value == ACE)
    v = "Ace";
    else if (value == JACK)
    v = "Jack";
    else if (value == QUEEN)
    v = "Queen";
    else if (value == KING)
    v = "King";
    else
    v = String.valueOf(value);
    if (suit == DIAMONDS)
    s = "Diamonds";
    else if (suit == HEARTS)
    s = "Hearts";
    else if (suit == SPADES)
    s = "Spades";
    else
    s = "Clubs";
    return v + " of " + s;
    private int value; //Value is an integer, so how can a
    private int suit; //string be assigned to an integer?
    }

    Thank you so much for offering to help me with this Jamie! When I tried to call change value using:
    Card dealer = (d.changeValue());
    I get an error message saying:
    Incompatible types found: int
    required: Card
    I had my weekly class last night and the professor cleared up a few things for me, but I've not had time to make all of the necessary changes. I did find out how toString worked, so that's one question out of the way, and he gave us a lot of information for adding another class to generate random numbers.
    Again, thank you so much. I really want to learn this but I'm feeling so stupid right now. Any help you can give me about the above error message would be appreciated.

  • New TO JAVA Programming

    Dear Forummembers,
    I am student doing postgraduate studies in IT.i have some queries related to one of my programming staff.i am very much new into Java programming and i am finding it a bit difficult to handle this program.The synopsis of the program is given below -
    You are required to design and code an object-oriented java program to process bookings for a theatre perfomance.
    Your program will read from a data file containing specifications of the performance,including the names of the theatre, the play and its author and the layout of the theatre consisting of the number of seats in each row.
    It will then run a menu driven operation to accept theatre bookings or display the current
    status of seating in the theatre.
    The name of the file containing the details of the performance and the theatre should be
    provided at the command line, eg by running the program with the command:
    java Booking Theatre.txt
    where Theare.txt represents an example of the data file.
    A possible data file is:
    Opera
    U and Me
    Jennifer Aniston
    5 10 10 11 12 13 14
    The data provided is as follows
    Line 1
    Name of the Theatre
    Line 2
    Name of the play being performed
    Line 3
    Name of the author of the play being performed
    Line 4
    A list of the lengths (number of seats) of each row in the theatre, from front to
    back.
    The program must start by reading this file, storing all the appropriate parameters and
    establishing an object to accept bookings for this performance with all details for the theatre
    and performance.
    The program should then start a loop in which a menu is presented to the user, eg:
    Select from the following:
    B - Book seats
    T - Display Theatre bookings
    Q - Quit from the program
    Enter your choice:
    And keep performing selected operations until the user�s selects the quit option, when the
    program should terminate.
    T - Display Theatre bookings
    The Display Theatre Bookings option should display a plan of the theatre. Every available
    seat should be displayed containing its identification, while reserved seats should contain an
    Rows in each theatre are indicated by letters starting from �A� at the front. Seats are
    numbered from left to right starting from 1. A typical seat in the theatre might be designated
    D12, representing seat 12 in row D.
    B - Book seats
    The booking of seats is to offer a number of different options.
    First the customer must be asked how many adjacent seats are
    required. Then start a loop offering a further menu of choices:
    Enter one of the following:
    The first seat of a selected series, eg D12
    A preferred row letter, eg F
    A ? to have the first available sequence selected for you
    A # to see a display of all available seats
    A 0 to cancel your attempt to book seats
    Enter your selection:
    1. If the user enters a seat indentifier such B6, The program should attempt to
    reserve the required seats starting from that seat. For example if 4 seats are
    required from B6, seats B6, B7, B8 and B9 should be reserved for the customer,
    with a message confirming the reservation and specifying the seats reserved..
    Before this booking can take place, some testing is required. Firstly, the row
    letter must be a valid row. Then the seat number must be within the seats in the
    row and such that the 4 seats would not go beyond the end of the row. The
    program must then check that none of the required seats is already reserved.
    If the seats are invalid or already reserved, no reservation should be made and the
    booking menu should be repeated to give the customer a further chance to book
    seats.
    If the reservation is successful, return to the main menu.
    2. The user can also simply enter a row letter, eg B.IN this case, the program should
    first check that the letter is a valid row and then offer the user in turn each
    adjacent block of the required size in the specified row and for each ask whether
    the customer wants to take them. Using the partly booked theatre layout above, if
    the customer wanted 2 seats from row B, the customer should be offered first:
    Seats B5 to B6
    then if the customer does not want them:
    Seats B10 to B11
    and finally
    Seats B11 to B12
    If the customer selects a block of seats, then return to the main menu. If none are
    selected, or there is no block of the required size available in the row, then report
    that no further blocks of the required size are available in the row and repeat the
    booking menu.
    3. If the user enters a ? the program should offer the customer every block of seats
    of the required size in the whole theatre. This process should start from the first
    row and proceed back a row at a time. For example, again using the partially
    booked theatre shown above, if the user requested 9 seats, the program should
    offer in turn:
    Seats A1 to A9
    Seats C1 to C9
    Seats C2 to C10
    Seats E3 to E11
    Seats E4 to E12
    If the customer selects a block of seats, then return to the main menu. If none are
    selected, or there is no block of the required size available in the whole theatre,
    then report that no further blocks of the required size are available and repeat the
    booking menu.
    4. If the user enters a # the program should display the current status of the seating
    in the theatre, exactly the same as for the T option from the main menu and then
    repeat the booking menu.
    5. If the user enters a 0 (zero), the program should exit from the booking menu back
    to the main menu. If for example the user wanted 9 seats and no block of 9 was
    left in the theatre, he would need to make two separate smaller bookings.
    The program should perform limited data validation in the booking process. If a single
    character other than 0, ? and # is entered, it should be treated as a row letter and then tested
    for falling within the range of valid rows, eg A to H in the example above. Any invalid row
    letters should be rejected.
    If more than one character is entered, the first character should be tested as a valid row letter,
    and the numeric part should be tested for falling within the given row. You are NOT
    required to test for valid numeric input as this would require the use of Exception handling.
    You are provided with a class file:
    Pad.java
    containing methods that can be used for neat alignment of the seat identifiers in the theatre
    plan.
    File Processing
    The file to be read must be opened within the program and if the named file does not exist, a
    FileNotFoundException will be generated. It is desirable that this Exception be caught and
    a corrected file name should be asked for.
    This is not required for this assignment, as Exception handling has not been covered in this
    Unit. It will be acceptable if the method simply throws IOException in its heading.
    The only checking that is required is to make sure that the user does supply a file on the
    command line, containing details of the performance. This can be tested for by checking the
    length of the parameter array args. The array length should be 1. If not, display an error
    message telling the user the correct way to run the program and then terminate the program
    System.exit(0);
    The file should be closed after reading is completed.
    Program Requirements
    You are expected to create at least three classes in developing a solution to this problem.
    There should be an outer driving class, a class to represent the theatre performance and its
    bookings and a class to represent a single row within the theatre.
    You will also need to use arrays at two levels. You will need an array of Rows in the Theatre
    class.
    Each Row object will need an array of seats to keep track of which seats have been reserved.
    Your outer driving class should be called BookingOffice and should be submitted in a file named BookingOffice.java
    Your second, third and any additional classes, should be submitted in separate files, each
    class in a .java file named with the same name as the class
    I am also very sorry to give such a long description.but i mainly want to know how to approach for this program.
    also how to designate each row about it's column while it is being read from the text file, how to store it, how to denote first row as row A(second row as row B and so on) and WHICH CLASS WILL PERFORM WHICH OPERATIONS.
    pls do give a rough guideline about designing each class and it's reponsibilty.
    thanking u and looking forward for your help,
    sincerely
    RK

    yes i do know that........but can u ppl pls mention
    atleast what classes shud i consider and what will be
    the functions of each class?No, sorry. Maybe somebody else will, but in general, this is not a good question for this forum. It's too broad, and the question you're asking is an overall problem solving approach that you should be familiar with at this point.
    These forums are best suited to more specific questions. "How do I approach this homework?" is not something that most people are willing or able to answer in a forum like this.

  • New to JAVA, but old school to programming

    Objects & Classes & Methods, Oh my!
    I'm pretty new to java, but I've been programming in several languages over the years. I thought it was about time to update my skill set, especially with the job market as it is today. I wanted to go JAVA because it's not specific to any environment.
    I picked up a begining JAVA book and was a little confused. When I was learning programming a program was called a program. a peice of code in a program called by a statement was called a subroutine (it was performed then control returned to the calling line and continued).
    Now I'm trying to make sense of everything I have read so far and trying to relate it back to my old school of thinking. I was hoping it would make it easier to retain and I could expand it as I learn and possibly realize that it IS different. I know it's a new way of thinking, but stay with me for minute.
    What I used to call a program is now a CLASS in JAVA (this can be a collection of code or other objects). A sub-routine in a CLASS is a Method. I know that the language part will come as I use it since I understand if's then's and whatever you use to gosub or goto, but I want to make sure I have down the lingo before I go to deep.

    I have no idea how you can compare Java to Cobol.
    DataFlex? How about that! In about '84 I switched to
    DataFlex from dBaseII. In '91 DataFlex changed from
    procedural to OOP. It took most of us at least a year
    to adjust, and then some to write concrete code. It
    was tough. They had bugs and we were limited with DOS.
    BUT, it was a great OOP training experience. Anyhow,
    needless to day Java is miles ahead on all fronts.Small world. I was stuck in the old DataFlex Ver 2.3 at that time. The company I worked for had the newer OOP package. I did get to work with it some, but not enough to become totally familiar with it. We started to move out of DataFlex towards PowerBuilder towards the end of 1995. I did get some OOP from that experience, but again only enough to learn about global variables, instance variables, and a few other items. I hoping that I will be able to get the solid OOP background that I need from JAVA since I hear through the grapevine that it may be a new tool that we will be looking at to enhance our programming. I was looking at PERL but even the PERL programmers we have agree that JAVA is more scalable.

  • Why is New to Java so much faster than Java Programming?

    It feels like the New to Java server is at my neighbor's house, and Java Programming is on Neptune. What gives? It always takes like 10 seconds to load the Java Programming board.

    I've noticed that, too. I've attributed it to message volume, since there are so many more messages under that category.
    Maybe the database doesn't have an index, or perhaps they bring back LOTS of entries and cache them. Who knows?
    %

  • Brand New to Java and Programming

    I'm brand new, ( RAW ) to software programming at this time. I'm starting from scratch, I work on a Help Desk for the government so I can perform some software functionality but nothing as far as programming.. I would like recommendations for someone starting out brand new.. Books to read (JAVA for Dummies?) any beginner courses? What steps would you take if you were starting out brand new as I am myself.. Thanks..
    PS, I plan on taking courses after I get the beginning stuff out of the way, just don't want to go in with no knowledge base..

    For a nice list of stock answers: The One to Torment Newbies with
    Sun's basic Java tutorial
    Sun's New To Java Center. Includes an overview of what Java is, instructions for setting up Java, an intro to programming (that includes links to the above tutorial or to parts of it), quizzes, a list of resources, and info on certification and courses.
    http://javaalmanac.com . A couple dozen code examples that supplement The Java Developers Almanac.
    jGuru. A general Java resource site. Includes FAQs, forums, courses, more.
    JavaRanch. To quote the tagline on their homepage: "a friendly place for Java greenhorns." FAQs, forums (moderated, I believe), sample code, all kinds of goodies for newbies. From what I've heard, they live up to the "friendly" claim.
    Bruce Eckel's Thinking in Java (Available online.)
    Joshua Bloch's Effective Java
    Bert Bates and Kathy Sierra's Head First Java.
    James Gosling's The Java Programming Language. Gosling is
    the creator of Java. It doesn't get much more authoritative than this.

  • Help needed, new to java programming

    hi,
    I have craeted a Frame with some check boxes and button called "button1".
    Can anyone tell me how can i count the number of CHECKED check boxes so that when i press the button1 in my code it should display the result as number of checked check boxes divided by total number of check boxes. It should display the result in a textfield here RESULT textfield in my code
    Thanks in advance ...i am sending the code i have written so far....
    public class Frame extends java.awt.Frame {
        /** Creates new form Frame */
        public Frame() {
            initComponents();
            setSize(600, 600);
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
        private void initComponents() {
            buttonGroup1 = new javax.swing.ButtonGroup();
            checkbox1 = new java.awt.Checkbox();
            checkbox2 = new java.awt.Checkbox();
            checkbox3 = new java.awt.Checkbox();
            button1 = new java.awt.Button();
            textField1 = new java.awt.TextField();
            setLayout(null);
            addWindowListener(new java.awt.event.WindowAdapter() {
                public void windowClosing(java.awt.event.WindowEvent evt) {
                    exitForm(evt);
            checkbox1.setLabel("checkbox1");
            add(checkbox1);
            checkbox1.setBounds(160, 50, 84, 20);
            checkbox2.setLabel("checkbox2");
            add(checkbox2);
            checkbox2.setBounds(160, 70, 84, 20);
            checkbox3.setLabel("checkbox3");
            add(checkbox3);
            checkbox3.setBounds(160, 90, 84, 20);
            button1.setLabel("button1");
            button1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    button1ActionPerformed(evt);
            add(button1);
            button1.setBounds(150, 180, 57, 24);
            textField1.setText("Result");
            textField1.setName("Result");
            add(textField1);
            textField1.setBounds(260, 180, 44, 20);
            pack();
        private void button1ActionPerformed(java.awt.event.ActionEvent evt) {
            // Add your handling code here:
        /** Exit the Application */
        private void exitForm(java.awt.event.WindowEvent evt) {
            System.exit(0);
         * @param args the command line arguments
        public static void main(String args[]) {
            new Frame().show();
        // Variables declaration - do not modify
        private java.awt.Button button1;
        private javax.swing.ButtonGroup buttonGroup1;
        private java.awt.Checkbox checkbox1;
        private java.awt.Checkbox checkbox2;
        private java.awt.Checkbox checkbox3;
        private java.awt.TextField textField1;
        // End of variables declaration
    }

    Two problems in the code you repost-ed:
    1. It lacks import statements.
    2. There is an extraneous } at the end of the button1ActionPerformed method.
    Correct them and it'll work fine. Posting the full source code:
    import java.awt.Component;
    import java.awt.Checkbox;
    public class Frame extends java.awt.Frame
         /** Creates new form Frame */
         public Frame()
              initComponents();
          * This method is called from within the constructor to initialize the form.
          * WARNING: Do NOT modify this code. The content of this method is always
          * regenerated by the Form Editor.
         private void initComponents()
              checkbox1 = new java.awt.Checkbox();
              checkbox2 = new java.awt.Checkbox();
              checkbox3 = new java.awt.Checkbox();
              button1 = new java.awt.Button();
              textField1 = new java.awt.TextField();
              setLayout( null );
              addWindowListener( new java.awt.event.WindowAdapter()
                   public void windowClosing( java.awt.event.WindowEvent evt )
                        exitForm( evt );
              checkbox1.setLabel( "checkbox1" );
              add( checkbox1 );
              checkbox1.setBounds( 120, 40, 84, 20 );
              checkbox2.setLabel( "checkbox2" );
              add( checkbox2 );
              checkbox2.setBounds( 120, 60, 84, 20 );
              checkbox3.setLabel( "checkbox3" );
              add( checkbox3 );
              checkbox3.setBounds( 120, 80, 84, 20 );
              button1.setLabel( "button1" );
              button1.addActionListener( new java.awt.event.ActionListener()
                   public void actionPerformed( java.awt.event.ActionEvent evt )
                        button1ActionPerformed( evt );
              add( button1 );
              button1.setBounds( 50, 170, 57, 24 );
              textField1.setText( "textField1" );
              add( textField1 );
              textField1.setBounds( 240, 170, 60, 20 );
              pack();
         private void button1ActionPerformed( java.awt.event.ActionEvent evt )
              // Add your handling code here:
              Component[] components = getComponents();
              int numOfCheckBoxes = 0;
              int numChecked = 0;
              for ( int i = 0; i < components.length; i++ )
                   if ( components[i] instanceof Checkbox )
                        numOfCheckBoxes++;
                        Checkbox checkBox = (Checkbox) components;
                        if ( checkBox.getState() )
                             numChecked++;
              double ratio = (double) numChecked / (double) numOfCheckBoxes;
              textField1.setText( Double.toString( ratio ) );
         /** Exit the Application */
         private void exitForm( java.awt.event.WindowEvent evt )
              System.exit( 0 );
         * @param args the command line arguments
         public static void main( String args[] )
              new Frame().show();
         // Variables declaration - do not modify
         private java.awt.Button button1;
         private java.awt.Checkbox checkbox1;
         private java.awt.Checkbox checkbox2;
         private java.awt.Checkbox checkbox3;
         private java.awt.TextField textField1;
         // End of variables declaration
    I can see from the code that the GUI was generated by a tool. Since you're new to Java programming, I'd recommend ditching the tool and writing everything by hand, otherwise you're not learning much. It's just like when you're learning proofs in Maths, where you start with first principles before making use of the proofs on their own.
    Also, it'll help tremendously if you could spend some time going through the Java Tutorial (http://java.sun.com/docs/books/tutorial/). It's free, and I find it very useful.
    Hth.

  • New in Java: java applet program using multithreading

    I am trying to write a program, which should move the words "Java Platform2" from left to right every time we 'refresh'.
    Can you please advise what is wrong in the logic??
    import java.applet.*;
    import java.awt.*;
    import java.lang.*;
    public class Ch61appth extends Applet implements Runnable
    int i=30;
    int x=10;
    int y=30;
    Thread t,cur;
         public void start()
              t=new Thread(this);
              t.start();
         public void paint(Graphics g)
              g.setColor(Color.blue);
              g.drawString("Java Platform2",x+i,y);
         public void run()
                   if ((x+i)<400)
                        {     i=i+20;
                        else
                        {     i=20;
              //cur=new Thread.currentThread();
              repaint();

    thanks for reply
    i tried using for loop. Earlier also i had tried using while loop with condition t==Thread.currentThread()
    The problem i am facing is the string just does not move and even after clicking refresh, it appears at same locations.
    CAN U ADVISE>
    bye
    kumar

  • New to Java - why won't my program run ?

    Hi
    I am new to Java - this compiles but does not run - any suggestions please ?
    class ThinkofANumberApp extends basic{
         public static void main (String param[]) throws Exception
         input source = new input ();
         output sink = new output ();
         int result = source.readint();
         //list number questions for numbers
              sink.writeln("Think of a number");
              source.readln();
              sink.writeln("Multiply it by 5");
              source.readln();
              sink.writeln("Add 6");
              source.readln();
              sink.writeln("Multiply it by 4");
              source.readln();
              sink.writeln("Add 9");
              source.readln();
              sink.writeln("Multiply it by 5");
              source.readln();
              sink.writeln("Type the final result");
              sink.write("My \"guess\" is that your"
              + " original number was ");
              sink.writeln((result-165)/100);
    Thanks in advance.
    Nadjie

    What is "input" and "output" and have you included these classes in your classpath?

  • New to Java and trying to make a game

    I'm really new to Java so please try not to roll over laughing at the following code. At the moment, as you can hopefully pick up from the code, i'm trying to get a shape(Polygon) to respond to keyboard events and i'm trying to make the object primarily respond to the cursor keys and to move the Polygon in the corresponding directions of the cursors. I'm stuck and i think i have initialised everything but i can't get the shape to move. I'm pretty sure i'm missing required code in the paint method.
    <code>
    import java.awt.*;
    import java.awt.Event.*;
    import java.applet.*;
    import java.io.*;
    public class PlodInvaders extends Applet implements Runnable {
    Point start, end, fire, shield, target;
    int co_x, x, y;
    int co_y;
    int current_x, current_y;
    char current_key;
    Font theFont;
    Thread th;
    Image ship;
    Polygon p;
    public void init() {
    setBackground(Color.black);
    // mouse co-oridnates
    co_x = this.size().width + 5;
    co_y = this.size().height + 5;
    theFont= new Font("Courier", Font.BOLD, 24);
    current_x = 150;
    current_y = 100;
    public void start() {
    th = new Thread(this);
    th.start();
    public boolean KeyDown(Event evt, int key) {
    switch(key) {
    case Event.LEFT: current_x = current_x - 10; break;
    case Event.RIGHT: current_x = current_x +10; break;
    case Event.UP: current_y = current_y + 10; break;
    case Event.DOWN: current_y = current_y - 10; break;
    default: current_key = (char) key;
    start = new Point(x, y);
    repaint();
    return true;
    public boolean MouseDown(Event evt, int x, int y) {
    fire = new Point(x, y);
    return true;
    public boolean MouseUp(Event evt, int x, int y) {
    target = new Point(x, y);
    repaint();
    return true;
    public void run() {
    public void paint(Graphics g){
    Polygon p = new Polygon();
    g.setColor(Color.white);
    p.addPoint(20,20);
    p.addPoint(50,25);
    p.addPoint(50,50);
    p.addPoint(25,50);
    p.addPoint(20,20);
    g.fillPolygon(p);
    </code>

    this is not prefect and it is not a applet, but it will make you start. you can email if you have any qeustions
    import java.awt.*;
    import java.awt.event.*;
    public class MoveP extends Frame implements KeyListener
         Polygon po = new Polygon();
            int ix=0;
         int iy=0;
    public MoveP()  
         addWindowListener(new WindowAdapter()
        {     public void windowClosing(WindowEvent ev)
              {     dispose();
                   System.exit(0);
         addKeyListener(this);
         setSize(300,372);
         po.addPoint(20,20);
         po.addPoint(50,25);
         po.addPoint(50,50);
         po.addPoint(25,50);
         po.addPoint(20,20);
         setVisible(true); 
    public void paint(Graphics g)
         g.setColor(Color.black);
         for (int i=0; i < po.npoints; i++)
              po.xpoints[i]+=ix;
              po.ypoints[i]+=iy;
         g.fillPolygon(po);
    public void keyTyped(KeyEvent e)
    public void keyPressed(KeyEvent e)
         ix = 0;
         iy = 0;
         int k = e.getKeyCode();
         if (k == 40) iy++;
         if (k == 38) iy--;
         if (k == 39) ix++;
         if (k == 37) ix--;
         repaint();
    public void keyReleased(KeyEvent e)
    public static void main (String[] args)
         new MoveP();
          Noah

  • I'm new to Java, you see....

    I'm not much of a Java man just yet...but I do know C and C++ very well, and I also am a very at using Macromedia Flash to program any kind of game there is...even 3D (which Flash doesn't support). I've also written a 75 page "book" (tutorial, rather) about programming games in Flash, and how to apply trigonometry, calculus, algebra, and geometry to create games (Like logarithmic level-up systems and parabolic slopes and such).
    And now that I've established that I'm not a complete n00b idiot, I have a question or two about Java, regarding the life cycle of an Applet and the flow of execution in an applet. In C/C++, execution begins at main() or WINMAIN(), and runs straight down the line, executing each line of code. My Java applet doesn't seem to do this.
    import java.awt.*;
    import java.applet.Applet;
    public class HelloWorld extends Applet{
         public void init(){
              //Nothing here.
         //Nothing in this function is executed...
         public int Bob(Graphics X){
              X.drawString("This doesn't print...",0,0);
              X.drawRect(150,150, 160, 160);
              Color Vermilion=new Color(255,56,0);
              X.setColor(Vermilion);
              X.fillRect(150,150,160, 160);
              return 0;
         public void paint (Graphics g){
              g.drawRect(0,0,300,150);
              g.setColor(Color.RED);
              g.fillRect(0,0,300,150);
              g.setColor(Color.BLUE);
              g.drawString("L33T |-|4x0|25 570|_3 |\/|y |\/|364|-|3|275",25,75);
    };�Why does paint execute, even though it's below Bob()? I'm assuming it's because paint() is a method that's important ad such...?
    �Also...WHERE is the entry point in a Java program? It would really help to know just where execution starts and ends.
    �Why is Java just about 100% classes and OOP? Is there REALLY a need for that? C and C++ do just fine with global functions outside of classes.
    �Can Java be used to create (almost) animations of sorts? Which would require one to be able to actually see an object's position be changed over a series of frames rather than having all of the code execute before you can see the object move..
    Hey, sorry about all the questions, ya? :cool:
    I'm new to this...so I guess it's okay if I have a few questions, right?
    Anyhoo, any help would be appreciated. :)

    I am short on time right now, so I will only answer one of your questions.
    A Java Applet uses the init() method as the entry point to the Applet. If you have an empty init() method, nothing is going to happen.
    void      init()
              Called by the browser or applet viewer to inform this applet that it has been loaded
              into the system.A Java application uses the main() mehtod as the entry point. The signature for the main method is:
    public static void main( String arguments[] )Applets are started by browsers, applications are started by a JVM startup program (typically, java).
    � {�                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Maybe you are looking for

  • B&W G3 Can't Sleep

    I was recently given a nice Blue and White G3, 350 MHz. I upgraded the hard drive to an 80GB drive, and upgraded the ram to 512 megs. Lately, I installed OS X Tiger and upgraded to 10.4.9 (now 10.4.10). The problem is that when I click Sleep under th

  • K7n2delta-L sound crackle problem

    hi. I experience sound crackling with the MSI K7n2 delta-L board. It happens when for example, im in the middle of a conversation in NetMeeting, and i hear a sound alert in YM, the sound crackles then in the conversation after that. I also hear sound

  • Rebate Agreements Report

    Hi everyone, I'm trying to create a report that will show all the current rebate agreements that the system has, with the total amount of their rebate documents (manual accruals, partial selttlement and final selttlement), also the total amount of th

  • Parental Controls(Enable Restrictions) and installing apps through ITunes store (PC)

    Through Parental control(Restrictions), the iTunes Store and Installing apps can be disabled on iPhone. Now is this feature can prevent apps getting installed if Apps are purchased through iTunes Store in PC and synced with iTunes? Is it possible to

  • How can I rename RAW files on my iPad?

    I am trying to find some way where I can rename, caption and keyword my photos on my iPad so that when I load them into Aperture those things go along with the photo.  I know that there are many ways to do this with conversion to jpeg or shooting RAW