Could someone explain this to me.

I have a panel that I add transparent textpanes with shapes drawn over the top, the shapes and textpanes originat from a class named round button.
I add the shapes in a loop:
for( int i = 0; i < answer.length; i++ ){
       if( answer[i] != null ){
          String answerText = answer;
buttonPanel.add(new RoundButton(answerText, buttonColor,
buttonShape, size, myMouseListener));
I've noticed that the first time I add 2 textpanes and shapes I get six calls to the drawSquareButton method. WHY?
I can not figure it out. Although I only get 2 squares on the screen, the flicker of the process is driving me nuts.
Below is class RoundButton
public class RoundButton extends JTextPane {
private Color color;
public String buttonShape;
private String label;
private Dimension size;
private java.awt.event.MouseListener myMouseListener;
public RoundButton(String label, Color color, String buttonShape,
                    Dimension size, java.awt.event.MouseListener myMouseListener) {
       super();
       setOpaque (false);
       setEditorKit (new MyEditorKit());
       SimpleAttributeSet set =  new SimpleAttributeSet();
       StyleConstants.setAlignment (set, StyleConstants.ALIGN_CENTER ); 
       setParagraphAttributes (set, true);
       setText(label);
       addMouseListener(myMouseListener);
       this.color = color;
       setPreferredSize(size);
       this.buttonShape = buttonShape;
// set the rendering hints for the Graphics object 
  private Graphics2D setGraphicsObject(Graphics g){
        Graphics2D g2 = (Graphics2D)g; 
        g2.setRenderingHint( RenderingHints.KEY_ANTIALIASING,
                     RenderingHints.VALUE_ANTIALIAS_ON );
        g2.setRenderingHint( RenderingHints.KEY_RENDERING,
                     RenderingHints.VALUE_RENDER_QUALITY );    
        g2.setRenderingHint( RenderingHints.KEY_COLOR_RENDERING,
                     RenderingHints.VALUE_COLOR_RENDER_QUALITY);
        return g2;
// Determine which shape to draw
  protected void paintComponent(Graphics g) {
     System.out.println("paint component");
        if( buttonShape.equals("square"))
            drawSquareButton(g, color);
        else if(buttonShape.equals ("oval"))
            drawOvalButton(g, color);
        else if(buttonShape.equals ("circle"))
            drawRoundButton(g, color);
        super.paintComponent(g);
  public void drawSquareButton(Graphics g, Color color){
        System.out.println("draw square button");
        Graphics2D g2 = setGraphicsObject(g);
        g2.setStroke(new BasicStroke(1.2f));
        g2.setColor(color);
        g2.fill(new RoundRectangle2D.Double(1,1,(getWidth()-3),(getHeight()-3),30,30));
        g2.setColor(color.darker ());
        g2.setStroke(new BasicStroke(2.2f));
        g2.draw(new RoundRectangle2D.Double(1,1,(getWidth()-3),(getHeight()-3),30,30));
  public void drawOvalButton(Graphics g, Color color){
        Graphics2D g2 = setGraphicsObject(g);
        g2.setStroke(new BasicStroke(1.2f));
        g2.setColor(color);
        g2.fillOval(0, 0, getSize().width-1, getSize().height-1);
        g2.setStroke (new BasicStroke(2.2f));
        g2.setColor(color.darker());
        g2.drawOval(0, 0, getSize().width-1, getSize().height-1);
  public void drawRoundButton(Graphics g, Color color){
        Graphics2D g2 = setGraphicsObject(g);
        g2.setStroke(new BasicStroke(1.2f));
        g2.setColor(color);
        g2.fillArc(0,0,getSize().width-1,getSize().height-1,0,360);
        g2.setStroke (new BasicStroke(2.2f));
        g2.setColor(color.darker());
        g2.drawArc(0,0,getSize().width-1, getSize().height-1, 0, 360);

Do you really want the super.paintComponent() after you've drawn your components?
Perhaps an else?
// Determine which shape to draw
  protected void paintComponent(Graphics g) {
     System.out.println("paint component");
        if( buttonShape.equals("square"))
            drawSquareButton(g, color);
        else if(buttonShape.equals ("oval"))
            drawOvalButton(g, color);
        else if(buttonShape.equals ("circle"))
            drawRoundButton(g, color);
        else
            super.paintComponent(g);
}

Similar Messages

  • When running labview's test executive I recieve runtime error: Call to step "PRE-RUN" failed. Could someone explain this error?

    I have a set of vi's that work when run under labview. However, when calling these vi's from labview's test executive I recieve runtime error: Call to step "PRE-RUN" failed. in Assign Connector Pane.vi->Call Test.vi->Execute Pre-Run.vi->Test Executive. Could someone explain this error to me? (or ideally tell me how to fix it?) Thanks.

    Hello,
    There are any number of possible causes to this problem. Which version of Test Executive are you using? Have you upgraded your Test Executive recently? The latest version is 5.1.1. If you have changed anything about Test Executive on your computer recently, I recommend you perform a mass compile of all your VI libraries, as having different versions of the VIs on your system could often result in the "Call to Step XYZ Failed" errors. Also, are you using any DAQ or Analysis VIs in your steps? We have seen problems where the use of DAQ or Analysis VIs in the sequence can cause intermittent "Call to Step...Failed" errors. There are some KnowledgeBase entries on our website that discuss this problem. Are you using the Test Executive in the VI environment, or
    as an executable? Again, there are some problems with using Test Executive as an executable that result in these errors, and there are also KnowledgeBase entries that discuss these problems.
    If you have a pared-down application that demonstrates the problem, feel free to send me your VIs and your .seq file and I will try to reproduce the problem.
    Alternatively, I would suggest you visit www.ni.com/teststand to learn about TestStand, our state-of-the-art Test Sequencing software that completely outperforms Test Executive. It is very easy to use and much more powerful, and we have a top-notch support team available dedicated exclusively to supporting TestStand. As you are probably aware, we are no longer developing Test Executive, and instead are concentrating our efforts on making TestStand the penultimate solution for all our customers' test sequencing needs.
    I appreciate your patience on this issue. Please let me know if I can offer further assistance.
    Have a pleasant weeken
    d.
    Sincerely,
    Darren Nattinger
    Applications Engineer
    National Instruments
    Darren Nattinger, CLA
    LabVIEW Artisan and Nugget Penman

  • Could someone explain this to me, please?

    I fixed a problem without really understanding how and why the problem occured or even why my fix worked.  I'm hoping somebody can explain it to me.  Here's the problem:
    My form had this structure:
    MainSubform
         Page1Subform
              Subform1
              Subform2
              Subform3
         Page2Subform
              other subforms
         Page3Subform
              other subforms.
    There were other objects under the
    My application viewer, which is FormStream filler, was finding a fourth node under Page1Suform.  I couldn't access this phantom node in any way to find out any information about it, so any Javascript which navigated the hierarchy would error when it tried to reach it.
    Through a long consultation with other developers, I found that there was something called a 'bind match" node.  They couldn't explain it to me.  Not knowing what a 'bind match" node was, and figuring it had something to do with linking a data source to an object, I started checking the Default Binding tab in the Object Panel.  The Default Binding for Page1Subform was set to None, while the Default Binding for every other subform was set to Normal.  I set the Default Binding for Page1Subform to Normal and my problem disappeared.  I tried setting other Default Binding properties of other subforms to None to see what would happen, and the phantom node seemed to reappear and follow those subforms around.
    Can anybody give me an explanation of what was happening?

    Hi again,
    right so I have done what you all said and gone and read a book on LabView fundamentals, "introduction to data aquisition with LABVIEW by RH king"
    it has answered my questions about the for loop and most of the rest, the thing I am now having trouble with is the pink lines coming from the DAQ assistant, I have tried all the options, generate signal, aquire, sine wave, digital, continuous samples, N samples but I can't get a pink line, all I can get in that location is a gray "error out", is this all it is, just connect error out to error in.
    Also another thing that is confusing me is, just before the graph, that component between the last division and the graph indicator, I am having trouble identifying.
    Sorry to keep badgering on about this one but I need to get this example completed for work.

  • Could someone explain this output?

    my Maze class
    import java.util.Scanner;
    import java.io.*;
    public class MazeProblem{
         private char [][] maze;               //maze array of 0's and 1's
         private boolean [][] visit;          //visited/unvisited array
         private int height, width;          //height and width of array
         private int startx, starty;          //starting point
         private int exitx, exity;          //exit point
         private Scanner sc;                    //file reader
         private StringTokenizer st;          // to split the file.
         public MazeProblem(String file){
              try{
                   sc = new Scanner(new BufferedReader(new FileReader(file)));
                   while (sc.hasNextLine()){
                        height = sc.nextInt();
                        width = sc.nextInt();
                        System.out.println("no. of rows: " +height); // tester code
                        System.out.println("no. of cols: " +width);      //tester
                        maze = new char[height][width];
                        visit = new boolean [height][width];
                        for (int i = 0; i < height; i++){
                             for (int j = 0; j < width; j++){
                                  maze [j] = sc.next().toCharArray()[0];
                        System.out.println("");
                        startx = sc.nextInt();
                        System.out.println("startx = " + startx);
                        starty = sc.nextInt();
                        System.out.println("starty = " + starty);
                        exitx = sc.nextInt();
                        System.out.println("exitx = " + exitx);
                        exity = sc.nextInt();
                        System.out.println("exity = " + exity);
              catch(FileNotFoundException e){
                   System.out.println("File not found.");
                   System.exit(0);
              finally{
                   sc.close();
              for (int i = 0; i < height; i++){
                   for(int j = 0; j < width; j++){
                        System.out.print(" " + maze[i][j]);
              System.out.println("");     
         //find out if there is a path from start to finish
         public boolean isPath(){
              return isPath(startx, starty);     //call recursive method
         //recursive method that chekcs for the path from current location
         //to finish location.
         private boolean isPath(int x, int y){
              //base case current loc. outside of maze
              if (x < 0 || x >= height || y < 0 || y >= width)
                   return false;
              //base case current loc. is a wall
              else if (maze[x][y] == '1')
                   return false;
              //base case current loc already visited
              else if (visit[x][y] == true)
                   return false;
              //base case current loc is exit
              else if (x == exitx && y == exity)
                   return true;
              else{
                   visit[x][y] = true;               //mark current location as visited
                   //if there is a path from one of the neighbors then there
                   //is a path from current loc.
                   if (isPath(x-1, y) || isPath(x+1, y) || isPath(x, y-1)
                        || isPath(x, y+1)){
                        return true;
                   else                              //if there are no paths from neighbors
                        return false;               //then there is no path from current loc.
    }tester classimport java.util.Scanner;
    public class MazeTest{
         public static void main(String[] args){
              Scanner sc = new Scanner(System.in);
              System.out.print("enter your file name: ");
              String file = sc.nextLine();
              MazeProblem maze = new MazeProblem(file);
                   if (maze.isPath())
                        System.out.println("Path: " + maze.isPath());
                   else
                        System.out.println("No path present.");
    }when ran at command:
    no. of rows: 4
    no. of cols: 6
    startx = 2
    starty = 1
    exitx = 0
    exity = 4
    1 0 1 1 0 1
    0 0 1 0 0 0
    1 0 1 0 1 0
    0 0 0 0 1 1
    Path: false
    there is an obvious path.
    if I change my tester file to omit the if else portion the program works.
    But I would like to output if there isnt a path available, and can't seem to make that happen.
    the file looks like this:
    4 6
    1 0 1 1 0 1
    0 0 1 0 0 0
    1 0 1 0 1 0
    0 0 0 0 1 1
    2 1
    0 4                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    B_pnzk wrote:
    if (maze.isPath())
    System.out.println("Path: " + maze.isPath());
    else
    // etc
    This bit of the code caught my eye. Since you output is saying "Path: false" how does it ever get to that line given that the condition was if(maze.isPath())?
    It seems to me that you could change the MazeTest main() method so that this oddity doesn't occur. Or - with a little more effort - you could change the MazeProblem class so that it can't occur.

  • Could someone explain this java practice to me

    Hi
    I have been reading the latest JDC tech tip newsletter and i came across the following line:
    Set sethash = new Hashset();
    I'm assuming an object of class Set implements the Hashset interface but why not use
    Set sethash = new Set();
    Instead? What are the advantages (if any ) are there in creating a reference to an object in this way? I've seen this quite often but could never understand why its done.
    I've always wondered about this.
    Thanks
    Kola

    1. well first of all a forum is one way of finding out
    something maybe not the best but its a way,
    No, sometimes a forum is not "a way" at all. For instance this forum is not the place to ask a question like....
    I have 100 million dollars and I need to set up a competitive service to completely replace ebay - so what do I do?
    Some questions are entirely too broad. Some questions are just impossible. Some questions display a severe lack of knowledge of some infrastruture which can only be address in java once that other knowledge is acquired.
    So not all questions are appropriate.
    2. its not as if i'm asking somone to do some
    homework, i'm asking more experienced developers than
    me why they do certain things a certain way. If i
    asked what is an interface then i could understand...
    Yes but your question is phrased rather poorly and so it is open to interpretation. The following are all interpretations that I saw:
    -You don't know what an interface is.
    -You simply didn't look at the definitions for the items that you specified in your example.
    -You don't know why one uses an interface in the first place.
    I suspect that reply 2 correctly guessed what your question was. However I consider that a luck guess. And notice that I do not list it in my guesses. Keep in mind that the only reason I believe this to be true is because I have seen the same question before (and I read a lot of questions.) Without my experience that is probably harder to see.
    3. if you read my post you would of seen that i said
    i've often seen something done a certain way and
    wondered why is that being Lazy? The operative word
    being "often"
    Lazy in the other posts probably refers to the preception that your question stems from the second guess that I made above. They felt that you could have looked it up.
    4. i could read as many books as i want..gang of 4,
    code complete, just java, dietel & dietel,thinking in
    java etc somethings you only learn through experience
    so i'm lazy because i have less experience than
    others?
    Same point as 3.
    5. finally if you do not have a construtive response
    to this message please do not bother with a reply i
    have no time for flame wars and i'm embarrassed to
    have to post this around other mature and talented
    programmers such as the ones that returned helpful
    answers to my posts!
    I can't speak for the others but I respond to about 10 posts a day. I read at least 30 a day. I do that six days a week. For me, it just sometimes gets tiring to see a question that the poster could have found the answer for by just looking at the java docs or by doing a simple search. Most of the time I just answer the question. Sometimes I point out that they could have found the answer themselves.
    Others can sometime be less tolerant of this.
    And still others just like to cause havoc. At least one of the responders to your post is of this type.
    Sometimes even free advice has a cost.

  • Could someone explain this please?

    Hi im new to the PCI-E world and i still really dont understand what this stuff means,this is a example off of a motherboard;
    PCI Express 2.0 x16     1 x mazarine PCI Express x16 slot with x16 operation
                                    1 x light-blue PCI Express x16 slot with x8 operation
    does the x8 mean the video card will only work half as good in the second slot?
    sorry for the newb question :(

    Have a read here: https://forum-en.msi.com/index.php?topic=115732.0

  • Could someone explain this tip?

    I have been given the following tip from my tutor to make my program:
    When you open the file for reading (before calling method
    acceptData), you will/should have created a Scanner object
    for reading from the file. It is this Scanner reference that
    should be passed to acceptData as the method's second argument
    (not a File argument).
    Does any one know exactly what should be written above "acceptData" and how it should be passed to "acceptData"?
    I don't think you should need the code to answer this question, correct me if I'm wrong.
    Thanks for any help in advance!

    I don't really understand, I have tried doing what you said above. I just keep getting different things, don't think I'm doing it right.
    These are the 3 modules that are being dealt with a the minute:
    public static void main(String[] args) throws IOException
              int Month;
              String reply;
              initialiseVariables();
              int Year = getYear();
              boolean leapYear = isLeapYear(Year);
              File dataFile = new File("Data" + Year + ".txt");
              Scanner input = new Scanner (dataFile);
              for(Month = 1; Month < 13; ++Month)
                   acceptData(Month,dataFile);
                   int numDays = getMonthDays(Month,leapYear);
                   updateStatistics(Month,numDays);
              displayStatistics();
              saveStatistics(Year);
              do
                   int monthNum = getMonth();
                   displayData(monthNum);
                   System.out.print("\nDo you wish to do this again?(y/n) ");
                   reply = input.next().toLowerCase();
              }while (reply.equals("y"));
              System.out.println("\n");
    public static void acceptData(int monthNum, Scanner scanner, File fileName) throws FileNotFoundException
              System.out.println("\nMonth Rainfall Max Temp Sun Hours");
              System.out.println("----- -------- -------- ---------\n");
              MonthName[monthNum] = scanner.next();
              System.out.print (MonthName[monthNum]);
              Rainfall[monthNum] = Integer.parseInt(input.nextLine());
              System.out.print (Rainfall[monthNum]);
              MaxTemp[monthNum] = Integer.parseInt(input.nextLine());
              System.out.print (MaxTemp[monthNum]);
              MaxDay[monthNum] = Integer.parseInt(input.nextLine());
              System.out.print (MaxDay[monthNum]);
              SunHours[monthNum] = Integer.parseInt(input.nextLine());
              System.out.print (SunHours[monthNum]);
              System.out.println();
              input.close();
    public static int getYear()
              int Year;
              Scanner input = new Scanner(System.in);
              System.out.println("\nPlease enter a year: ");
              Year = input.nextInt ();
              File fileName = new File("Data" + Year + ".txt");
              while (!fileName.exists())
                        System.out.println ("\n*** File not found! ***");
                        System.out.println("\nPlease enter a year: ");
                        Year = input.nextInt ();
                        fileName = new File("Data" + Year + ".txt");
              return Year;
    I basically need acceptData to work so it prints from the file onto the screen.

  • Could someone explain this method of using forms

    this method used in a page of the web site I currently tinker on has a peculiar look to the way one of the forms was put in place. That form below and its code aswell should make the form visible on the page is desing view, but its isn't showing one, though on the server and web browser it does show that the form exist and working just fine, what Im trying to get at is that all the other forms are visible in desing view except this one, and I need to edit some of the text on it cause the letters are too far from the forms on the right. so where might this form be located? any help is greately appreciated cause I'm trying to get to know the whole site in case of a technical/design issue if one arises.

    To see parsed data in PHP pages, you need a local testing server.
    WAMP for Windows
    http://www.wampserver.com/en/
    XAMPP for Windows
    http://www.apachefriends.org/en/xampp-windows.html
    XAMPP for Mac
    http://www.apachefriends.org/en/xampp-macosx.html
    MAMP for Mac
    http://www.mamp.info/en/downloads/index.html
    Setting up a PHP environment in Dreamweaver
    http://www.adobe.com/devnet/dreamweaver/articles/setup_php.html
    Nancy O.

  • I want to download iPhoto but it won't let me says I need iOS5.1.  I have the 4s. Could someone explain this?.1.

    I want to download iPhoto but it won't. Says I need iOS5.0. I have the new 4s. Can anyone help me out?

    Your iPhone has to have the iOS upgraded to 5.1 first. If you have not updated it is probably running 5.0 or 5.0.1
    To update the iOS go to
    Settings > General > Software Update then follow the prompts.
    If that says your are at 5.1 then reboot your iPad. Press and hold the Home and Sleep buttons simultaneously ignoring the red slider until the Apple logo appears. Let go of the buttons and let the iPad restart. See if that fixes your problem.

  • Could someone explain what is wrong with this refind expression?

    Hi, could someone explain what is wrong with this refind expression
    faultCode:Server.Processing faultString:'Unable to invoke CFC - Malformed regular expression "^[0-2][0-9][/][0-1][0-2][/][1-2][0-9]{3}+$".'
    thanks

    ^[0-2][0-9][/][0-1][0-2][/][1-2][0-9]{3}$ works,
    thanks
    dates 12/12/2007matching

  • I know this isn't really the right place to ask, but could someone explain why when I open Portal 2, that I got off steam and spent a whole day downloading, keeps crashing when I click the Campaign/Single Player mode. It Freezes and then crashes. Help!

    I know this isn't really the right place to ask, but could someone explain why when I open Portal 2, that I got off steam and spent a whole day downloading, keeps crashing when I click the Campaign/Single Player mode. It Freezes and then crashes. Help!

    I know this isn't really the right place to ask...
    Uhm, why don't you go to the right place, then? There are several Steam/Portal forums out there...

  • Could someone explain to me why Flash virtual tours don't work after update to Flash Player 10.1?

    Hello there,
    Could someone explain to me why Flash virtual tours don't work after update to Flash Player 10.1?
    Thanks!

    www.privium.nl
    klick the icon image 'virtual tour' upper right corner.
    This works on my other pc, on which I did not update to 10.1 ...
    (I produced this virtual tour; it is stored on the FTP server of the service provider I use for this)
    Awaiting your reply,
    Regards,

  • Could someone explain why mds is using so much CPU?

    Could someone explain what mds is doing if my Mac has been indexed (don't see activity in Spotlight menu bar icon) & I haven't recently added a lot of files?
    I noticed my Mac was slowing down for a while so I looked in Activity Monitor & it says mds is running at 60% CPU. Isn't this something to do with Spotlight indexing?

    If you recently upgraded the OS or installed an application that includes a metadata parser for spotlight (such software generally comes in the form of a package instead of a single icon), it will force spotlight to reindex. Also, restoring from a backup does the same thing.
    Also, if you used mdutil to disable spotlight indexing on the volume and then reenable it, it will force a reindexing.

  • Could someone explain me about tools like "RICEF"

    Hi Guys,
    Could someone explain me about tools like "RICEF"(I dont know if iam spelling it correctly) and ASAP methodology. Iam wondering how this are related to SAP upgrade and fresh SAP implementation.
    Many thanks in advance.
    Warm Regards,
    Garrick.

    Hi
    It would be helpful to go through the help document of ASAP Methodology.
    The following information may clarify some doubts/requirements you have.
    Generating the Project IMG through ASAP:
    After you have set the project scope, the next step is to generate the Project IMG. From the Business Process Master List (BPML), you can directly access the IMG activities relevant for configuring each process.
    BPML: The Business Process Master List, along with the Business Blueprint, is a key result of the second phase of the Roadmap. Microsoft Excel tables contain the SAP scenarios, process groups, and processes that have been set in scope in the SAP Reference Structure, and are crucial for configuring your SAP System. In Realization, the third phase of the Roadmap, the BPML provides the basis for monitoring and steering test activities and for configuring your SAP System. It contains the titles of the structure items, and displays the status, the owner, links to documentation and links to the SAP System. Amongst other things, the BPML allows you to:
    1) Set your baseline and final scope. These are used for baseline and final configuration.
    2) Access the Project IMG and specific IMG activities assigned to structure items.
    3) Access integration test plans, which help you carry out all required integration tests.
    The Prerequisite is you have set the project scope.
    Process Flow to use the Business Blueprint as a basis for configuring your SAP System:
    1) Set the project scope.
    2) Generate the Project IMG.
    3) Generate the BPML.
    4) From a specific processes in the BPML, you can go to the relevant IMG activities and make Customizing settings.
    Hope this information provides information
    Check the following link for downloading the complete reference document on ASAP.
    http://help.sap.com/printdocu/core/print46b/en/data/en/pdf/SVASAP.pdf
    http://help.sap.com/printdocu/core/Print46c/en/data/pdf/SVASAQADBCBI/QADBCBI.pdf
    http://help.sap.com/printdocu/core/Print46c/en/data/pdf/SVASACCT/SVASACCT.pdf
    http://help.sap.com/printdocu/core/Print46c/en/data/pdf/SVASAPROZ/SVASAPROZ.pdf
    http://help.sap.com/printdocu/core/Print46c/en/data/pdf/SVASQADBS/Q&ADBSTRUCSTAN.pdf
    http://help.sap.com/printdocu/core/Print46c/en/data/pdf/SVASAPE/SVASAPE_01.pdf
    Regards

  • Could someone explain the Factory Method Design Pattern

    Hi Experts.
    Could someone please explain for me the Factory Method Design Pattern. I read it a little and I understand that it is used in JDBC drivers but i'm not clear on it.
    Could someone explain.
    Thanks in advance
    stephen

    Basically, you have one class that's sole purpose is to create instances of a set of other classes.
    What will usually happen is you have a set of related classes that inherit from some base class. We'll say for example that you have a base class CAR and it has sub-classes FORD, GM, HONDA (sorry Crylser). Instead of having the user call the constructors for FORD, GM, and HONDA, you can give the user a Factory Class that will give him a copy. We'll call our factory class Dealership. Inside dealership, you can have a static function :
    public static Car makeCar(String type)
    if(type.equals("FORD")
    return new FORD();
    else if(type.equals("GM")
    return new GM();
    else if(type.equals("HONDA")
    return new HONDA();
    So when the user needs a car, they will just call
    Dealership.makeCar("FORD").
    This is a good way to hide the implementation of your classes from the user, or if you require complex initialization of your objects.
    Another good example of this is in the Swing library. To get a border around a component, you call static methods on BorderFactory.
    Hope this helped.
    Ed

Maybe you are looking for

  • Process Chain Component for Deleting Openhub Destination

    I have an openhub that places the results of a DSO on AL11. I created / scheduled a process chain for updating the file. I'd like to modify the process chain and add a step to delete the file on AL11 before I run the DTP. Is this possible? Mike

  • Making a delete commit automatically with ADF BC, Struts and ADF UIX

    I'm trying to create a delete action that commits to the database automatically using ADF Business Components, Struts and ADF UIX. I have a browse page from which the user can view all records in the table, and perform edit, create and delete actions

  • How to call other execs from java application

    What is the best way to make a call to execute an external executable written in another language (i.e. c++ or ada95) from within a java application?

  • Rosetta 'checkbox' is not in the Quicken 2007 info panel

    i got my new Imac, first time Mac user, installed Quicken 2007, which does crash everytime I use it. Followed instructions for the info panel to check the 'rosetta' box, but there is no Rosetta box in my info window. Under the 'General' it does say P

  • Adding objects in transport request

    Hi sdn, by mistake I didn't include some infoobjects in the transport request, how i can add this missing infoobjects in my transport request rubane