Help with some code

I am a complete newbe to programming in general but especially to JAVA. I just started a class to learn but the professor just assigns tasks and the book does not go into actually how to do any of what he asks. Of course this is an online class so there is no real teaching on his part either. What is wrong with my code. I have had to look at code online to try and figure this stuff out. I'm afraid though I havent quite got the jist of what the syntax is for JAVA so my understanding of all of this is very limited.
here is my code: (the way the forums message box works it seems to word wrap a little different then notepad++ so please bare with the lines that should be "//" and dont show it at the beginning. (example first two lines).
// My java app that checks to see if a number is even or odd and if it is between 1 and 1000. It also uses the JOptionPane to input and output.
import javax.swing.JOptionPane;
import java.io.*;
import java.lang;
public class numberChecker
public static void main(String[] args) throws IOException{
try{
JOptionPane.showMessageDialog( "This is a Program to check whether numbers are even\nand if they are between 1 and 1000");
String name =
JOptionPane.showInputDialog( null, "Enter in a Number");
Integer.parseInt( String, name );
if (name % 2 == 0)
JOptionPane.showMessageDialog("Is %s even\ntrue");
} else {
JOptionPane.showMessageDialog("Is %s even\nfalse.");
if (name > 0)
if (name < 1001)
JOptionPane.showMessageDialog("The number %s between 1 and 1000 is true");
} else {
JOptionPane.showMessageDialog("The number %s between 1 and 1000 is false");
} else {
JOptionPane.showMessageDialog("The number %s between 1 and 1000 is false");
JOptionPane.showMessageDialog(null, name);
catch(NumberFormatException e){
JOptionPane.showWarningDialog(e.getMessage() + " is not a numeric value.");
System.exit(0);
};

i had updated the code to be this now:
// My java app that checks to see if a number is even or odd and if it is between 1 and 1000. It also uses the JOptionPane to input and output.
    import javax.swing.JOptionPane;
    import java.io.*;
    import java.lang;
    public class numberChecker
        public static void main(String[] args) throws IOException{
    try{
            JOptionPane.showMessageDialog( "This is a Program to check whether numbers are even\nand if they are between 1 and 1000");
            String name =
                JOptionPane.showInputDialog( null, "Enter in a Number");
          Int valueToParse =
                Integer.parseInt( name );
                    if (valueToParse % 2 == 0)
                        JOptionPane.showMessageDialog("Is ",valueToParse," even\ntrue");
                        } else {
                        JOptionPane.showMessageDialog("Is ",valueToParse," even\nfalse.");
                    if (name > 0)
                            if (name < 1001)
                            JOptionPane.showMessageDialog("The number ",valueToParse," between 1 and 1000 is true");
                            } else {
                            JOptionPane.showMessageDialog("The number ",valueToParse," between 1 and 1000 is false");
                        } else {
                        JOptionPane.showMessageDialog("The number ",valueToParse," between 1 and 1000 is false");
                JOptionPane.showMessageDialog(null, name);
        catch(NumberFormatException e){
        JOptionPane.showWarningDialog(e.getMessage(), " is not a numeric value.");
        System.exit(0);
        };Now i get a bunch of "cant find symbol" errors.

Similar Messages

  • A little help with some code and theory

    Hey guys, I'm kinda new to this whole programming thing so
    bare with me please. I have a little problem that I just can't seem
    to get my hear around. I have a working on an inventory management
    page. It keeps track of what software is installed where and how
    many copies we have, and serials and such. Well, this page was set
    up long before I started here and it wasn't too friendly. So I'm
    editing it and adding some new features. Well one of them is
    displaying the “available installs count” with the
    search results.
    Here is my problem. The way the system keeps track of what
    software is installed where is by adding taking the appId from the
    table it with all the app's information on it (the sn, name, max
    installs, etc) and creating a new entry in another table that
    indexs that appId and the workstation it is installed on. (along
    with an Install id) well the only way to check to see how many
    copies is installed is to get the record count for a particular
    appId.
    This is where I run into trouble. When a user searches for
    apps the results page displays the apps that still have installs
    available. So where the record count of getInstallCount for
    whatever appId is less than the max installs. Well what is the best
    way to do this since to get the record count of getInstallCount I
    need an appID and the appID isn't found until I do the search
    query. What I'm using now is this but it always returns 0 for
    current Install Count. See the attached Snippet of code:
    I see what it is doing. It is getting the isntallCount for
    all appIds, but I dont' know how to narrow it down without doing
    the search first, and I don't know how to do the search with out
    getting the install count first. Any ideas or advice would rock
    guys. Like I said I'm kinda new to this programming stuff but it is
    awesome! Thanks!
    Kevin

    The w and wi are just table aliases that make it easier to
    referrence those tables by column when joining multiple tables
    (avoids having to prefix column names with the entire table name,
    etc.) When doing a self-join (joining a table to itself), the use
    of table aliases is
    required, otherwise you would have no other way to tell
    which column belonged to which "instance" of table.
    The query itself is pretty simple. It is just using a
    correlated subquery to select only those instances of
    workstationApps where the count of appID instances in
    workstationAppIndex is less than the amount specified in the
    maxConcurrentInstalls for the same appID.
    Also, I do see what you are doing with #form.searchType#, I
    was just making sure that it was what you really intended to do.
    Phil

  • Need Help with some code

    Hello, thanks for helping:
    my problem is that I am creating a "before" and "after" situation between strings. (What a string was before.. and now what it is)
    so here's the sample I created. Basically a display issue. If you run it you'll know the problem.
    Thanks again for helping.
       import javax.swing.*;
       import java.awt.*;
       import java.awt.event.*;
        public class JScrollExample extends JFrame
          JPanel mainpanel = new JPanel();
          JTextArea text = new JTextArea();
          JScrollPane scroll = new JScrollPane(text);
          String[] before, after, other;
          int sda, indexMaxLength;
          int[] ja;
          StringBuilder[] sb;
          String[] name;
           public JScrollExample()
             getContentPane().add(mainpanel, BorderLayout.NORTH);
             setTitle("JScrollExample");
             text.setColumns(100);
             text.setRows(30);
             mainpanel.add(scroll);
             before = new String[]
                   "asdf-asdfasdfasdf-asdf", "asdf-asdfasdfasdf-asdffdsaasdf",
                   "asdf-asdffdsaasdffdssasdfasdf-asdf", "AVDSDFDSasdf-asdfasdfasdf-asdf",
                   "asdsdfsdfsdfsdfsdsdfsdf-asddsffasdsdfsdfasdfvfdvdfvfd-asdf"
             after = new String[]
                   "jkloolkj-iriod-3342", "jsdfsdolkj-iriod-3342", "jkloolkj-fdsfiriod-3342",
                   "jkloolkj-idsfsfsfsdfsdfiod-3sdfds342", "ASXkloolkj-iriod-3342MBW"
             other = new String[]
                   "AAAAAAAAAAAAAAAAAAAA", "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
                   "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "AAAAAAAAA", "AAAAAAAAAAAAA"
             indexMaxLength = 0;
             sb = new StringBuilder[before.length];
             ja = new int[before.length];
             name = new String[before.length];
             for(int j = 0; j < before.length; j++)
                if(before[j].length() > before[indexMaxLength].length())
                   indexMaxLength = j;
             sda = before[indexMaxLength].length();
             for(int i = 0; i < before.length; i++)
                ja[i] = ((sda - before.length()) + 25);
    for(int j = 0; j < ja.length; j++)
    sb[j] = new StringBuilder("");
    for(int g = 0; g < ja[j]; g++)
    sb[j].append(" -");
    text.append("I'm trying to make it look nice and neat," +
                   "and have each line have same amount of '-' " + "I tried doing it " +
                   "and this is what I got. Basically what i'm doing is finding " +
                   "the longest string, subtracting each string's \nlength with the " +
                   " longest one, then adding 25, to get an equal value, then using " +
                   "that value to put that many '-' in between before and after. But " +
                   "because every character has a different size, it doesn't work\n " +
                   "unless all the characters are the same\n\n");
    for(int i = 0; i < before.length; i++)
    String y = (after[i]);
    text.append(before[i] + sb[i].toString() + "> " + y + "\n");
    indexMaxLength = 0;
    sb = new StringBuilder[before.length];
    ja = new int[before.length];
    for(int j = 0; j < other.length; j++)
    if(other[j].length() > other[indexMaxLength].length())
    indexMaxLength = j;
    sda = other[indexMaxLength].length();
    for(int i = 0; i < other.length; i++)
    ja[i] = ((sda - other[i].length()) + 25);
    for(int j = 0; j < ja.length; j++)
    sb[j] = new StringBuilder("");
    for(int g = 0; g < ja[j]; g++)
    sb[j].append(" -");
    text.append("\n\nWHAT I WANT IS THIS: \n\n");
    for(int i = 0; i < other.length; i++)
    String y = (after[i]);
    text.append(other[i] + sb[i].toString() + "> " + y + "\n");
    public static void main (String[] args)
    JFrame.setDefaultLookAndFeelDecorated(true);
    JScrollExample frame = new JScrollExample();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);          
    frame.setVisible(true);
    frame.pack();

    what methods do you think I should use?I think you should use the monospaced font.
    I went to the font metrics page, and I understand what it does.Well, then you should realize that you can't be guaranteed that your column will line up if you attempt to use the FontMetrics class. All the FontMetrics class can tell you is the width of a String.
    You can calculate the width of your longest String and then calculate the width of 25 " -" to get the total width before the second colum. Lets assume this width is 500. Now lets also assume that each " -" string is 10 pixels.
    If we have "i" as the only text and its width is 3 pixels, then how do you calculate a multiple of " -" which will total to 500 pixels?
    Similiarly if you have a "W" as the text and its width is 7 pixels you will never be able to add characters that will total to 500 pixesl.
    So if you need "- - - - >" between column 1 and column 2 the easiest solution is to use a monospaced font.
    If on the other hand you only care about column two lining up in the same postion each time, then you may be able to use tabs in a JTextPane as you can easily control the placement of text for each tab. This posting will give you an idea:
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=585006

  • Need help with some code ... Searching a tree and inserting data

    I'm trying to write code for the addIterative method below.
    My problem is that I also need to search the list or node to see if the word exists.
    The method add(word,line,position,iterative) validates the parameters; and, in order to update the tree and/or any relevant linked-list, calls either the incomplete method addIterative(word,line,position) or the incomplete method addRecursive(word,line,position). Note the following: if the word is not contained currently in the tree, then all of the (word,line,position) triplet needs to be added to the data structure; otherwise, only the (line,position) pair needs to be added to the data structure. The result must be the same regardless of the algorithmic strategy employed.
    any suggestions would be greatly appreciated, new to java, and very lost.
    regards,
    Jimmy
    * Write a description of class Tree091 here.
    * @author (your name)
    * @version (a version number or a date)
    class Tree091 /*(i.e., WordTree)*/
    { private char[] word=null;
    private List091 list=null;
    private Tree091 precursor=null; /*(i.e., leftSubTree)*/
    private Tree091 successor=null; /*(i.e., rightSubTree)*/
    public Tree091(char[] word,
    List091 list,
    Tree091 precursor, /*(i.e., lexicographically < word)*/
    Tree091 successor) /*(i.e., lexicographically > word)*/
    { if (word==null) return;
    if (word.length<1) return;
    if (list==null) return;
    this.word=word;
    this.list=list;
    this.precursor=precursor;
    this.successor=successor;
    public void add(char[] word,
    int line,
    int position,
    boolean iterative)
    { if (word==null) return;
    if (word.length<1) return;
    if (line<0) return;
    if (position<0) return;
    if (iterative)
    this.addIterative(word,line,position);
    else
    this.addRecursive(word,line,position);
    private void addIterative(char[] word,
    int line,
    int position)
    /* something goes here*/
    private void addRecursive(char[] word,
    int line,
    int position)
    /* something goes here*/
    private int compare(char[] array1,
    char[] array2)
    { if (array1==null) return -2;
    if (array2==null) return -2;
    int length1=array1.length;
    if (length1==0) return -2;
    int length2=array2.length;
    if (length2==0) return -2;
    int minLength=length1<length2?length1:length2;
    for (int i=0; i<minLength; i++)
    { if (array1[i]<array2) return -1;
    if (array1[i]>array2[i]) return 1;
    return length1==length2 ? 0 : length1<length2 ? -1 : 1;
    public boolean contained(char[] word)
    { int compare=compare(this.word,word);
    if (compare==1&&this.precursor!=null)
    return this.precursor.contained(word);
    if (compare==0) return true;
    if (compare==-1&&this.successor!=null)
    return this.successor.contained(word);
    return false;
    public int listNodeCount(boolean iterative)
    /* something goes here*/
    return 24;
    public int maximumWordLength(int currentLength)
    /* something goes here*/
    return 25;
    public String toString()
    { String string="";
    if (this.precursor!=null) string+=this.precursor;
    string+="\""+(new String(this.word))+"\""+this.list;
    if (this.successor!=null) string+=this.successor;
    return string;
    public int treeNodeCount()
    /* something goes here*/
    return 26;
    public String wordArray(int length)
    /* something goes here*/
    return "hey hey wordarray";

    hey,
    ok, wow, that was intense, my brain hurts!!!!
    And now I've got to go do a graduate program test, argh!!!
    A problem I keep getting is trying to figure out what my lecturer is doing in the start of the Tree091 class,
    that is, I can see that he is constructing the list and tree but it appears that he is doing it all at the same time, and I'm getting confused with what actually gets inserted into the list, and do we insert the word, line and position, or just the line and position?
    Also, I didnt use a 'while loop', I'm not sure how, but I found a 'for loop' in the text book, what do you think of it? Is it ok for now?
    And I'm getting an error at this line:
    Tree091 ins = new Tree091(char[] word); // getting error '.class' expected here
    any ideas?
    heres what I've got so far:
    private void addIterative(Comparable char[] word,int line, int position){
    // Insert char[] word into the this BST     
         int direction = 0;     
         Tree091 parent = null, curr = root;
         for (;;) {     
              if (curr == null) {
                   Tree091 ins = new Tree091(char[] word); // getting error '.class' expected here
                   // word found so we call insertList method
                   insertList091(line, position, List091 precursor);
                   if (root) == null)
                        root = ins;
                   else if (direction < 0)     
                        parent.left = ins;
                   else // direction > 0
                        parent.right = ins;
                   return;
              direction = elem.compareTo(curr.element);
              if (direction == 0)
                   return;
              parent = curr;
              if (direction < 0)
                   curr = curr.left;
              else // direction > 0
                   curr = curr.right;
    }And heres an attempt at the insertList method
    private void insertList(char[] word, int line, int position, List091 precursor){
    // Insert line and position at a given point in this List091, either after the node
    // precursor, or before the first node if precursor is null
    // Looking at assignment question we may need a double linked list
         List091 ins = new List091 (char[] word, line, position, null);
         if precursor == null) { //insert before first node (if any).
              ins.successor = first;
              first = ins;
         } else {
              ins.successor = precursor.successor;
              precursor.successor = ins;
    }How far off am I Joachim?
    cheers,
    Jimmy
    ps. heres the tree091 class again:
    class Tree091 /*(i.e., WordTree)*/
    { private char[] word=null;
      private List091 list=null;
      private Tree091 precursor=null; /*(i.e., leftSubTree)*/
      private Tree091 successor=null; /*(i.e., rightSubTree)*/
      public Tree091(char[] word,
                     List091 list,
                     Tree091 precursor, /*(i.e., lexicographically < word)*/
                     Tree091 successor) /*(i.e., lexicographically > word)*/
      { if (word==null) return;
        if (word.length<1) return;
        if (list==null) return;
        this.word=word;
        this.list=list;
        this.precursor=precursor;
        this.successor=successor;
      public void add(char[] word,
                      int line,
                      int position,
                      boolean iterative)
      { if (word==null) return;
        if (word.length<1) return;
        if (line<0) return;
        if (position<0) return;
        if (iterative)
          this.addIterative(word,line,position);
        else
          this.addRecursive(word,line,position);
      private void addIterative(char[] word,
                                int line,
                                int position)
        /* students to complete */
      private void addRecursive(char[] word,
                                int line,
                                int position)
         /* students to complete */
      private int compare(char[] array1,
                          char[] array2)
      { if (array1==null) return -2;
        if (array2==null) return -2;
        int length1=array1.length;
        if (length1==0) return -2;
        int length2=array2.length;
        if (length2==0) return -2;
        int minLength=length1<length2?length1:length2;
        for (int i=0; i<minLength; i++)
        { if (array1<array2[i]) return -1;
    if (array1[i]>array2[i]) return 1;
    return length1==length2 ? 0 : length1<length2 ? -1 : 1;
    public boolean contained(char[] word)
    { int compare=compare(this.word,word);
    if (compare==1&&this.precursor!=null)
    return this.precursor.contained(word);
    if (compare==0) return true;
    if (compare==-1&&this.successor!=null)
    return this.successor.contained(word);
    return false;
    public int listNodeCount(boolean iterative)
    /* students to complete */
    public int maximumWordLength(int currentLength)
    /* students to complete */
    public String toString()
    { String string="";
    if (this.precursor!=null) string+=this.precursor;
    string+="\""+(new String(this.word))+"\""+this.list;
    if (this.successor!=null) string+=this.successor;
    return string;
    public int treeNodeCount()
    /* students to complete */
    public String wordArray(int length)
    /* students to complete */
    Edited by: allergy01 on Apr 25, 2009 9:19 PM
    Edited by: allergy01 on Apr 25, 2009 9:20 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Help with some code concerning threads, please.

    I get a crazy error when i run this program and press forward ('w') more then once. can anyone help?
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    public class NBoard extends JFrame implements KeyListener{
         int selection = 0;
         boolean selectionmade = false;
         final int WIDTH = 600;
         final int HEIGHT = 600;
         Image Viz =Toolkit.getDefaultToolkit().getImage(JOptionPane.showInputDialog("What character do you want?")+".gif");
         int XC = 50;
         int YC = 50;
         Thread moving = new Move();
         Unit Host = new Unit();
         public NBoard(){
              this.setSize(WIDTH,HEIGHT);
              selection = Integer.parseInt(JOptionPane.showInputDialog("What level design do you want?"));
              if(selection > 0){
                   selectionmade = true;
              addKeyListener(this);
              this.setVisible(true);
         public static void main(String args[]){
              new NBoard();
         public void paint(Graphics g){
              if(selectionmade == true){
                   selectionmade = false;
                   if(selection == 1){
                        g.setColor(Color.white);
                        g.fillRect(0,0,WIDTH,HEIGHT);
                        g.setColor(Color.black);
                        g.drawLine(WIDTH/2,0,WIDTH/2,HEIGHT);
                   if(selection == 2){
                        g.setColor(Color.white);
                        g.fillRect(0,0,WIDTH,HEIGHT);
                        g.setColor(Color.black);
                        g.drawLine(WIDTH/2,0,WIDTH/2,HEIGHT);
                        for(int ctr = 1; ctr < 6; ++ctr){
                             g.drawRect(WIDTH/4 ,ctr * 100, 20, 20);
                             g.drawRect((WIDTH / 3) * 2 ,ctr * 100, 20, 20);
                   if(selection == 3){
                        g.setColor(Color.white);
                        g.fillRect(0,0,WIDTH,HEIGHT);
                        g.setColor(Color.black);
                        g.drawLine((WIDTH/2) - 90,0,(WIDTH/2) + 90,HEIGHT);
                   g.drawImage(Viz,XC,YC,this);
              public void keyPressed(KeyEvent e){                              //The Problem Areas
                   if(e.getKeyChar() == 'w'){
                        moving.start();                                             //Starting the thread to move up
                   else if(e.getKeyChar() == 's'){
                        YC = YC + 2;
                   else if(e.getKeyChar() == 'a'){
                        XC = XC - 2;
                   else if(e.getKeyChar() == 'd'){
                        XC = XC + 2;
                   System.out.println(e.getKeyChar());
                   repaint();
         public void keyReleased(KeyEvent e){                              //The Problem Areas
              if(e.getKeyChar() == 'w'){
              System.out.println("YO ZAPPA");
                   moving.interrupt();                                             //Trying to interrupt the thread once the key is released
         public void keyTyped(KeyEvent e){}
    class Move extends Thread{                                                  //The Problem Areas
         Unit Host = new Unit();
         public void run(){                                                       //The Thread
              System.out.println("YO TESTING");
              Unit.XC = Unit.XC - 2;
              try{
                   Thread.sleep(1000);
              catch (Exception e){}
    class Unit{                                                                      //The Object which will hold all of the information about each unit
         static int XC = 30;
         static int YC = 30;
    }     Thank you!

    The problem is that each movement in each direction
    should be in its own thread, because later on i am
    going to try to network it so that more people can
    play. That's why it has to be in a thread. The game
    is basically gonna be a very simple rendition of
    dodgeball, although i want to get the movement right
    before I get to the ball.
    Thanks for the pseudo code, but the problem is
    implementing those commansd into a thread.
    All i want to do for now is to be able to press the
    'w' button, and make the guy move forward, while the
    program is capable of doing anything else. Any help
    in getting it to this stage would be appreciated.I have managed to rewrite you code to be compilable and runnable, however, I don't
    understand the roles of the 'w' key, Move class and Unit class in your game. So I have
    left out those parts.
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    public class NBoard2 extends JFrame implements KeyListener{
      int selection = 0;
      boolean selectionmade = false;
      final int WIDTH = 600;
      final int HEIGHT = 600;
      Image Viz
       = Toolkit.getDefaultToolkit().getImage(JOptionPane.showInputDialog
          ("What character do you want?")+".gif");
      int XC = 50;
      int YC = 50;
      Move moving;
      GamePanel gp;
      boolean notStarted;
      public NBoard2(){
        notStarted = true;
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(WIDTH, HEIGHT);
        selection
         = Integer.parseInt(JOptionPane.showInputDialog
            ("What level design do you want?"));
        if(selection > 0){
          selectionmade = true;
        addKeyListener(this);
        gp = new GamePanel();
        add(gp, BorderLayout.CENTER);
        setVisible(true);
        moving = new Move(this);
      public static void main(String args[]){
        new NBoard2();
      class GamePanel extends JPanel{
        public void paintComponent(Graphics g){
          super.paintComponent(g);
          if(selectionmade == true){
            selectionmade = false;
            if(selection == 1){
              g.setColor(Color.white);
              g.fillRect(0, 0, WIDTH, HEIGHT);
              g.setColor(Color.black);
              g.drawLine(WIDTH/2, 0, WIDTH/2, HEIGHT);
            else if(selection == 2){
              g.setColor(Color.white);
              g.fillRect(0, 0, WIDTH, HEIGHT);
              g.setColor(Color.black);
              g.drawLine(WIDTH / 2, 0, WIDTH / 2, HEIGHT);
              for(int ctr = 1; ctr < 6; ++ctr){
                g.drawRect(WIDTH/4, ctr * 100,  20, 20);
                g.drawRect((WIDTH / 3) * 2 , ctr * 100, 20, 20);
            else if(selection == 3){
              g.setColor(Color.white);
              g.fillRect(0, 0, WIDTH, HEIGHT);
              g.setColor(Color.black);
              g.drawLine((WIDTH / 2) - 90, 0, (WIDTH / 2) + 90, HEIGHT);
          g.drawImage(Viz, XC, YC, this);
      } // class GamePanel
      public void keyPressed(KeyEvent e){
        if(e.getKeyChar() == 'w' && notStarted == true){
          moving.stop = false;
          moving.start();
          notStarted = false;
        else if(e.getKeyChar() == 's'){
          YC = YC + 2;
        else if(e.getKeyChar() == 'a'){
          XC = XC - 2;
        else if(e.getKeyChar() == 'd'){
          XC = XC + 2;
        // System.out.println(e.getKeyChar());
        repaint();
      public void keyReleased(KeyEvent e){
        if(e.getKeyChar() == 'w'){
          //System.out.println("YO ZAPPA");
          moving.stop = true;
          notStarted = true;
          /* reinstantiate the thread, if you need it */
          moving = new Move(this); // Java Thread can't be reused
        }                          // Once finished its run()method,
      }                            // thread is no more in valid state
      // if you do not want to reinstantiate the Move thread at the second
      // 'w' press, write a proper conditional for that
      public void keyTyped(KeyEvent e){}
    } // class NBoard2
    class Move extends Thread{
      Unit Host = new Unit();
      public boolean stop = false;
      JPanel gpanel;
      public Move(NBoard2 bd){
        gpanel = bd.gp;
      public void run(){
        while (! stop){
          System.out.println("YO TESTING");
          Unit.XC = Unit.XC - 2;
          //// What Unit.XC does for NBoard2.XC or other drawing parameters???
          //// There's no logic written yet.
          //// In other words, Move and Unit class do not particpate in the game
          //// at all.
          gpanel.repaint(); // may be you need it here ??? or ??
          try{
            Thread.sleep(1000);
          catch (Exception e){
    class Unit{
      static int XC = 30;
      static int YC = 30;
    }You must learn basic of major aspects of Java programming. Tuorials at java.sum.com site are
    good for that.

  • Need some help with some code

    obviously:) why else would i be here?! anyways. I need to make a field where the user can fill in an e-mail address and when they click the submit button it goes to the e-mail address they entered. here is what i am working with so far. www.salvationroad.com/dice.html

    At present, I can't access the page. I guess you'll
    need JavaScript.TO: mrgli
    Note that this reply is to a 2-month old thread. Most of your other 13 posts are also to old, dead threads. As a new user of these boards, this is understandable. But by doing so, you cause others to spend time and energy ( as the posters following you, here, did) for no benefit.
    Please, if you're going to reply to threads found via a search, check the thread dates and reply only to current threads.
    If you have a solution to the problem that an old thread addressed, and the problem is still current, it's reasonable to post that solution - in moderation.
    Thanks

  • Help with some beginner code

    Hello, I am new to java and I need a bit of help with some code that I'm writing. here is the code:
    import javax.swing.*;
    public class Test{
         public static void main(String[] args){
         JOptionPane.showMessageDialog(null,"We will now build a block with *'s","Block",1);
         String input=JOptionPane.showInputDialog(null,"Type a number: ","Number",3);
         int number=Integer.parseInt(input);
         int count=0; int count2=0;
         for(count2=0; count2<number; count2++){
              for(count=0; count<number; count++){
              System.out.print("* ");
    System.exit(0);
    }Now, all I need is to build a block of *'s with the number that the user inputs. With the code that I wrote I get the correct number of *'s but not in the form of a block. They just print out in a straight line. I know this is a very simple task but could someone please help me out? What do I need to modify in my code so that the *'s print out arranged as a block like so:
    **********

    Your code only uses the print method which prints without a carriage return/line feed. So you need to add a line of code to print a carriage return/line feed. Where? well that is your task to work out.

  • Need help with WMI code that will send output to db

    'm new to WMI code writing, so I need some help with writing code that we can store on our server. I want this code to run when a user logs into their computer
    and talks to our server. I also want the code to:
    * check the users computer and find all installed patches
    * the date the patches were installed
    * the serial number of the users computer
    * the computer name, os version, last boot up time, and mac address
    and then have all this output to a database file. At the command prompt I've tried:
    wmic qfe get description, hotfixid
    This does return the patch information I'm looking for, but how do I combine that line of code with:
    wmic os get version, csname, serialnumber, lastbootuptime
    and
    wmic nicconfig get macaddress
    and then get all this to output to a database file?

    Thank you for the links. I checked out http://technet.microsoft.com/en-us/scriptcenter/dd793612.aspx and
    found lots of good information. I also found a good command that will print information to a text file.
    Basically what I'm trying to do is retrieve a list of all installed updates (Windows updates and 3rd party updates). I do like that the below code because it gives me the KB numbers for the Windows updates. I need this information so my IT co-workers &
    I can keep track of which of our user computers need a patch/update installed and preferably which patch/update. The minimum we want to know is which patches / updates have been installed on which computer. If you wondering why we don't have Windows automatic
    updates enable, that's because we are not allowed to.   
    This is my code so far. 
    #if you want the computer name, use this command
    get-content env:computername
    $computer = get-content env:computername
    #list of installed patches
    Get-Hotfix -ComputerName $computer#create a text file listing this information
    Get-Hotfix > 'C:\users\little e\Documents\WMI help\PowerShell\printOutPatchList.txt'
    I know you don't want to tell me the code that will print this out to a database (regardless if it's Access or SQL), and that's find. But maybe you can tell me this. Is it possible to have the results of this sent to a database file or do I need to go into
    SQL and write code for SQL to go out and grab the data from an Excel file or txt file? If I'm understanding this stuff so far, then I suspect that it can be done both ways, but the code needs to be written correctly for this to happen. If it's true, then which
    way is best (code in PowerShell to send information to SQL or SQL go get the information from the text file or Excel file)?

  • Want a complete migration guide to upgrade 11.1.0.7 to 11.2.0.3 database using DBUA..We are implementing R12.1.3 version and then have to migrate the default 11gR1 database to 11.2.0.3 version. Please help with some step by step docs

    Want a complete migration guide to upgrade 11.1.0.7 to 11.2.0.3 database using DBUA..We are implementing R12.1.3 version and then have to migrate the default 11gR1 database to 11.2.0.3 version. Please help with some step by step docs

    Upgrade to 11.2.0.3 -- Interoperability Notes Oracle EBS R12 with Oracle Database 11gR2 (11.2.0.3) (Doc ID 1585578.1)
    Upgrade to 11.2.0.4 (latest 11gR2 patchset certified with R12) -- Interoperability Notes EBS 12.0 and 12.1 with Database 11gR2 (Doc ID 1058763.1)
    Thanks,
    Hussein

  • Can you help with the code to publish Flash to my own domain.

    Thank you for your help, I publish the my site to my own domain, I do not use .Mac, I tested your code and ity works well on .Mac, can you help with the code to publish to my own domain.
    Thank you again

    You appear to have just collected a variety of code snippets and thrown them together, including a section of AS2 code ( gage.onRelease = function() {... )
    The suggestion I offered yesterday still stands.  You should find a tutorial regarding AS3 and the atan2 function.  Beyond that, what you show suggests this is a school assignment.  You should seek help from your fellow students and instructor if that is the case.

  • I need help with this code error "unreachable statement"

    the error_
    F:\Java\Projects\Tools.java:51: unreachable statement <-----------------------------------------------------------------------------------------------------------------THIS
    int index;
    ^
    F:\Java\Projects\Tools.java:71: missing return statement
    }//end delete method
    ^
    F:\Java\Projects\Tools.java:86: missing return statement
    }//end getrecod
    ^
    3 errors
    import java.util.*;
    import javax.swing.*;
    import java.awt.*;
    public class Tools//tool class
    private int numberOfToolItems;
    private ToolItems[] toolArray = new ToolItems[10];
    public Tools()//array of tool
    numberOfToolItems = 0;
    for(int i = 0; i < toolArray.length; i++)//for loop to create the array tools
    toolArray[i] = new ToolItems();
    }//end for loop
    }//end of array of tools
    public int search(int id)//search mehtod
    int index = 0;
    while (index < numberOfToolItems)//while and if loop search
    if(toolArray[index].getID() == id)
    return index;
    else
    index ++;
    }//en while and if loop
    return -1;
    }//end search method
    public int insert(int id, int numberInStock, int quality, double basePrice, String nm)//insert method
    if(numberOfToolItems >= toolArray.length)
    return 0;
    int index;
    index = search(id); <-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------HERE
    if (index == -1)
    toolArray[index].assign(id,numberInStock, quality, basePrice,nm);
    numberInStock ++;
    return 1;
    }//end if index
    }//end if toolitem array
    return -1;
    }//end insert method
    public int delete(/*int id*/)//delete method
    }//end delete method
    public void display()//display method
    for(int i = 0; i < numberOfToolItems; i++)
    //toolArray.display(g,y,x);
    }//end display method
    public String getRecord(int i)//get record method
    // return toolArray[i].getName()+ "ID: "+toolArray[i].getID()
    }//end getrecod
    }//end class
    Edited by: ladsoftware on Oct 9, 2009 6:08 AM
    Edited by: ladsoftware on Oct 9, 2009 6:09 AM
    Edited by: ladsoftware on Oct 9, 2009 6:10 AM
    Edited by: ladsoftware on Oct 9, 2009 6:11 AM

    ladsoftware wrote:
    Subject: Re: I need help with this code error "unreachable statement"
    F:\Java\Projects\Tools.java:51: unreachable statement <-----------------------------------------------------------------------------------------------------------------THIS
    int index;
    ^
    F:\Java\Projects\Tools.java:71: missing return statement
    }//end delete method
    ^
    F:\Java\Projects\Tools.java:86: missing return statement
    }//end getrecod
    ^
    3 errorsThe compiler is telling you exactly what the problems are:
    public int insert(int id, int numberInStock, int quality, double basePrice, String nm)//insert method
    if(numberOfToolItems >= toolArray.length)
    return 0; // <<== HERE you return, so everyting in the if block after this is unreachable
    int index;
    index = search(id);  //< -----------------------------------------------------------------------------------------------------------------HERE
    if (index == -1)
    toolArray[index].assign(id,numberInStock, quality, basePrice,nm);
    numberInStock ++;
    return 1;
    }//end if index
    }//end if toolitem array
    return -1;
    }//end insert method
    public int delete(/*int id*/)//delete method
    // <<== HERE where is the return statement?
    }//end delete method
    public String getRecord(int i)//get record method
    // return toolArray.getName()+ "ID: "+toolArray[i].getID() <<== HERE you commented out the return statement
    }//end getrecod
    }//end class

  • I need help with my code..

    hi guys. as the subject says I need help with my code
    the Q for my code is :
    write a program that reads a positive integer x and calculates and prints a floating point number y if :
    y = 1 ? 1/2 + 1/3 - ? + 1/x
    and this is my code
       This program that reads a positive integer x and calculates
       and prints a floating point number y if :
                 y = 1 - 1/2 + 1/3 - ? + 1/x
       import java.util.Scanner; // program uses class Scanner
        class Sh7q2
           // main method begins execution of Java application
           public static void main( String args[] )
          // create Scanner to obtain input from command window
             Scanner input = new Scanner( System.in );
             int i = 1; // i is to control the loop
             int n = 2; // n is suppose to control the number sign
             int x; // a positive integer entered by the user
             int m;
             System.out.println("Enter a positive integer");
             x = input.nextInt();
             do
                m = (int) Math.pow( -1, n)/i;
                System.out.println(m);
                   n++;
                   i++;
             while ( m >= 1/x );
          } // end method main
       } // end class Sh7q2 when I compile it there is no error
    but in the run it tells me to enter a positive integer
    suppose i entered 5
    then the result is 1...
    can anyone tell me what's wrong with my code

       This program that reads a positive integer x and calculates
       and prints a floating point number y if :
                 y = 1 - 1/2 + 1/3 - ? + 1/x
       import java.util.Scanner; // program uses class Scanner
        class Sh7q2
           // main method begins execution of Java application
           public static void main( String args[] )
          // create Scanner to obtain input from command window
             Scanner input = new Scanner( System.in );
             int i = 1; // i is to control the loop
             int n = 1; // n is suppose to control the number sign
             int x; // a positive integer entered by the user
             double m;
             int a = 1;
             double sum = 0;
             System.out.println("Enter a positive integer");
             x = input.nextInt();
             for ( i = 1; a <= x; i++)
                m =  Math.pow( -1, n+1)/i;
                sum  = sum + m;
                n++;
                a++;
             System.out.print("y = " + sum);
          } // end method main
       } // end class Sh7q2is it right :S

  • I need help with some simple code! Please read!

    hi everyone.
    I'm having problems with a piece of code, and i'd be extremely greatful if somebody could give me a hand with it. I'm totally new to java and have to make a program for my university degree, but i'm finding it extremely difficult, mainly due to my total lack of apptitude for this type of thing. I know this is easy stuff, but the books I have are no use so any help would be greatly appreciated.
    I have to write a program which uses two class files. I want one with the code to produce a simple button, and one to invoke it several times at different locations. I decided to write the program as one class file at first, and thought i'd be able to split it up at later. The program works fine when it is one class file. My book said that to split the two classes up, all i needed to do was change the second class to public, although this seems to not work at all. I'm at my wits end on this, and if anyone could correct my code I'd be eternally greatful.
    Here is the first class... (sorry about the lack of indentation)
    >>>>>>>>>>
    import java.awt.*;
    import java.applet.Applet;
    public class Phone extends Applet {
    private Image image;
    public void init() {
    setLayout(null);
    image = getImage(getDocumentBase(), "phone.jpg");}
    public void paint (Graphics g) {
    g.drawImage(image, 0, 0, 700, 530, this);
    PhoneButton myButton;
    myButton = new PhoneButton(20,20);
    >>>>>>>
    This is the second class....
    >>>>>>>
    public class PhoneButton {
    private Button butt;
    public PhoneButton(int a, int b, int c){
    setLayout(null);
    butt = new Button();
    butt.setBounds(a,b,20,20);
    add(butt);
    >>>>>>>>
    My compiler generates errors relating to Button, but i can't do anything to please it.
    Also, could anyone give me some pointers on how to add a different number or symbol to each button. That is what I added int c for, but i couldn't get it to work.
    Cheers in advance.
    Michael Morgan

    I found that there are 5 error in your code.
    1. You should import the "java.awt" package to the PhoneButton.java
    2. The PhoneButton is not a kind of Component. You cannot not add it to the Phone class
    3. the myButton = new PhoneButton(20, 20) does not provide enough parameters to create PhoneButton
    4. You cannot add a Button to a PhoneButton. Becaue the PhoneButton is not a kind of Container
    Fixed code:
    import java.awt.*;
    public class PhoneButton extends Button {
    public PhoneButton(int a, int b, int c){
         setBounds(a, b, 20, 20);
         setLabel(String.valueOf(c));
    ===========================================
    import java.awt.*;
    import java.applet.Applet;
    public class Phone extends Applet {
    private Image image;
    public void init() {
    setLayout(null);
    image = getImage(getDocumentBase(), "phone.jpg");}
    public void paint (Graphics g) {
    g.drawImage(image, 0, 0, 700, 530, this);
    PhoneButton myButton;
    myButton = new PhoneButton(20,20, 1);
    ======================
    Visual Paradigm for UML - Full Features UML CASE tool
    http://www.visual-paradigm.com/

  • Help with some java login code

    hey,
    I am a new member but used to visit the site regularly. I am undergoing a java project and I cannot seem to get my head around how to code when users log in, there name must appear at the top of each page they visit.
    User enters name into a text box. Do I use getter and setter methods? any bit of help would be of some advantage to me.
    Thanks for your time and I'll help with anyone else who is stuck.

    if JSP or servlet use Session...
    if you are using frame you have to consider... which frame is a top parent. that top frame will have the set and get method.. for you to set and retrieve the user name.. bear in mind that different object will have different user...
    so you have to play fair game ...hehehehe :-)

  • Trouble with some code  help please

    i need help with this program i have to do a webclient in java i will put here the instructions that were given to me and then the work i have been doing so you can have an idea of what i'm doing any help you give me i will be very thankful thanks.
    Here are the instructions
    The class WebClient will represent a simple web client. This class must provide the following functions:
    1. connect to a web page using a URL
    2. obtain or get the response from a server
    This funcionality will be provided by the public interface of the class:
    - WebClient( )
    Creates a new object of the class
    - void setURL(String url)
    Used to indicate the URL of the web page
    - String getResponse()
    Gets the response of the server to the page who's URL was indicated(Example of a response: HTTP/1.0 200 OK)
    You have to implement the following:
    1. The class WebClient with an public interface that Includes the methods specified upwards, in a file called WebClient.java
    2.A class WebClientTester, in a file called WebClientTester.java, with a main program that minimun have to:
    a) Create a instance of WebClient
    b) Using 3 valid URL's
    - Invoque setURL to indicate the URL of the server
    - Invoque getResponse to get the response of the server
    - display in the console the response of the server
    c) Using 3 invalid URL's (this is the correct server but the page does not are on the server)
    - Invoque setURL to indicate the URL of the server
    - Invoque getResponse to get the response of the server
    - display in the console the response of the server
    As a tip they give me that i can use the clases HttpURLConnection and URL to implement WebClient. It is recommended to save the URL in an instance field of WebClient.
    Those are the instructions now i will write here what i have do until now
    This is the WebClient Class:
    public class WebClient
         public String Wecli;
         public WebClient()
              Wecli = new String();
         public void setURL(String url)
         /** need code here */     
         public String getResponse()
         /** need code here */     
         public void display()
              System.out.println(Wecli);
    what i need there is the methods constructors or whatever are so that setURL and getResponse work and do what are suposed to do.
    Here is The WebClientTester class
    public class WebClientTester
         public static void main(String[] args)
              WebClient wbcl = new WebClient();
              wbcl.setURL(http://www.nba.com);
              wbcl.getResponse();
              wbcl.display();
              wbcl.setURL(http://www.mlb.com);
              wbcl.getResponse();
              wbcl.display();
              wbcl.setURL(http://www.msn.com);
              wbcl.getResponse();
              wbcl.display();
         wbcl.setURL(http://www.nba.com/baseball.html);
              wbcl.getResponse();
              wbcl.display();
         wbcl.setURL(http://www.mlb.com/basketball.html);
              wbcl.getResponse();
              wbcl.display();
         wbcl.setURL(http://www.msn.com/practice.html);
              wbcl.getResponse();
              wbcl.display();
    that is basically what i think i need so that the program works any other help you can give me will be very useful thanks for reding it and give your opinions.

    Those are the instructions now i will write here what i have do until nowLooks like you've posted your homework instructions, done less than the bare minimum to make it look like you thought about this problem, and now you want strangers to help you cheat by giving you the code that does the work so you can hand it in as your own.
    %

Maybe you are looking for