Assistance with good programming

Hey!
I'm new to this Java game like most of the rest of us on here. I've just finished testing my first big project (calling methods etc.- all quite basic stuff)
but I'm wondering if anyone out there could spare five minutes just to help me on the 'good programming' side of things.
I didn't bother posting the code, but if someone can help me out I can get it to them.
Many MANY thanks, and hopefully one day I'll be able to answer some of the other beginner questions myself!
CoosMC

From my limited programming knowledge, i believe that you are only suppose to put your variables outside of a method if absolutely necessary. This is because when the variables are declared outside of the method they are called global and will use up memory the entire time the program is running, compared to local variables which only use up memory when the specific method is called.
As for the repeating of the variables as 0 or none outside AND inside the main method. If you are using global variables, then there is no need to repeat the numbers inside the main method, unless the values of the variables change AND the main method is called more than once in your program. Since your variables are within a while loop, then you will have to repeat the numbers if you want the same starting point every time. If you want the variables to keep the value of the previous loop, then do not put the 0 at the beginning.
As for if private static int claimnum = 0 is necessary. take a look here to learn more about that and look at "Access Attributes" for more info as well as the rest of this tutorial.
http://developer.java.sun.com/developer/onlineTraining/new2java/divelog/part1/page4.jsp
anyone out there, please correct me if i'm wrong.
i'm still a bit of a rookie myself.
Andy

Similar Messages

  • I downloaded Adobe Acrobat XI Pro - I signed in and now all I get is the Adobe Download Assistant with a prompt to keep downloading the program or help page.

    I downloaded Adobe Acrobat XI Pro - I signed in and now all I get is the Adobe Download Assistant with a prompt to keep downloading the program or help page. How can I launch the actual program and not the Assistant?
    Under the download or application file I only have the Assistant program

    Moving this discussion to the Acrobat Installation & Update Issues forum.
    Isabellasf have you ran the installation files which were downloaded?  By default they are downloaded to the download folder within your User folder.

  • What's a good program to use to make flyers and handouts with?

    What's a good program to use to make flyers and handouts with? I'm not a wiz with computers so nothing too sophisticated is needed. Thanks!

    Pages would be fine but there are hundreds, I'd recommend using the Mac App Store.

  • Help with Inventory Program

    Hello,
    I am new to Java programming and I need some assistance in trying to complie my program correctly. I would greatly appreciate it.
    I have started my program, but keep getting the same two compile errors.
    C:\Program Files\Java\Product.java:91: illegal start of expression
    public InventoryPart1(String name, double number, double units, double price)
    ^
    C:\Program Files\Java\Product.java:113: class, interface, or enum expected
    }//end class InventoryPart1
    My assignment ask:
    Choose a product that lends itself to an inventory (for example, products at your workplace, office supplies, music CDs, DVD movies, or software).
    Create a product class that holds the item number, the name of the product, number of units in stock and the price of each unit.
    Create a Java application that displays the product number, the name of the product, number of units in stock, the price of each unit, and the value of inventory (the number of units multiplied by price of each unit). Pay attention to the good programming practices in the text to ensure your source code is readable and well documented.
    This is what I have so far.
    * Product.java
    * @author Amy Summers
    * A class created as a Product
    * which hold information with a constructor
    //Create and manipulate a Product class.
    import java.util.Scanner;//program uses Scanner
    class Product
    private String nameIn;
    private double numberIn;//item number
    private double unitsIn;//number of units in stock
    private double priceIn;//price of each unit
         //four-argument constructor
    public Product( String nameIn, double numberIn,
    double unitsIn, double priceIn )
    //implicit call to Object constructor occurs here
         nameIn = nameIn;
         numberIn = numberIn;
         unitsIn = unitsIn;
         priceIn = priceIn;
              }//end four-argument Product constructor
              // set product name
              public void setNameIn (String name)
    name = nameIn;
              }//end method setNameIn
              //return product name
              public String getNameIn()
         return nameIn;
              }//end method getNameIn
              // set number
              public void setNumberIn (double number)
              number = numberIn;
              }//end method setNumberIn
              //return number
              public double getNumberIn()
         return numberIn;
              }//end method getNumberIn
                   //set units
                   public void setUnitsIn ( double units)
                   units = unitsIn;
                   }//end method setUnitsIn
                   //return units
                   public double getUnitsIn()
                   return unitsIn;
                   }//end method getUnitsIn
                   //set price
                   public void setPriceIn (double price)
                   price = priceIn;
                   }//end method set priceIn
                   //return price
                   public double getPriceIn()
                   return priceIn;
                   }//end method getPriceIn               
    }//end class Product
    * InventoryPart1.java
    * @author Amy Summers
    public class InventoryPart1
         private String Productname;//product name for this
    InventoryPart1     
         //constructor initializes productName
         public InventoryPart1(String name, double number,
    double units, double price)
              Product myProduct1 = new Product
    ();//initializes productName
                   System.out.printf("%s%s\n", "Name",
                   getnameIn() );//display name
                   System.out.printf("%s%
    s\n", "Number",
                   getnumberIn() );//display number
                   System.out.printf("%s%s\n", "Units",
                   getunitsIn() );//display units
                   System.out.printf("$%.2f\n", "Price",
                   getpriceIn() );//display price
                   value = unitsIn * priceIn;//mulitple
    numbers
                   System.out.printf("$%.2f\n",
    value);//display inventory value
         }//end main method
    }//end class InventoryPart1

    * Product.java
    * @author Amy Summers
    * A class created as a Product
    * which hold information with a constructor
    //Create and manipulate a Product class.
    import java.util.Scanner;//program uses Scanner
    class Product
          private String nameIn;
          private double numberIn;//item number
          private double unitsIn;//number of units in stock
          private double priceIn;//price of each unit
           //four-argument constructor
        public Product( String nameIn, double numberIn, double unitsIn, double priceIn )
                //implicit call to Object constructor occurs here
                     nameIn = nameIn;
                     numberIn = numberIn;
                     unitsIn = unitsIn;
                     priceIn = priceIn;
                    }//end four-argument Product constructor
                    // set product name
                    public void setNameIn (String name)
                name = nameIn;
                   }//end method setNameIn
                   //return product name
                    public String getNameIn()
                    return nameIn;
                    }//end method getNameIn
                    // set number
                    public void setNumberIn (double number)
                  number = numberIn;
                    }//end method setNumberIn
                     //return number
                    public double getNumberIn()
                    return numberIn;
                   }//end method getNumberIn
                   //set units
                   public void setUnitsIn ( double units)
                   units = unitsIn;
                   }//end method setUnitsIn
                   //return units
                   public double getUnitsIn()
                   return unitsIn;
                   }//end method getUnitsIn
                   //set price
                   public void setPriceIn (double price)
                   price = priceIn;
                   }//end method set priceIn
                   //return price
                   public double getPriceIn()
                   return priceIn;
                   }//end method getPriceIn               
    }//end class Product
    * InventoryPart1.java
    * @author Amy Summers
    public class InventoryPart1
         private String Productname;//product name for this InventoryPart1     
         //constructor initializes productName
         public InventoryPart1(String name, double number, double units, double price)
              Product myProduct1 = new Product();//initializes productName
                   System.out.printf("%s%s\n", "Name",
                   getnameIn() );//display name
                   System.out.printf("%s%s\n", "Number",
                   getnumberIn() );//display number
                   System.out.printf("%s%s\n", "Units",
                   getunitsIn() );//display units
                   System.out.printf("$%.2f\n", "Price",
                   getpriceIn() );//display price
                   value = unitsIn * priceIn;//mulitple numbers
                   System.out.printf("$%.2f\n", value);//display inventory value
         }//end main method
    }//end class InventoryPart1Sorry about that.

  • Overheating MacBook running Windows XP with CAD program

    Every time I run the Autosketch program with Windows XP, the laptop overheats and the fan becomes extremely noisy. The over heating occurs only when in Windows.
    What can I do to overcome this problem?
    Thanks for your assistance.

    welcome to windoze.
    you'll have to contact the software vendor, it's their app doing it, must be running the CPU / GPU pretty hard. My guess is that the fix is probably a desktop machine with good power & cooling.
    tho a good machine, macbook is a consumer oriented machine that wasn't designed to run pro CAD software.
    Message was edited by: kmac1036

  • Problems with square root approximations with loops program

    i'm having some trouble with this program, this loop stuff is confusing me and i know i'm not doing this correctly at all. the expected values in the tester are not matching up with the output. i have tried many variations of the loop in this code even modifying the i parameter in the loop which i guess is considered bad form. nothing seems to work...
    here is what i have for my solution class:
    /** A class that takes the inputted number by the tester and squares it, and
    *  loops guesses when the nextGuess() method is called. The epsilon value is
    *  also inputted by the user, and when the most recent guess returns a value
    *  <= epsilon, then the hasMoreGuesses() method should return false.
    public class RootApproximator
       /** Takes the inputted values from the tester to construct a RootApproximator.
        * @param val the value of the number to be squared and guessed.
        * @param eps the gap in which the approximation is considered acceptable.
         public RootApproximator(double val, double eps)
              value = val;
              square = Math.sqrt(val);
              epsilon = eps;
       /** Uses the algorithm where 1 is the first initial guess of the
        *  square root of the inputted value. The algorithm is defined by
        *  "If X is a guess for a square root of a number, then the average
        *  of X and value/X is a closer approximation.
        *  @return increasingly closer guesses as the method is continually used.
       public double nextGuess()
             final int TRIES = 10000;
             double guess = 1;
              for (double i = 1; i < TRIES; i++)
                   double temp = value / guess;
                   guess = (guess + temp) / 2.0;
              return guess;
       /** Determines if there are more guesses left if the difference
        *  of the square and current guess are not equal to or less than
        *  epsilon.
        *  @return the value of the condition.
       public boolean hasMoreGuesses()
              return (square - guess <= epsilon);
       private double square;
       private double value;
       private double epsilon;
       private double guess;
    here is the tester:
    public class RootApproximatorTester
       public static void main(String[] args)
          double a = 100;
          double epsilon = 1;
          RootApproximator approx = new RootApproximator(a, epsilon);
          System.out.println(approx.nextGuess());
          System.out.println("Expected: 1");
          System.out.println(approx.nextGuess());
          System.out.println("Expected: 50.5");
          while (approx.hasMoreGuesses())
             approx.nextGuess();
          System.out.println(Math.abs(approx.nextGuess() - 10) < epsilon);
          System.out.println("Expected: true");
    and here is the output:
    10.0
    Expected: 1 // not sure why this should be 1, perhaps because it is the first guess.
    10.0
    Expected: 50.5 // (100 + 1) / 2, average of the inputted value and the first guess.
    true
    Expected: true
    i'm new to java this is my first java course and this stuff is frustrating. i'm really clueless as to what to do next, if anyone could please give me some helpful advice i would really appreciate it. thank you all.

    i'm new to java this is my first java course and this
    stuff is frustrating. i'm really clueless as to what
    to do nextMaybe it's because you don't have a strategy for what the program is supposed to do? To me it looks like a numerical scheme for finding the squareroot of a number.
    Say the number you want to squarerroot is called value and that you have an approximation called guess. How do you determine whether guess is good enought?
    Well in hasMoreGuesses you check whether,
    (abs(value-guess*guess) < epsilon)
    The above decides if guess is within epsilon of being the squareroot of value.
    When you calculate the next guess in nextGuess why do you loop so many times? Aren't you supposed to make just one new guess like,
    guess = (guess + value/guess)/2.0
    The above generates a new guess based on the fact that guess and value/guess must be on each side of value so that the average of them must be closer too value.
    Now you can put the two together to a complete algoritm like,
    while (hasMoreGuesses()) {
       nextGuess();
    }In each iteration of the loop a new "guess" of the squareroot is generated and this continues until the guess is a sufficiently close approximation of the squareroot.

  • Need help to draw a graph from the output I get with my program please

    Hi all,
    I please need help with this program, I need to display the amount of money over the years (which the user has to enter via the textfields supplied)
    on a graph, I'm not sure what to do further with my program, but I have created a test with a System.out.println() method just to see if I get the correct output and it looks fine.
    My question is, how do I get the input that was entered by the user (the initial deposit amount as well as the number of years) and using these to draw up the graph? (I used a button for the user to click after he/she has entered both the deposit and year values to draw the graph but I don't know how to get this to work?)
    Please help me.
    The output that I got looked liked this: (just for a test!) - basically this kind of output must be shown on the graph...
    The initial deposit made was: 200.0
    After year: 1        Amount is:  210.00
    After year: 2        Amount is:  220.50
    After year: 3        Amount is:  231.53
    After year: 4        Amount is:  243.10
    After year: 5        Amount is:  255.26
    After year: 6        Amount is:  268.02
    After year: 7        Amount is:  281.42
    After year: 8        Amount is:  295.49
    After year: 9        Amount is:  310.27
    After year: 10        Amount is:  325.78
    After year: 11        Amount is:  342.07
    After year: 12        Amount is:  359.17
    After year: 13        Amount is:  377.13
    After year: 14        Amount is:  395.99
    After year: 15        Amount is:  415.79
    After year: 16        Amount is:  436.57
    After year: 17        Amount is:  458.40And here is my code that Iv'e done so far:
    import javax.swing.*;
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.RenderingHints;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.lang.Math;
    import java.text.DecimalFormat;
    public class CompoundInterestProgram extends JFrame implements ActionListener {
        JLabel amountLabel = new JLabel("Please enter the initial deposit amount:");
        JTextField amountText = new JTextField(5);
        JLabel yearsLabel = new JLabel("Please enter the numbers of years:");
        JTextField yearstext = new JTextField(5);
        JButton drawButton = new JButton("Draw Graph");
        public CompoundInterestProgram() {
            super("Compound Interest Program");
            setSize(500, 500);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            amountText.addActionListener(this);
            yearstext.addActionListener(this);
            JPanel panel = new JPanel();
            panel.setBackground(Color.white);
            panel.add(amountLabel);
            amountLabel.setToolTipText("Range of deposit must be 20 - 200!");
            panel.add(amountText);
            panel.add(yearsLabel);
            yearsLabel.setToolTipText("Range of years must be 1 - 25!");
            panel.add(yearstext);
            panel.add(drawButton);
            add(panel);
            setVisible(true);
            public static void main(String[] args) {
                 DecimalFormat dec2 = new DecimalFormat( "0.00" );
                CompoundInterestProgram cip1 = new CompoundInterestProgram();
                JFrame f = new JFrame();
                f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                f.getContentPane().add(new GraphPanel());
                f.setSize(500, 500);
                f.setLocation(200,200);
                f.setVisible(true);
                Account a = new Account(200);
                System.out.println("The initial deposit made was: " + a.getBalance() + "\n");
                for (int year = 1; year <= 17; year++) {
                      System.out.println("After year: " + year + "   \t" + "Amount is:  " + dec2.format(a.getBalance() + a.calcInterest(year)));
              @Override
              public void actionPerformed(ActionEvent arg0) {
                   // TODO Auto-generated method stub
    class Account {
        double balance = 0;
        double interest = 0.05;
        public Account() {
             balance = 0;
             interest = 0.05;
        public Account(int deposit) {
             balance = deposit;
             interest = 0.05;
        public double calcInterest(int year) {
               return  balance * Math.pow((1 + interest), year) - balance;
        public double getBalance() {
              return balance;
    class GraphPanel extends JPanel {
        public GraphPanel() {
        public void paintComponent(Graphics g) {
            Graphics2D g2 = (Graphics2D)g;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            g2.setColor(Color.red);
    }Your help would be much appreciated.
    Thanks in advance.

    watertownjordan wrote:
    http://www.jgraph.com/jgraph.html
    The above is also good.Sorry but you need to look a bit more closely at URLs that you cite. What the OP wants is a chart (as in X against Y) not a graph (as in links and nodes) . 'jgraph' deals with links and nodes.
    The best free charting library that I know of is JFreeChart from www.jfree.org.

  • Having a few issues with several programs (tor / mpd / ccm..)

    Hey everybody,
    I'll arrange this post in 3 parts since I have 3 different kinds of "major" problems or questions .
    1st ( tor - privoxy - polipo - iptables )
    I somehow found this article in your wiki and therefore tried to get tor and privoxy up and running on my desktop machine, as this didn't work as I hoped it would I searched farther in the wiki and installed and configured (as far as I've thought of) polipo and iptables.
    Now I've put all 4 of them in my rc.conf, but somehow some of my http connections don't seem to work in chromium while iptables is running (https works fine though [e.g. archwiki works, youtube doesn't]).
    I did everything as suggested in the polipo wiki entry, meaning I changed my /etc/iptables/iptables.rules to
    *nat
    :PREROUTING ACCEPT [0:0]
    :POSTROUTING ACCEPT [0:0]
    :OUTPUT ACCEPT [0:0]
    -A OUTPUT -p tcp --dport 80 -m owner --uid-owner polipo -j ACCEPT
    -A OUTPUT -p tcp --dport 80 -j REDIRECT --to-ports 8123
    COMMIT
    and removed all proxy settings from my browser - meaning all corresponding flags in the startcommand. I also added "forward / localhost:8123" to the privoxy config and changed the polipo configuration according to the wiki in order to work with tor (the socksParentProxy, socksProxyType part).
    now the next problem - that might probably be related to the first - is that my privoxy doesn't load in daemon mode anymore.
    I think it's since I've installed polipo that privoxy began to refuse starting together with the other daemons
    [usR@machine ~]$ privoxy
    Apr 23 00:20:56.459 b75086c0 Fatal error: can't check configuration file '/home/usR/config': No such file or directory
    this is the output I get when I try to start privoxy in normal user mode from the terminal, when I try starting the daemon manually (/etc/rc.d/privoxy start) it says
    touch: cannot touch `/var/log/privoxy/logfile': Permission denied
    chgrp: cannot access `/var/log/privoxy/logfile': Permission denied
    chmod: cannot access `/var/log/privoxy/logfile': Permission denied
    touch: cannot touch `/var/log/privoxy/jarfile': Permission denied
    chgrp: cannot access `/var/log/privoxy/jarfile': Permission denied
    chmod: cannot access `/var/log/privoxy/jarfile': Permission denied
    Apr 23 00:22:34.490 b76396c0 Fatal error: Cannot setgid(): Insufficient permissions.
    [/var/log/privoxy belongs to privoxy:adm]
    when I do the same in sudo mode it just fails without displaying an error message..
    I added this code to the /etc/rc.d/privoxy executable but I still get this owner conflict error and I have no idea what might be causing it.
    if [ ! -d /var/log/privoxy ]
    then
    mkdir /var/log/privoxy
    touch /var/log/privoxy/errorfile
    touch /var/log/privoxy/logfile
    chown -R privoxy:adm /var/log/privoxy
    fi
    If the order of the daemons in rc.conf is of any real importance here a copy of my setup
    ( @polipo @privoxy @syslog-ng !set-hw-addr !iptables @network netfs hddtemp @crond hal dbus @alsa @slim @tor )
    2nd ( mpd & mpc )
    I'm just wondering if there's a way to output the position of a track in the current playlist combined with a search. since mpc search <type> <query> only prints out full file path and name, but not the position in the playlist so that you could play it with mpc play. I thought of a method to print out the whole list with mpc playlist and pipe this output into a listing program, than grep out the song I'm looking for all that in a little bash script, to replace mpc search.
    Is there an integrated mpc search function that works the way I imageine it and my idea therefore redundant, or if not, is it realizable the way I picture it; does such a listing program exist?
    3rd ( cairo-compmgr )
    Since I'm already posting here I thought I'd mention my older problem which I  still couldn't solve.
    1st) I need to start cairo-compmgr(-git) in sudo mode to be able to edit any settings or activate the gui in any way. how do I automatically start the program on startup in sudo mode? I tried editing ~/.fluxbox/startup & ~/.fluxbox/init, even tried adding it in /etc/rc.d/ and /etc/rc.conf in order to start it as a daemon (lol, noob) but none of that worked properly obviously Any ideas? I don't want to start it manually and "waste" a terminal window for that every time I boot.
    2nd) I can change opacity (transparency) in both versions only per hotkey, and when I do so the settings don't get saved, they even get reset to normal opacity as soon as another window gets selected. does anybody know if there's a config file or any way to save opacity settings for certain windows & programs, so that they automatically get loaded when cairo starts and stay applied until it gets closed?
    [or generally: how do I configure the Plugins? ]
    the last "problem" which occurs only with cairo-compmgr-git:
    When I rightclick the ccm icon in the task bar and disable the composite desktop, the whole program kills itself oO
    In the old version the option "Composite desktop"'s box just got un-checked and I could easily restart ccm by rightclicking the logo again and re-enabling the "Composite desktop" option.
    Any clues on that by any chance?
    I'm using Fluxbox by the way, if that's of any importance for any of the problems. hope I didn't forget any important information if so please remind me
    Would be thankful for any kind of help
    have a nice weekend
    deF
    //edit:
    concernig the tor / privoxy problem, I managed getting all the daemons to start up at bootup again, my iptables situation remains the same though.
    I went through all the config files again and played around with chown and chmod a little and for now the system is stable, everytime I reboot all the daemons start without any problems.
    but when i start chromium with --proxy-server=localhost:8118 now, I get the following error message
    The following error occurred while trying to access http://torcheck.xenobite.eu/index.php?:
    504 Connect to torcheck.xenobite.eu:80 failed: SOCKS error: network unreachable
    Generated Sat, 23 Apr 2011 04:49:08 CEST by Polipo on archzor.localdomain:8118.
    notably with all programs running now, tor, polipo, privoxy (and by now dansguardian as well)..
    I'm tired so I'll go asleep now, maybe I'll find something tomorrow in the logfiles or whatever, so far:
    every kind of help is still very appreciated
    ²
    /var/log/polipo/polipo.log
    Disabling disk cache: No such file or directory
    Couldn't bind: Address already in use
    Couldn't establish listening socket: Address already in use
    Couldn't bind: Address already in use
    Last edited by deF291 (2011-04-23 03:13:48)

    okay I've finally been able to get tor and all the other programs to work according to my plan the only thing that's still making problems is that iptables doesn't work as I want it to, when I start chromium without proxy settings privoxy doesn't seem to forward the information to polipo.. do I need to add another rule to iptables.rules in order for the program to know it has to reroute the information again or how can I get this to work? and is there any way to run rtorrent with proxy support?
    anyway, problem 2 and 3 are still to be solved.
    and does anybody know where i can get a good dansguardian blacklist that was not designed for 6 year old children and for which I don't need to subscribe? I'm still getting these partypoker popups -.-
    //e: with iptables it's the same thing as described in the first post. https works, http doesnt. I get the output "Invalid header received from client." on http sites. still no idea why though.. (and the https-version of torcheck.xenubite says i'm tor unprotected while starting the browser with iptables)
    Last edited by deF291 (2011-04-23 16:16:31)

  • How to Rename a Topic ID in Map File to Avoid Conflict with Another Program?

    Robo 8 HTML:
    Can somebody assist me in understanding how to rename a topic ID in my map.h file?
    An application programmer informs me there are nine topic IDs (shown below) in my project map file which conflict with predefined names of constants/functions from the Visual Studio Libs program and, is requesting I change the names of the topics listed below to resolve topic ID conflict in order to enable F1 call for these topics.
    #define Open    59
    #define Save    60
    #define Print   63
    #define Cut     72
    #define Copy    73
    #define Paste   74
    #define Clear   75
    #define Status  81
    #define Substructure  139
    Can I simply alter the topic names and retain their associated map numbers in <Create/Edit Map ID> dialog to resolve the map file conflict with Visual Studio Libs program functions? Or, is there more work involved in changing a topic name in a map.h file?
    Any assistance with this question is greatly appreciated.
    Thanks,
    robert

    Hi,
    Simply renaming the TopicID's in the .h file won't work. The TopicID is used in the alias file (projectname.ali) to link a map number with a topic. Also, you can use either TopicID's or map numbers to call the help. (Using TopicID's only works for WebHelp afaik.)
    If you use map numbers to call the help, you can rename the TopicID using the mentioned dialog. No problem.
    If you want to change the ID from the files, you have to change both the .h file as the .ali file. No changes to topics needed.

  • Since I've installed Mountain Lion, I am having lock up issues with multiple programs. MS Outlook has crashed and I've lost all my folders. HELP?

    Since I've installed Mountain Lion, I am having lock up issues with multiple programs. MS Outlook has crashed and I've lost all my folders. HELP?

    okay I've finally been able to get tor and all the other programs to work according to my plan the only thing that's still making problems is that iptables doesn't work as I want it to, when I start chromium without proxy settings privoxy doesn't seem to forward the information to polipo.. do I need to add another rule to iptables.rules in order for the program to know it has to reroute the information again or how can I get this to work? and is there any way to run rtorrent with proxy support?
    anyway, problem 2 and 3 are still to be solved.
    and does anybody know where i can get a good dansguardian blacklist that was not designed for 6 year old children and for which I don't need to subscribe? I'm still getting these partypoker popups -.-
    //e: with iptables it's the same thing as described in the first post. https works, http doesnt. I get the output "Invalid header received from client." on http sites. still no idea why though.. (and the https-version of torcheck.xenubite says i'm tor unprotected while starting the browser with iptables)
    Last edited by deF291 (2011-04-23 16:16:31)

  • Need advise on large file processing with good performance

    Hi All,
    I am working on a program in which I have to read millions of records from application server file.For this, I am reading 1 million records each time and uploading into the DB-table.
    what is the best approach to process the millions of records.what I am currently doing is, I read 1 million records one by one , modify each and every record based on some conditions and store them in one internal table and update the DB table.
    I am also thinking alternate approach is,read 1 million into one internal table and after that within the loop, modify each and every records for given condition and update the DB table.
    which approach is the best one?
    you can advise me any other alternate approches with good performance.
    Regards,
    Nivas
    Edited by: Nivas4081 on Jul 24, 2008 2:55 PM

    Hi Joshi,
    Thanks for your reply reply. I have tested both ways as I mentioned in my query but reading record by reocrd and update data packets takes less time than reading into iternal table,then modify and update the DB table.
    Hi ralph,
    Thanks for the reply.
    The modifications are similar in all the lines.I get related data from other class/method,do some calculation and modify each each record.
    Are there any performnace tricks to be followed when processing large amount of data.by the way I am reading certail amount of records say 400K and updating DB table using parallel processing.
    Apart from this, any suggestions on this?
    Regards,
    Nivas

  • Beginner with a programming problem

    I am getting quite frustrated trying to figure out how to proceed with a Java program I've been assigned. I'm hoping that my problem is not too amorphous to warrant assistance.
    The program is an exercise in Swing and creating GUI's, and at this stage, I only need to create an array of dice objects which can paint themselves on a JPanel. The instructor has given us two files -- one extending JPanel and containing a main method to test the classes, and another which represents a die.
    Some issues are
    1) I don't know where to call repaint.
    2) When the overridden paintComponent method is called, it wipes out
    the background color on my panel, which I set in the constructor.
    3) I got null pointer exceptions when I ran the instructor 's main method... I moved the setVisible up in the chain and they went away (Though he stated not to alter the main method, I don't know enough about Java Graphics to know if it's his mistake or mine)
    4) I'd just like to see some something appear.
    I should add that I rewrote this whole thing in one file (without using an array) and was able to get the graphics to paint.
    Sorry for posting copious amounts of code, but hopefully it will clear up what I'm trying to do. If anyone could just give me some pointers in the right direction, I would greatly appreciate it. Thank you for your time.
    //      File:  DicePanel.java
    public class DicePanel extends JPanel
      private int number_of_dice = 0;
      private DiceDrawn [] dice; 
      /** The x,y coordinates where the first die is drawn */
      private int xCoordinate = 5; //default
      private int yCoordinate = 5; //default
      /** Constructor with default properties */
      public DicePanel()
        this.setSize(getPreferredSize());
        this.setBackground(Color.blue);
        // set size and color
      /*  Set the Dice array  */
      public void setDice(DiceDrawn[] d)
      }// end setDice
      /** Return xCoordinate */
      public int getXCoordinate()
        return xCoordinate;
      /** Set a new xCoordinator */
      public void setXCoordinate(int x)
         xCoordinate = x;
      /** Return yCoordinator */
      public int getYCoordinate()
        return yCoordinate;
      /** Set a new yCoordinator */
      public void setYCoordinate(int y)
         yCoordinate = y;
      /** Paint the Dice Panel */
      protected void paintComponent(Graphics g)
        super.paintComponent(g);
        for (int i = 0; i < dice.length; i++ )
          dice.drawDie(g, xCoordinate, yCoordinate);
    setXCoordinate(getXCoordinate() + 41);
    // draw each die using default start coordinates,
    // moving right each time
    /** Override get method for preferredSize */
    public Dimension getPreferredSize()
    return new Dimension(200, 50);
    // the main method to test DicePanel and DiceDrawn
    // do not change this method.
    public static void main(String [] args)
    JFrame f = new JFrame();
    // f.setVisible(true);
    f.setTitle("Draw Dice");
    f.setSize(500,400);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container cp = f.getContentPane();
    // show 6 dice initially
    DiceDrawn [] dice = new DiceDrawn [6];
    for(int i = 0; i < dice.length; i++)
    dice[i] = new DiceDrawn(i+1);
    DicePanel dicePanel = new DicePanel();
    dicePanel.setDice(dice);
    System.out.println(dice.length);
    cp.add(dicePanel, BorderLayout.NORTH);
    f.setVisible(true);
    // show only one die for the rest of the program
    dice = new DiceDrawn [1];
    System.out.println("Dice Drawn Class Test");
    int i = Io.readInt("Enter an integer between 1 and 6");
    while( i > 0 )
    dice[0] = new DiceDrawn(i);
    dice[0].setSelected( i%2 == 0 ? true : false);
    dicePanel.setDice(dice);
    i = Io.readInt("Enter an integer between 1 and 6");
    System.exit(0);
    // File: DiceDrawn.java
    public class DiceDrawn
    private final int SIZE = 36;
    private final int QUARTER = SIZE/4;
    private int face; // face value
    private boolean selected; // pressed = true
    public DiceDrawn( int f)
    setFace(f);
    setSelected(true);
    }// end DiceDrawn
    public void setSelected( boolean s )
    selected = s;
    public boolean isSelected()
    return selected;
    public void setFace(int i)
    face = i;
    public int getFace()
    return face;
    // Draw a die starting at the given coordinates
    public void drawDie(Graphics g, int xcoor, int ycoor)
    g.setColor(Color.WHITE);
    g.fillRect(xcoor,ycoor, SIZE, SIZE);
    g.setColor(Color.BLACK);
    switch(face)
    case 1:
    g.fillOval((xcoor-4)+(2*QUARTER), (ycoor-4)+(2*QUARTER), SIZE/8, SIZE/8);
    break;
    case 2:
    g.fillOval((xcoor-4)+ QUARTER, (ycoor-4) + QUARTER, SIZE/8, SIZE/8);
    g.fillOval((xcoor-4)+(3*QUARTER), (ycoor-4)+(3*QUARTER), SIZE/8, SIZE/8);
    break;
    case 3:
    g.fillOval((xcoor-4)+ QUARTER, (ycoor-4) + QUARTER, SIZE/8, SIZE/8);
    g.fillOval((xcoor-4)+(3*QUARTER), (ycoor-4)+(3*QUARTER), SIZE/8, SIZE/8);
    g.fillOval((xcoor-4)+(2*QUARTER), (ycoor-4)+(2*QUARTER), SIZE/8, SIZE/8);
    break;
    case 4:
    g.fillOval((xcoor-4)+ QUARTER, (ycoor-4) + QUARTER, SIZE/8, SIZE/8);
    g.fillOval((xcoor-4)+(3*QUARTER), (ycoor-4)+(3*QUARTER), SIZE/8, SIZE/8);
    g.fillOval((xcoor-4)+ QUARTER, (ycoor-4) + (3*QUARTER), SIZE/8, SIZE/8);
    g.fillOval((xcoor-4)+ (3*QUARTER), (ycoor-4)+ QUARTER, SIZE/8, SIZE/8);
    break;
    case 5:
    g.fillOval((xcoor-4)+ QUARTER, (ycoor-4) + QUARTER, SIZE/8, SIZE/8);
    g.fillOval((xcoor-4)+(3*QUARTER), (ycoor-4)+(3*QUARTER), SIZE/8, SIZE/8);
    g.fillOval((xcoor-4)+ QUARTER, (ycoor-4) + (3*QUARTER), SIZE/8, SIZE/8);
    g.fillOval((xcoor-4)+ (3*QUARTER), (ycoor-4)+ QUARTER, SIZE/8, SIZE/8);
    g.fillOval((xcoor-4)+(2*QUARTER), (ycoor-4)+(2*QUARTER), SIZE/8, SIZE/8);
    break;
    case 6:
    g.fillOval((xcoor-4)+ QUARTER, (ycoor-4) + QUARTER, SIZE/8, SIZE/8);
    g.fillOval((xcoor-4)+(3*QUARTER), (ycoor-4)+(3*QUARTER), SIZE/8, SIZE/8);
    g.fillOval((xcoor-4)+ QUARTER, (ycoor-4)+(2*QUARTER), SIZE/8, SIZE/8);
    g.fillOval((xcoor-4)+ (3*QUARTER), (ycoor-4)+(2*QUARTER), SIZE/8, SIZE/8);
    g.fillOval((xcoor-4)+ QUARTER, (ycoor-4) + (3*QUARTER), SIZE/8, SIZE/8);
    g.fillOval((xcoor-4)+ (3*QUARTER), (ycoor-4)+ QUARTER, SIZE/8, SIZE/8);
    break;
    // draw a die using a rectangle of 36 by 36 pixels
    // at the coordinates given.
    // use a switch statement to draw the appropriate face.
    }// end DrawDie
    }// end DiceDrawn

    Once you get beyond your initial problems, you'll find that there is another problem. When it displays the dice corresponding to the numbers you select, the x coordinate eventually becomes greater than the frame width. You need to make a change to the paintComponent method so it looks like:
      /** Paint the Dice Panel */
      protected void paintComponent(Graphics g)
        super.paintComponent(g);
        for (int i = 0; i < dice.length; i++ )
          dice.drawDie(g, xCoordinate, yCoordinate);
    if(dice.length > 1)
    setXCoordinate(getXCoordinate() + 41);
    // draw each die using default start coordinates,
    // moving right each time
    Note that I have added an if above the setXCoordinate so that it will only add to the X coordinate when it is displaying the 6 dice initially. It won't add anything when it is displaying the single dice.

  • Help with Paint program.

    Hello. I am somewhat new to Java and I was recently assigned to do a simple paint program. I have had no trouble up until my class started getting into the graphical functions of Java. I need help with my program. I am supposed to start off with a program that draws lines and changes a minimum of 5 colors. I have the line function done but my color change boxes do not work and I am able to draw inside the box that is supposed to be reserved for color buttons. Here is my code so far:
    // Lab13110.java
    // The Lab13 program assignment is open ended.
    // There is no provided student version for starting, nor are there
    // any files with solutions for the different point versions.
    // Check the Lab assignment document for additional details.
    import java.applet.Applet;
    import java.awt.*;
    public class Lab13110 extends Applet
         int[] startX,startY,endX,endY;
         int currentStartX,currentStartY,currentEndX,currentEndY;
         int lineCount;
         Rectangle red, green, blue, yellow, black;
         int numColor;
         Image virtualMem;
         Graphics gBuffer;
         int rectheight,rectwidth;
         public void init()
              startX = new int[100];
              startY = new int[100];
              endX = new int[100];
              endY = new int[100];
              lineCount = 0;
              red = new Rectangle(50,100,25,25);
              green = new Rectangle(50,125,25,25);
              blue = new Rectangle(50,150,25,25);
              yellow = new Rectangle(25,112,25,25);
              black = new Rectangle(25,137,25,25);
              numColor = 0;
              virtualMem = createImage(100,600);
              gBuffer = virtualMem.getGraphics();
              gBuffer.drawRect(0,0,100,600);
         public void paint(Graphics g)
              for (int k = 0; k < lineCount; k++)
                   g.drawLine(startX[k],startY[k],endX[k],endY[k]);
              g.drawLine(currentStartX,currentStartY,currentEndX,currentEndY);
              g.setColor(Color.red);
              g.fillRect(50,100,25,25);
              g.setColor(Color.green);
              g.fillRect(50,125,25,25);
              g.setColor(Color.blue);
              g.fillRect(50,150,25,25);
              g.setColor(Color.yellow);
              g.fillRect(25,112,25,25);
              g.setColor(Color.black);
              g.fillRect(25,137,25,25);
              switch (numColor)
                   case 1:
                        g.setColor(Color.red);
                        break;
                   case 2:
                        g.setColor(Color.green);
                        break;
                   case 3:
                        g.setColor(Color.blue);
                        break;
                   case 4:
                        g.setColor(Color.yellow);
                        break;
                   case 5:
                        g.setColor(Color.black);
                        break;
                   case 6:
                        g.setColor(Color.black);
                        break;
              g.setColor(Color.black);
              g.drawRect(0,0,100,575);
         public boolean mouseDown(Event e, int x, int y)
              currentStartX = x;
              currentStartY = y;
              if(red.inside(x,y))
                   numColor = 1;
              else if(green.inside(x,y))
                   numColor = 2;
              else if(blue.inside(x,y))
                   numColor = 3;
              else if(yellow.inside(x,y))
                   numColor = 4;
              else if(black.inside(x,y))
                   numColor = 5;
              else
                   numColor = 6;
              repaint();
              return true;
         public boolean mouseDrag(Event e, int x, int y)
              int Rectheight = 500;
              int Rectwidth = 900;
              currentEndX = x;
              currentEndY = y;
              Rectangle window = new Rectangle(0,0,900,500);
              //if (window.inside(Rectheight,Rectwidth))
                   repaint();
              return true;
         public boolean mouseUp(Event e, int x, int y)
              int Rectheight = 500;
              int Rectwidth = 900;
              startX[lineCount] = currentStartX;
              startY[lineCount] = currentStartY;
              endX[lineCount] = x;
              endY[lineCount] = y;
              lineCount++;
              Rectangle window = new Rectangle(0,0,900,500);
              if (window.inside(Rectheight,Rectwidth))
                   repaint();
              return true;
         public void Rectangle(Graphics g, int x, int y)
              g.setColor(Color.white);
              Rectangle screen = new Rectangle(100,0,900,600);
    }If anyone could point me in the right direction of how to go about getting my buttons to work and fixing the button box, I would be greatly appreciative. I just need to get a little bit of advice and I think I should be good after I get this going.
    Thanks.

    This isn't in any way a complete solution, but I'm posting code for a mouse drag outliner. This may be preferable to how you are doing rectangles right now
    you are welcome to use and modify this code but please do not change the package and make sure that you tell your teacher where you got it from
    MouseDragOutliner.java
    package tjacobs.ui;
    import java.awt.BasicStroke;
    import java.awt.Color;
    import java.awt.Component;
    import java.awt.Container;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.Point;
    import java.awt.Stroke;
    import java.awt.event.*;
    import java.util.ArrayList;
    import java.util.Iterator;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.SwingUtilities;
    * See the public static method addAMouseDragOutliner
    public class MouseDragOutliner extends MouseAdapter implements MouseMotionListener {
         public static final BasicStroke DASH_STROKE = new BasicStroke(1.0f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL, 10.0f, new float[] {8, 8}, 0);
         private boolean mUseMove = false;
         private Point mStart;
         private Point mEnd;
         private Component mComponent;
         private MyRunnable mRunner= new MyRunnable();
         private ArrayList mListeners = new ArrayList(1);
         public MouseDragOutliner() {
              super();
         public MouseDragOutliner(boolean useMove) {
              this();
              mUseMove = useMove;
         public void mouseDragged(MouseEvent me) {
              doMouseDragged(me);
         public void mousePressed(MouseEvent me) {
              mStart = me.getPoint();
         public void mouseEntered(MouseEvent me) {
              mStart = me.getPoint();
         public void mouseReleased(MouseEvent me) {
              Iterator i = mListeners.iterator();
              Point end = me.getPoint();
              while (i.hasNext()) {
                   ((OutlineListener)i.next()).mouseDragEnded(mStart, end);
              //mStart = null;
         public void mouseMoved(MouseEvent me) {
              if (mUseMove) {
                   doMouseDragged(me);
         public     void addOutlineListener(OutlineListener ol) {
              mListeners.add(ol);
         public void removeOutlineListener(OutlineListener ol) {
              mListeners.remove(ol);
         private class MyRunnable implements Runnable {
              public void run() {
                   Graphics g = mComponent.getGraphics();
                   if (g == null) {
                        return;
                   Graphics2D g2 = (Graphics2D) g;
                   Stroke s = g2.getStroke();
                   g2.setStroke(DASH_STROKE);
                   int x = Math.min(mStart.x, mEnd.x);
                   int y = Math.min(mStart.y, mEnd.y);
                   int w = Math.abs(mEnd.x - mStart.x);
                   int h = Math.abs(mEnd.y - mStart.y);
                   g2.setXORMode(Color.WHITE);
                   g2.drawRect(x, y, w, h);
                   g2.setStroke(s);
         public void doMouseDragged(MouseEvent me) {
              mEnd = me.getPoint();
              if (mStart != null) {
                   mComponent = me.getComponent();
                   mComponent.repaint();
                   SwingUtilities.invokeLater(mRunner);
         public static MouseDragOutliner addAMouseDragOutliner(Component c) {
              MouseDragOutliner mdo = new MouseDragOutliner();
              c.addMouseListener(mdo);
              c.addMouseMotionListener(mdo);
              return mdo;
         public static interface OutlineListener {
              public void mouseDragEnded(Point start, Point finish);
         public static void main(String[] args) {
              JFrame f = new JFrame("MouseDragOutliner Test");
              Container c = f.getContentPane();
              JPanel p = new JPanel();
              //p.setBackground(Color.BLACK);
              c.add(p);
              addAMouseDragOutliner(p);
              f.setBounds(200, 200, 400, 400);
              f.addWindowListener(new WindowClosingActions.Exit());
              f.setVisible(true);
    }

  • Developer: How can I let people open files with my program?

    Hello Everyone,
    I just finished my program for the Mac, and decided to make it an application.
    I used Platypus to make my program into an application. Unfortunately when I try to open a file with my program (control + click on file + open with -> other), my application is grayed out and I can't select it. I see it there along with the other applications but I can't select it like I can Mail or TextEdit.
    I read somewhere I had to use XCode to let people open files with my program but I have never used XCode and I have no idea how to do that. Any help would be appreciated.
    Thanks,
    Nick

    You've posted in the wrong forum. This is the OS X Leopard Installation and Setup forum. You need to post your problem in the Developers forum. Also, since Platypus is not an Apple product, you should visit it's developers forum for assistance. The Apple Discussions is intended to assist users with problems and questions about Apple products only.
    To use XCode Tools you need to install it from the Optional Installs folder on your OS X Installer Disc One. It comes with documentation. More assistance can be found at developer.apple.com.

  • What is a good program to install windows via a flashdrive...Have the iso

    What is a good program to install windows via a flashdrive...Have the iso...

    What are you trying to do?
    You can install Windows in a Boot Camp partition and have a Dual Boot system where you run one operating system at a time. Either Windows or Mac OS X.
    Or you can use one of the 3 available virtual machine software parograms to install Windows in a virtual machine on top of Mac OS X. Then you can run both Windows and OS X at the same time.
    If you go with the Boot Camp option then you really need to burn that ISO file onto a DVD disc as Boot Camp likes to install from disc.
    If you go with the virtual machine option then you can use that ISO file as it is to install Windows. You will just point the VM to the USB thumb drive to find the Windows OS to do the install from.

Maybe you are looking for