Suggestions on how to make this coding better?

Hey everyone, I was just wondering if anyone had any suggestions on how to make my code better. It's for a project and I want to get a good grade on it. It works fine but I just want to see what everyone thought before I hand it in.
import java.io.*;
import java.util.StringTokenizer;
     This class process the input expressions containing rational expressions and proecesses them and then outputs the results.
     @author *****
     @version 1.0
public class Proj1
     private static String buffer = null; //User input
     private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
     private static PrintWriter outfile = null;
     private static int totCount = 0, goodCount = 0, badCount = 0; //Total, Valid, and Invalid counts
     private static boolean fileInput = false; //File to read data
     private static boolean fileOutput = false; //Output for the data
     private static boolean screenOutput = false; //Output so the user can view it
     private static String outFile = null; //File for output
     private static String inFile = null; //File for input
          Main method
     public static void main (String[] args) throws Exception
          Proj1 proj1 = new Proj1();
          proj1(args);
          runs the program
     private static void proj1(String [] args) throws Exception
          if (args.length == 0)
               printBanner();
               System.out.println("\n" + "\n" + "Please enter an expression, or type quit");
               do
                    screenOutput=true;
                    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
                    processData();
               }while(!buffer.equals("quit"));//exits if quit is entered
          if (args[0].charAt(0) != '-')
               badOption("Invalid Option Specified ");
          for(int i=1; i<args[0].length(); i++)
               switch(args[0].charAt(i))
                    case 'f': fileInput = true;
                                break;
                    case 'o': fileOutput = true;
                                break;
                    case 'b': fileOutput = true;
                                screenOutput = true;
                                break;
                    default:  printBanner();
                                invalidOption("Proj1: Invalid Option Found: " + args[0].charAt(i));
          if(fileInput && args[0].length() == 2)
               screenOutput = true;
          if(fileInput && !fileOutput)
               if(args.length == 1)
                    badOption("No Input File Specified.");
               else
                    File inFile = new File(args[1]);
                    if(!inFile.exists())
                         nonExist("Input File " + args[1] + " not found");
               br = new BufferedReader(new FileReader(args[1]));
               printBanner();
               processData();
               closeFiles();
          if(fileOutput && fileInput)
               printBanner();
               if(args.length > 2)
                    outFile = args[2];
               else
                    if(args.length > 1)
                         outFile = "proj1.dat";
                         noOut("No output file specified , defaulting to proj1.dat");
               inFile = args[1];
               br = new BufferedReader(new FileReader(inFile));
               processData();
               closeFiles();
          if(fileOutput && screenOutput)
               printBanner();
               if(args.length == 1)
                    outFile = "proj1.dat";
                    noOut("No output file specified, defaulting to proj1.dat");
                    System.out.println("\n" + "\n" + "Please enter an expression, or type quit");
                    BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
                    processData();
                    closeFiles();
               else
                    outFile=args[1];
                    System.out.println("\n" + "\n" + "Please enter an expression, or type quit");
                    br = new BufferedReader(new InputStreamReader(System.in));
                    processData();
                    closeFiles();
     Processes the input data by the user by doing the specified operations and then displays the output
     private static void processData() throws Exception
          if(fileOutput)
               outfile = new PrintWriter(new FileOutputStream(outFile), true);
          else if(fileOutput && screenOutput)
               outfile = new PrintWriter(new FileOutputStream(outFile), true);
          buffer = br.readLine();
          while(!buffer.equals(""))
               StringTokenizer reader = new StringTokenizer(buffer);
               int count = 0;
               String number1 = null;
               String number2 = null;
               String op = null;
               boolean valid = true;
               boolean secondNumber = true;
               while (reader.hasMoreTokens())
                    switch(count)
                         case 1: number1 = reader.nextToken();
                                   break;
                         case 2: op = reader.nextToken();
                                   break;
                         case 3: number2 = reader.nextToken();
                                   break;
                    count++;
               if(number1 == null || number1.equals("quit"))
                    printSummary(goodCount, badCount, totCount);
                    closeFiles();
               if(number2 == null)
                    secondNumber = false;
               char character;
               int position = 0;
               String s = "0123456789/-";
               for(int i = 0; i < number1.length(); i++)
                    character = number1.charAt(i);
                    position = s.indexOf(character);
                    if(position == -1)
                         valid = false;
               if(secondNumber)
                    for(int i = 0; i < number2.length(); i++)
                         character = number2.charAt(i);
                         position = s.indexOf(character);
                         if(position == -1)
                              valid=false;
               int denomin2 = 0;
               int numer2 = 0;
               String n1 = null;
               String d1 = null;
               int izerCount = 0;
               StringTokenizer st2 = new StringTokenizer(number1,"/");
               while(st2.hasMoreTokens())
                    switch(izerCount)
                         case 1: n1 = st2.nextToken();
                                   d1 = "1";
                                   break;
                         case 2: d1 = st2.nextToken();
                    izerCount++;
               int numer1;
               int denomin1;
               int tokenCount = 0;
               if(valid)
                    numer1 = Integer.parseInt(n1);
                    denomin1 = Integer.parseInt(d1);
                    String n2 = null;
                    String d2 = null;
                    if(secondNumber)
                         StringTokenizer st3 = new StringTokenizer(number2, "/");
                         while(st3.hasMoreTokens())
                              switch(tokenCount)
                                   case 1: n2 = st3.nextToken();
                                             d2 = "1";
                                             break;
                                   case 2: d2 = st3.nextToken();
                              tokenCount++;
                         numer2 = Integer.parseInt(n2);
                         denomin2 = Integer.parseInt(d2);
                         RationalNumber z1 = new RationalNumber(numer2, denomin2);
                    RationalNumber z = new RationalNumber(numer1,denomin1);
                    RationalNumber z1 = new RationalNumber(numer2,denomin2);
                    boolean lt = true; //whether the first number is less than the second
                    boolean gt = true; //whether the first number is greater than the second
                    boolean eq = true; //whether the first number is equal to the second
                    boolean le = true; //whether the first number is less or equal to the second
                    boolean ge = true; //whether the first number is greater than or equal to the second
                    boolean zeroDenom = true; //whether the denominator is zero
                    if(denomin1 == 0 || denomin2 == 0)
                         zeroDenom = true;
                         badCount++;
                    else
                         zeroDenom = false;
                    if(!zeroDenom && secondNumber)
                         if(op.equals("+"))
                              RationalNumber z2 = z.add(z1);
                              if(screenOutput)
                                   System.out.println(buffer + " = " + z2.getNumerator()+ "/" +z2.getDenominator());
                              if(fileOutput || fileOutput && screenOutput)
                                   outfile.println(buffer + " = " + z2.getNumerator()+ "/" +z2.getDenominator());
                              goodCount++;
                         else if(op.equals("-"))
                              RationalNumber z3 = z.sub(z1);
                              if(screenOutput)
                                   System.out.println(buffer + " = " + z3.getNumerator()+ "/" +z3.getDenominator());
                              if(fileOutput || fileOutput && screenOutput)
                                   outfile.println(buffer + " = " + z3.getNumerator()+ "/" +z3.getDenominator());
                              goodCount++;
                         else if(op.equals("*"))
                              RationalNumber z4 = z.mlt(z1);
                              if(screenOutput)
                                   System.out.println(buffer + " = " + z4.getNumerator()+ "/" +z4.getDenominator());
                              if(fileOutput || fileOutput && screenOutput)
                                   outfile.println(buffer + " = " + z4.getNumerator()+ "/" +z4.getDenominator());
                              goodCount++;
                         else if(op.equals("/"))
                              RationalNumber z5 = z.div(z1);
                              if(screenOutput)
                                   System.out.println(buffer + " = " + z5.getNumerator()+ "/" +z5.getDenominator());
                              if(fileOutput || fileOutput && screenOutput)
                                   outfile.println(buffer + " = " + z5.getNumerator()+ "/" +z5.getDenominator());
                              goodCount++;
                         else if(op.equals("<"))
                              lt=z.lt(z1);
                              if(screenOutput)
                                   System.out.println(buffer + " is " + lt);
                              if(fileOutput || fileOutput && screenOutput)
                                   outfile.println(buffer + " is " + lt);
                              goodCount++;
                         else if(op.equals(">"))
                              gt=z.gt(z1);
                              if(screenOutput)
                                   System.out.println(buffer + " is " + gt);
                              if(fileOutput || fileOutput && screenOutput)
                                   outfile.println(buffer + " is " + gt);
                              goodCount++;
                         else if(op.equals("="))
                              eq=z.eq(z1);
                              if(screenOutput)
                                   System.out.println(buffer + " is " +  eq);
                              if(fileOutput || fileOutput && screenOutput)
                                   outfile.println(buffer + " is " +  eq);
                              goodCount++;
                         else if(op.equals("<="))
                              le=z.le(z1);
                              if(screenOutput)
                                   System.out.println(buffer + " is " + le);
                              if(fileOutput || fileOutput && screenOutput)
                                   outfile.println(buffer + " is " + le);
                              goodCount++;
                         else if(op.equals(">="))
                              ge=z.ge(z1);
                              if(screenOutput)
                                   System.out.println(buffer + " is " + ge);
                              if(fileOutput || fileOutput && screenOutput)
                                   outfile.println(buffer + " is " + ge);
                              goodCount++;
                         else
                              if(op==null)
                                   if(screenOutput)
                                        System.out.println("Invalid expression: " + buffer);
                                   if(fileOutput || fileOutput && screenOutput)
                                        outfile.println("Invalid Expression: " + buffer);
                                   badCount++;
                         else
                              if(screenOutput)
                                   System.out.println("Invalid expression: " + buffer );
                              if(fileOutput || fileOutput && screenOutput)
                                   outfile.println("Invalid expression: " + buffer);
                              badCount++;
                    else
                         if(screenOutput)
                              System.out.println("Invalid operand: " + buffer);
                         if(fileOutput || fileOutput && screenOutput)
                              outfile.println("Invalid operand: " + buffer);
               else
                    if(screenOutput)
                         System.out.println("Invalid operand: " + buffer);
                    if(fileOutput || fileOutput && screenOutput)
                         outfile.println("Invalid operand: " + buffer);
                    badCount++;
               buffer = br.readLine();
     Prints the banner for the program
     private static void printBanner()
          System.out.println("+++++++++++++++++++++++++++++++++++++++++"+"\n"+"+Welcome to the expression connection   +"+"\n"+"+++++++++++++++++++++++++++++++++++++++++");
     Prints the total number of expressions, total number of valid expressions, and total number of bad expressions.
     private static void printSummary(int goodCount, int badCount, int totCount)
          totCount = goodCount + badCount;
          System.out.println("\n");
          System.out.println("+++++++++++++++++++++++++++++++++++++++++");
          System.out.println("+ Total Expressions:        "+totCount);
          System.out.println("+ Total Valid Expressions   "+goodCount);
          System.out.println("+ Total Bad Expressions     "+badCount);
          System.out.println("+++++++++++++++++++++++++++++++++++++++++");
     Prints the error message if there is no output file specified
     private static void noOut(String errorString)
          System.out.println("\n");
          System.out.println("Proj1: " + errorString);
     Prints the error message if there is an invalid option input by the user
     private static void invalidOption(String errorString)
          System.out.println("\n");
          System.out.println("Proj1: " + errorString);
          System.out.println("Proj1: Usage is: java proj1 [-fob] [input] [output]");
          System.exit(0);
     Prints the error message if there is a bad option input by the user
     private static void badOption(String errorString)
          System.out.println("\n");
          System.out.println("Proj1: " + errorString);
          System.out.println("Proj1: Usage is: java proj1 [-fob] [input] [output]");
          System.exit(0);
     Prints the error message if the input file does not exist
     private static void nonExist(String errorString)
          System.out.println("\n");
          System.out.println("Proj1: " +errorString);
          System.out.println("Proj1: Usage is: java proj1 [-fob] [input] [output]");
          System.exit(0);
     Closes the files used by the user
     private static void closeFiles( )
          if(fileOutput && !screenOutput)
               outfile.close();
          System.exit(0);
}

Well working is good...
The code itself is less than spectacular I'm afraid. There is very little
OOness to this. For your future reference when you complete a program
and it consists of nothing but static methods you have done something
incorrectly.
As far as the code you do have goes some refactoring would be nice.
The two main methods you have (proj1 but especially processData) are
too long and unwieldy. processData seems to be a program in an of
itself. It's complicated and hard to follow.
My recommendation to you would be to read this http://java.sun.com/docs/books/tutorial/java/index.html
Especially focus on the sections dealing with explanation of Object
programming. These terms and concepts can certainly be confusing to
new programmers so you may also want to consider finding yourself a
tutor to help you get a better grasp of these concepts.
In short if it works that's good. And it's also good to see that you put the
effort and time in that you have. However if I was grading your project
I'd give it a C- at best because this is a Java program in syntax only.

Similar Messages

  • Suggestion on how to make this photo better

    It is a timelapse of stars, the sky was seperated from the forground so I could edit the forground better.  But I feel like something does not match up right.  Possible the white balance is different with the background and forground.  Not sure so need help.  Thanks.
    http://drive.google.com/file/d/0B5Uis2RlxS1mdUNwaHJ6SHVYOW8/edit?usp=sharing
    one of the origionals used to make it - http://drive.google.com/file/d/0B5Uis2RlxS1mUmNNMVNrSTMtOVk/edit?usp=sharing
    Its 243 images merged

    Well working is good...
    The code itself is less than spectacular I'm afraid. There is very little
    OOness to this. For your future reference when you complete a program
    and it consists of nothing but static methods you have done something
    incorrectly.
    As far as the code you do have goes some refactoring would be nice.
    The two main methods you have (proj1 but especially processData) are
    too long and unwieldy. processData seems to be a program in an of
    itself. It's complicated and hard to follow.
    My recommendation to you would be to read this http://java.sun.com/docs/books/tutorial/java/index.html
    Especially focus on the sections dealing with explanation of Object
    programming. These terms and concepts can certainly be confusing to
    new programmers so you may also want to consider finding yourself a
    tutor to help you get a better grasp of these concepts.
    In short if it works that's good. And it's also good to see that you put the
    effort and time in that you have. However if I was grading your project
    I'd give it a C- at best because this is a Java program in syntax only.

  • How to make this forum better?

    Hi friends
    I have the ability to create an announcement inside this forum. So I'm thinking about this possibility. I'm following this forum for about a time just to be sure it's free of spammers (and also for learning each time more about scripts and participating when having time).
    I'd like your opinion....
    What do you think about creating an announcement called "Read it before posting your questions here". The body of the announcement should tell the users links from where are the manuals of Illustrator Scripting and the JavaScripts Tools Guide. This could help people find useful informations of Illustrator scripting and know more about it. Do you think it would be useful?
    Also, do you think some times...is there some users who ask questions, but, at true their objectives is to make the specialists here to create an entire code for them?? ...like..."Hey, I want to create a snow ball in Illustrator. How could I do via script?"
    If you perceive there are such users, do you think would be good to include in the announcement a paragraph to warn about this?? So, this would alert this forum is a place essentially for "help"?
    Can you share your inputs about this subject, on how I could create a good announcement to help new users to use it better?
    Thank you very much
    Best Regards
    Gustavo.
    Message was edited by: Gustavo Del Vechio

    Carlos
    When I open the Illustrator scripting main page (http://forums.adobe.com/community/illustrator/illustrator_scripting), logged or not, the new yellow widget appears above the list of discussions. See my print of screen.
    Other unecessary widgets was taken off from the avaliable area of the page.
    Don't you see it in your side?
    Best Regards
    Gustavo.

  • Any suggestions for how to make this text look amazing?

    Hey guys,
    I'm a newbie at photoshop and I've recently started learning to run this blog that I create called Cultural Facts of the Day.
    I am developing a graphic style for some of the stories that I post and I'm looking for advice on how to better some of the images on text. I have this one photo I am working on now. I'm using a Futura and gothic text, but I'm looking for inspiration or a tutorial on how to optimize text lay out on an image like this. I just want to put it out there that I am willing to pay for Skype tutorials if anyone wants to help me out!
    This is what I'm working with and what I have so far:
    My inspiration so far has been this Time article:

    If the only thing you need to do efficiently is appending an object to the end of file, then quick & dirty solution follows
    static void addObject(Object o,File f)throws IOException{
    RandomAccessFile raf=new RandomAccessFile(f);
    raf.seek(f.length());
    ObjectOutputStream out=new ObjectOutputStream(new RAFOutputStream(raf));
    out.write(obj);
    out.close();
    static Vector readAll(File f)throws IOException{
    ObjectInputStream in=new ObjectInputStream(new FileInputStream(f));
    Vector v=new Vector();
    Object obj;
    while((obj=in.readObject())!=null){
    v.addElement(obj);
    return v;
    class RAFOutputStream extends OutputStream{
    private RandomAccessFile raf;
    RAFOutputStream(RandomAccessFile raf){
    this.raf=raf;
    public void write(int b)throws IOException{
    raf.write(b);
    public void close()throws IOException{
    raf.close();
    }

  • I need to sync my laptop and iphone to my bosses laptop and iphone.  Can two apple users share the same icloud?  If not, any suggestions on how to make this work?  We need to be able to pull files, etc

    I need to sync my laptop and iphone with my bosses laptop and iphone.  We need to be able to have access to the same files. 
    Any suggestions?

    Yes you can both use the same iCloud account.

  • HT1192 Any suggestions on how to make this caps lock thing more user friendly?

    It is really dificult to type with this.

    What is more user friendly than using a finger to tap the caps lock key?

  • Please Suggest, How to make this view efficient ?

    Hi there,
    Could you please suggest me,how to make the following VIEW (QUERY) efficient regarding performance point of view.
    CREATE OR REPLACE VIEW XXX_TRX_TO_NUM_V
    (ROW_NUM, ORIG_TRX_NUM, TRX_NUMBER, TRX_DATE, PURCHASE_ORDER,INTERFACE_HEADER_ATTRIBUTE6, INTERFACE_HEADER_ATTRIBUTE1, INTERFACE_HEADER_ATTRIBUTE5, BILL_TO_CONTACT_ID, REMIT_TO_ADDRESS_ID, BILL_TO_CUSTOMER_ID, BILL_TO_SITE_USE_ID, ORG_ID)
    AS
    Select rownum row_num,trx_number orig_trx_num,to_number(a.trx_number) trx_number,a.trx_date,a.purchase_order,a.interface_header_attribute1
    ,a.interface_header_attribute6,a.interface_header_attribute5,a.bill_to_contact_id
    ,a.remit_to_address_id,a.bill_to_customer_id,a.bill_to_site_use_id,a.org_id
    from ra_customer_trx_all a
    where a.trx_number is not null
    and a.trx_number not in
    (select trx_number
    from
    (select rownum,/*+ ALL_ROWS ,16 */ r.trx_number,ltrim(rtrim(translate(/*+ ALL_ROWS ,16 */ r.TRX_number,'0123456789',' '), ' ' ), ' ' ) tx
    from ra_customer_trx_all r)
    where tx is not null)
    order by trx_number
    Thanks in Advance !
    Shahzad

    I think you have the hints in the wrong place - as far as I was aware, the hint had to come straight after the SELECT/UPDATE/INSERT/DELETE key word - but I could be wrong as I've never really tried it elsewhere. Also, unless the optimiser mode for your database is set to FIRST_ROWS or RULE (god help you!:), ALL_ROWS is the default behaviour.
    Basically what you are trying to say is bring me back all ra_customer_trx_all rows that have purely numeric trx_numbers right?
    Why, if you need to be able to represent trx_number as a number, do you have non-numeric data in there???? That's a bit dodgy isn't it?
    Anyway, what about:
    CREATE TABLE dt_test_num (id varchar2(10))
    insert
    into
         dt_test_num
    select
         chr(47 + rownum)
    from
         all_tables
    where
         rownum <= 20
    select
         to_number(id),
         id
    from
         dt_test_num
    where
         translate(id,'0123456789',' ') IS NULL
    update
         dt_test_num
    set
         id=id||chr(67-rownum)
    select
    FROM
         dt_test_num
    select
         to_number(id),
         id
    from
         dt_test_num
    where
         translate(id,'0123456789',' ') IS NULL
    /Also, you are selecting rownum and aliasing it. Why? rownum will be assigned before the sort.
    HTH
    David
    Message was edited by:
    david_tyler
    Hello
    Slight correction to the where clause. Art first I thought you didn't need the trim on there, but that was just down to the number sequence in translate...
    SQL> select nvl(translate('1A','1234567890',''),'NULL') from dual
      2  /
    NVL(
    NULL
    SQL> select nvl(translate('1A','1234567890',' '),'NULL') from dual
      2  /
    NV
    A
    SQL> select nvl(translate('1','1234567890',' '),'NULL') from dual
      2  /
    N
    SQL> select nvl(translate('2','1234567890',' '),'NULL') from dual
      2  /
    NVL(
    NULL
    SQL> select nvl(translate('2','0123456789',' '),'NULL') from dual
      2  /
    NVL(
    NULL
    SQL> select nvl(translate('1','0123456789',' '),'NULL') from dual
      2  /
    NVL(
    NULL
    SQL> select nvl(translate('0','0123456789',' '),'NULL') from dual
      2  /
    N
    SQL> select nvl(TRIM(translate('0','0123456789',' ')),'NULL') from dual
      2  /
    NVL(
    NULL
    SQL> select nvl(TRIM(translate('1','0123456789',' ')),'NULL') from dual
      2  /
    NVL(
    NULLTranslate still confuses me :-(

  • Something keeps trying to download on my mac and I don't know what it is. It is not in the apple store and just comes out nowhere and request for my password to download something and I don't know what it is. How to make this stop?

    Something keeps trying to download on my mac and I don't know what it is. It is not in the apple store and just comes out nowhere and request for my password to download something and I don't know what it is. How to make this stop? It pops up every single day.

    Erica,
         I can, with 99.99% certainty, tell you that you are absolutely right in not wanting to download or install this "Helper," whatever it is (but we can be equally certain it would not "help" anything).
         I cannot comment as to Oglethorpe's recommendation of 'adwaremedic'; I am unfamiliar with it.  His links to the Apple discussion and support pages warrant your time and attention.
         It might be really simple -- Trying looking in your Downloads folder, trash anything that you don't know with certainty is something you want to keep, and then Secure Empty your Trash. Then remove the AdBlock extension, LastPass, and Web of Trust extensions to Safari and re-boot. If the issue goes away, still be extraordinarily careful in the future.
         Unfortunately, it's probably not going to be that simple to get rid of, in which case I'd then try the line by line editing in HT203987. 
         I have no further suggestions (other than a complete wipe and re-install...but that's a pain because trying to restore from Time Machine would simply ... restore the Mal).
       For the rest of us, please post when you find a solution.
         Best.
         BPW
      (Also, try to edit your second post -- black out your last name on the screenshot and re-post it for others)

  • How to make this in Adobe Photoshop CS5? PLEASE Help!

    Hey guys, i reallllllllly  want to know how to make this image in adobe photoshop.... the cone around the forecast track. Can you guys please show me how to do this? Id greatly appreciate it!

    There's a lot implied here, but you're not going to get around having to do the following in general:
    Use an unmarked map as a background.
    Draw shapes on layer(s) above the background and make them partially transparent.
    Obviously the key is to draw shapes that express the "cone of uncertainty" exactly as you want it to look, and with a minimum of fuss.
    I'd suggest drawing shapes with Path tools, then filling the shapes, applying a stroke (for the edge border), and using masking to hide parts you don't want to show (or which overlap with the other parts you're drawing).
    Are you needing to do this over and over or just once?
    -Noel

  • White line onscreen in all applications.  I do not know if I did something or if this is some problem.  Everything seem to be working alright otherwise.  Any suggestions on how to fix this p

    I have an eight year old IMAC with the Intel dual core.  Today for the first time a fine white vertical line appeared on screen in all applications.  I do not know if I did something or if this is a larger problem.  Everything  else seems to be working alright.  Any suggestions on how to fix this problem would be appreciated. Thanks.

    Eight-year old iMacs did not have Intel processors. Please do "About this Mac" from you Apple menu to see something like this:
    Please post the "Version" under  the big "Mac OS X" and the "Processor" information. These can make a big difference in advising you how to proceed.
    iOS  4.1 currently shown in you profile will not run on a  Mac computer; it is only for iDevices (Pads, Pods and Phones), so fixing that in your profile can help you get answers faster because people won't to ask for more info before forming an answer.

  • Anyone knows how to make this code to netbeans??

    anyone knows how to make this code to netbeans?? i just want to convert it into netbeans... im not really advance with this software... anyway..just reply if you have any idea...or steps how to build it... etc.... thanks guys...
       import javax.swing.*;
       import javax.swing.table.*;
       import java.awt.*;
       import java.awt.event.*;
       import java.util.regex.*;
       public class FilterTable {
         public static void main(String args[]) {
           Runnable runner = new Runnable() {
             public void run() {
               JFrame frame = new JFrame("Sorting JTable");
               frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
               Object rows[][] = {
                 {"AMZN", "Amazon", 41.28},
                 {"EBAY", "eBay", 41.57},
                 {"GOOG", "Google", 388.33},
                 {"MSFT", "Microsoft", 26.56},
                 {"NOK", "Nokia Corp", 17.13},
                 {"ORCL", "Oracle Corp.", 12.52},
                 {"SUNW", "Sun Microsystems", 3.86},
                 {"TWX",  "Time Warner", 17.66},
                 {"VOD",  "Vodafone Group", 26.02},
                 {"YHOO", "Yahoo!", 37.69}
               Object columns[] = {"Symbol", "Name", "Price"};
               TableModel model =
                  new DefaultTableModel(rows, columns) {
                 public Class getColumnClass(int column) {
                   Class returnValue;
                   if ((column >= 0) && (column < getColumnCount())) {
                     returnValue = getValueAt(0, column).getClass();
                   } else {
                     returnValue = Object.class;
                   return returnValue;
               JTable table = new JTable(model);
               final TableRowSorter<TableModel> sorter =
                       new TableRowSorter<TableModel>(model);
               table.setRowSorter(sorter);
               JScrollPane pane = new JScrollPane(table);
               frame.add(pane, BorderLayout.CENTER);
               JPanel panel = new JPanel(new BorderLayout());
               JLabel label = new JLabel("Filter");
               panel.add(label, BorderLayout.WEST);
               final JTextField filterText =
                   new JTextField("SUN");
               panel.add(filterText, BorderLayout.CENTER);
               frame.add(panel, BorderLayout.NORTH);
               JButton button = new JButton("Filter");
               button.addActionListener(new ActionListener() {
                 public void actionPerformed(ActionEvent e) {
                   String text = filterText.getText();
                   if (text.length() == 0) {
                     sorter.setRowFilter(null);
                   } else {
                     try {
                       sorter.setRowFilter(
                           RowFilter.regexFilter(text));
                     } catch (PatternSyntaxException pse) {
                       System.err.println("Bad regex pattern");
               frame.add(button, BorderLayout.SOUTH);
               frame.setSize(300, 250);
               frame.setVisible(true);
           EventQueue.invokeLater(runner);
       }

    its okay onmosh.....what we need to
    this...forum....is to have a good......relationship
    of programmers......and to start with .....we need to
    have a good attitude........right.....???.....no
    matter how good you are in programming but if you did
    not posses the right kind of attitude....everything
    is useless.....in the first place....all we
    want....is just to ask...some....help....but
    conflicts......but unluckily......we did not expect
    that there are members in here which......not
    good...to follow.....just as suggestion for those
    people not having the right kind of attidude...why
    can't you do in a very nice message sharing in a very
    nice....way....why we need to put some
    stupid....stuff...words.....can't you live with out
    ******* ****....its not.....lastly especially you
    have your children right now and people around...that
    somehow......idiolize...you even me....is one of
    them......but showing but attitude....is not
    good......tnx....hope you'll take it this....in the
    positive side.....be optimistic...guys....the
    world..is not yours....all of us will just past
    away....always..remember that one.....treasure..our
    stay in this....temporary home.....which...is
    world....Whoa. That post seems to be killing my brain.
    URK
    Join........us..........do not be..........afraid.......

  • Not able to acess app store .. Tried every thing with ... Dns change .. Time chage.... Reset... Location services .suggest me how to resolve this issue

    Not able to acess app store .. Tried every thing with ... Dns change .. Time chage.... Reset... Location services .suggest me how to resolve this issue

    Hi aditya123,
    If you are having difficulty connecting to the App store from your iPhone, you may want to try the steps in this article -
    Can't connect to the iTunes Store
    http://support.apple.com/kb/TS1368
    Specifically -
    Troubleshoot issues on an iPhone, iPad, or iPod touch
    If you haven't been able to connect to the iTunes Store:
    Make sure your date, time, and time zone are correct in Settings > General > Date & Time.
    Note: Time Zone may list another city in your time zone.
    Make sure that your iOS software is up to date by tapping Settings > General > Software Update (iOS 5 or later) or connecting your iOS device to iTunes and clicking Check for Update on your device's Summary page.
    Check and verify that you're in range of a Wi-Fi router or base station. If you're on a device with cellular service, make sure that cellular data is turned on from Settings > General > Cellular.
    Note: If connected to cellular data, larger items may not download. You may need to connect to Wi-Fi to download apps, videos, and podcasts.
    Make sure that you have an active Internet connection. You can check the user guide for your device for help with connecting to the Internet.
    Make sure that other devices (portable computers, for example) are able to connect to the Wi-Fi network and access the Internet.
    Try resetting (turning off and then on again) your Wi-Fi router.
    If the issue persists, try troubleshooting your Wi-Fi networks and connections.
    It looks like you have already done many of these, but there are a few more to check out.
    Thanks for using Apple Support Communities.
    Best,
    Brett L

  • How do make this query ?

    CREATE TABLE CLIENT (
         CLIENTID NUMBER PRIMARY KEY,
         NAME VARCHAR2(40)
    CREATE TABLE SALESMAN (
         SALESMANID NUMBER PRIMARY KEY,
         NAME VARCHAR2(40),
         ALL_CLIENTS NUMBER -- ACCESS ALL CLIENTS IF VALUE IS 1
    CREATE TABLE CLIENTSALESMAN (
         SALESMANID NUMBER,
         CLIENTID NUMBER
    INSERT INTO CLIENT VALUES(1,'Bob');
    INSERT INTO CLIENT VALUES(2,'Jhon');
    INSERT INTO CLIENT VALUES(3,'Robert');
    INSERT INTO CLIENT VALUES(4,'Clarck');
    INSERT INTO SALESMAN VALUES (1,'Christina',0);
    INSERT INTO SALESMAN VALUES (2,'Doug',1); -- access all clients
    INSERT INTO CLIENTSALESMAN VALUES (1,1);
    INSERT INTO CLIENTSALESMAN VALUES (1,2);
    How do you return all the clients of a salesman ? same that SALESMAN.ALL = 1 OR SALESMAN.ALL = 0.
    the salesman.all is 1 then he access all clients no need insert in CLIENTSALESMAN. If SALESMAN.ALL = 0 he
    access clientsalesman.
    Does somebody some suggestion how i make this ?
    thanks !

      1  select *
      2  from (select a.name SALESMAN, b.name CLIENT
      3  from   salesman a, client b, clientsalesman
      4  where  a.SALESMANID = c.SALESMANID
      5  and    b.CLIENTID = c.CLIENTID
      6  union
      7  select a.name SALESMAN, b.name CLIENT
      8  from   salesman a, client b
      9  where   a.ALL_CLIENTS = 1)
    10* where salesman = '&1'
    SQL> /
    Enter value for 1: Christina
    old  10: where salesman = '&1'
    new  10: where salesman = 'Christina'
    Christina                                Bob
    Christina                                Jhon
    SQL> /
    Enter value for 1: Doug
    old  10: where salesman = '&1'
    new  10: where salesman = 'Doug'
    Doug                                     Bob
    Doug                                     Clarck
    Doug                                     Jhon
    Doug                                     RobertNicolas.

  • Hello Anybody, I have a question. Can any of you please suggest me how to make an xml file from the database table with all the rows? Note:- I am having the XSD Schema file and the resulted XML file should be in that XSD format only.

    Hello Anybody, I have a question. Can any of you please suggest me how to make an xml file from the database table with all the records?
    Note:- I am having the XSD Schema file and the resulted XML file should be in that XSD format only.

    The Oracle documentation has a good overview of the options available
    Generating XML Data from the Database
    Without knowing your version, I just picked 11.2, so you made need to look for that chapter in the documentation for your version to find applicable information.
    You can also find some information in XML DB FAQ

  • I am having trouble with iMessage being activated. It has worked up until yesterday and now won't activate and is saying no address in the send and receive section. My number is there but not ticked. Any suggestions on how to fix this?

    I am having trouble with iMessage being activated. It has worked up until yesterday and now won't activate and is saying no address in the send and receive section. My number is there but not ticked. Any suggestions on how to fix this? I have shut down my phone, but still no luck!

    iMessage and FaceTime went down yesterday for some people. Mine is still down. My iMessage is saying the same thing about being activated. Sounds like you are still down too. Ignore the status page that says everything is fine - it lies.

Maybe you are looking for