Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Yes, it's just providing an anonymous inner class implementation of JPanel on initialization. You have probably seen it before with action listeners, Comparators, Runnables that are being handed off to a thread, etc.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Was it a Baptist church?
:twisted:

scru commented: hehe +3
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Given the above discussion on using a panel to draw on and the fact that overriding paintComponent() really is the better way to go, I'd recommend the following, which is only a minor re-arrangement of your existing code (see comments on changes)

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class Hangman extends JFrame implements ActionListener {

    // DECLARATIONS
    JLabel inputL,
      lettersL,
      wordL;
    JTextField inputTF,
      lettersTF,
      wordTF;
    JButton checkB,
      exitB;
    final String WORD[] = {"SPLINTER", "MAGICAL", "FUNDAMENTAL", "ONYX", "UNIVERSAL", "MYSTERIOUS", "QUAIL", "DISCOVER", "UNIQUE", "OLYMPICS"};
    static int index;
    int chances = 6;
    char[] blanks, guess;
    String usedLetters = "";
    // New reference to your hangman panel
    JPanel graphicPanel;

    public Hangman() {
        // override paintComponent to call the drawHangman() method
        graphicPanel = new JPanel() {
            protected void paintComponent(Graphics g) {
                super.paintComponent(g);
                drawHangman(g);
            }
        };
        graphicPanel.setBackground(Color.black);

        inputL = new JLabel("Enter a letter");
        lettersL = new JLabel("Used Letters");
        wordL = new JLabel("The Word");

        inputTF = new JTextField();
        lettersTF = new JTextField(26);
        wordTF = new JTextField(16);

        inputTF.setFont(new Font("Arial", Font.BOLD, 20));
        inputTF.setHorizontalAlignment(0);
        lettersTF.setFont(new Font("Arial", Font.BOLD, 20));
        lettersTF.setEditable(false);
        lettersTF.setHorizontalAlignment(JTextField.CENTER);
        wordTF.setFont(new Font("Arial", Font.BOLD, 20));
        wordTF.setEditable(false);
        wordTF.setHorizontalAlignment(JTextField.CENTER);

        String text = "";
        for(int ctr = 0; ctr<WORD[index].length(); ctr++) {
            text = text+"_ ";
        }
        wordTF.setText(text);
        blanks = text.toCharArray();

        checkB = new JButton("Check");
        checkB.addActionListener(this);

        exitB = new JButton("EXIT");
        exitB.addActionListener(this);

        Container pane = getContentPane();
        pane.setLayout(new GridLayout(1, 2, 10, 0));

        Container pane1 = new Container();
        pane1.setLayout(new GridLayout(8, 1, 8, 8));
        pane1.add(wordL);
        pane1.add(wordTF);
        pane1.add(lettersL);
        pane1.add(lettersTF);
        pane1.add(inputL);
        pane1.add(inputTF);
        pane1.add(checkB, BorderLayout.EAST);
        pane1.add(exitB, BorderLayout.SOUTH);

        pane.add(graphicPanel);
        pane.add(pane1);

        setResizable(false);
        setTitle("Hangman BETA VERSION");
        setLocation(120, 120);
        setVisible(true);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setSize(500, 500);
    } …
sciwizeh commented: useful information +1
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Yes, extending a component and overriding paintComponent() is the usual and preferable way to do it and this code would certainly benefit from that (drag another window over the frame and see what happens to the hangman graphic), but at a minimum the existing code could draw to a panel (or label) reference with few changes.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

He needn't rewrite the whole thing. Just a new panel where the drawing is to occur and use that graphic context to drawn on instead of the JFrame context.

By the way, be sure to dispose of a graphics context obtained with getGraphics() by calling dispose() on the reference when you are finished with it.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, these stand out pretty clearly

pixelData[x][y] = pixelData[x][y];
heatData[x][y] = heatData[x][y];

(around line 445 in your posting above)
and these

c = elements.get(pixelData[x][y]).getRed() + 
    heatData[x][y]; 
c2 = elements.get(pixelData[x][y]).getGreen() + 
    heatData[x][y]; 
c3 = elements.get(pixelData[x][y]).getBlue() + 
    heatData[x][y];

(~line 739)
The compiler may be able to consolidate some of those if it recognizes the invariance, but short of looking at the bytecode I can't say for certain. Those are just a few places where there is redundancy in an inner loop.

Other unnecessary access may be occurring from checks or calculations that have already been performed by a neighboring pixel or not needed at all because they are not near any active elements of the display. Not knowing nor having time to intimately know the code, I can't really say if that is the case or if it can't be dealt with easily. You know the logic of those loops and calculations and your intent far better and I am just pointing out some possibilities.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

HTML is not a programming language.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Perhaps you could develop "a software" that replaces all occurrences of "plz", "u", "ur", "thx", and other text-speak gibberish with their actual English words prior to posting. That would help compliance with the forum rules here.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Use a separate panel for the painting, don't paint directly on the JFrame.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

ok, i replaced the random creation with an instance variable, i haven't re-profiled it yet, although it didn't make a noticeable frame rate difference, i didn't expect it too... but overall it will probably all adds up though.

Correct. It's not a huge overhead, but given that it is unnecessary and the number of invocations of pc(), it is a worthwhile change to make.

changing to switch statements just won't work in an easy way, i use too many range comparisons (rand<3 for example) and not enough equalities (==) to make using switch statements work at all.

Changing to switch statement is unlikely to reap large improvements anyway, so I wouldn't sweat that. The number of array accesses and calculations per pixel is overwhelmingly the bulk of the workload.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Start with the Read Me post stickied at the top of this forum entitled Starting Java.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

So write it. I doubt you're going to find any "generic" code for that.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Neat program. I don't have a great deal of time to go through it at the moment, but here are some things to consider from the start.

First, you'll want to set up a repeatable test state of the program. In order to get any reliable information on the impact of any changes, you need to get your simulation running the same for each iteration. The easiest way to do that is probably to capture some of the commands you use to add elements to System.out (with their current parameters) and paste these into a test() method that you can call to rebuild the running conditions each time you want to test any changes.

Secondly, you need to capture the execution time for each invocation of computeAndDrawSand() so you have concreate numbers to work from. That is of course the roughest measure you can get. If you have a profiler to use, all the better, so you can drill down through methods calls (Netbeans has one build in and I think Eclipse may as well).

Here is a profiler snapshot from Netbeans after letting your code for several minutes with a lot of elements on the screen:

sandProfile.png


The bulk of your computation time is occurring in the moveSand() method, with doNeighbor() as the heaviest offender. The pc() method is pulling a lot of time due to a very large number of invocations (it also creates a new Random for each invocation). Are you sure …

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Post what you have so far if you would like input on it. See the forum policies on homework help. Asking for answers to "compare to yours" is identical to "answer this for me" for all practical purposes.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Why do you insist on claiming any credit for these posts?
http://www.google.com/search?sourceid=mozclient&ie=utf-8&oe=utf-8&q=%22I'd+planned+a+trip+to+Hawaii+next+month+but+this+is+so+easy+and+profitable+that+I+want+to+fix+it+before+it+cures+itself%22

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

"Our world has grown weary of greed, exploitation and division, of the tedium of false idols and piecemeal responses, and the pain of false promises," he told the crowd.

So he's saying the world has grown weary of the church?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You have "first" defined as a member of the "path" class, not of the "square" class. Also, you are using the class name, rather than the parameter name, in your on_path() method.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Can any one tell about the difference between the Abstract Class and Interface?

Abstract classes can contain implementations of some methods, while interfaces cannot. This allows abstract classes to serve as a base implementation of a class hierarchy that shares some (or much) common code and require that subclasses implement only the portions that are specific to themselves.

Can abstract class replaces Interface?

In some cases, yes, in others, no. See next comment below.

If all things can be done in Abstract class Why we need Interface?

Java only allows for single inheritance of classes, but the number of interfaces implemented is unlimited. Use of interfaces allows classes to act as more than one type of object. Without interfaces, all methods that you may want a group of classes to share must be stuffed into a common base class. What if some of these methods only apply to some classes but not others? Your class hierarchy would become a polluted mess, littered with methods that may not even apply to a particular class. Interfaces operate as a contract that guarantees a class implements one or more methods without forcing them to descend from a common base class. Many different kinds of class hierarchies may want to be Printable, or Comparable, or Displayable, without having to extend from some common ancestor. That can only be accomplished with interfaces.

You read more about this here if you wish: http://www.codeguru.com/java/tij/tij0080.shtml

Alex Edwards commented: Expert Answer +2
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Do not hijack threads for completely unrelated (and poorly written) requests for help.

Especially not with "urgent plz" in it.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You have overridden paint() but you are not calling paintComponents(), which is responsible for rendering the components in the container.

Painting on the frame directly often lends itself to troublesome behavior like this if you are not careful to preserve the top-level container rendering processes. It is much easier to instead use a JPanel for this within the frame and override paintComponent() (not paint()) on the JPanel for your drawing code.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You are not likely to find an open source hospital management system.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

how we can call one servlet from other servlet and give the source code of all process?
send it in this id: <removed>

1) Do not hijack threads. Post your own thread if you have a question.
2) Do not ask for code to be emailed. This is against the rules.
3) Read the tutorial that was already posted above. It is directly related to your question and you are just plain lazy if you cannot bother to read it.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

have u made the project?
plz send me one for i m in urgent need.

You are in urgent need of learning to do your own work. This forum is not for completing your homework for you.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Do not use "=" or "!=" to compare strings. Use the string function equals() or equalsIgnoreCase().

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Take a look at the end of line 14 where you have the while statement. See anything that perhaps should not be there?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Please place all posted code inside [code] [/code] or [code=java] [/code] tags.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You could also purchase the book Head First Java

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If you can't post the code, no one call say what you are doing wrong. Do you think we can read it over your shoulder?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Unfortunately, I would imagine so, unless you can find some third party conversion utility. That seems a bit unlikely though for TypeReader. I looked a bit on Google but didn't come up with anything.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Short batching programs like you describe are certainly easy to code up if you have access to the API commands to perform those actions. In this case that would mean a command line interface for TypeReader such that you could specify the input file and the output file and it's format via command line switches, or a scripting interface provided by the application. Not knowing anything about TypeReader, I couldn't say if it has any of those capabilities. I just saw the mention of the batch processing capability and thought that might be worth looking into.

Does Typereader have any macro recording or scripting capabilities? I didn't see any mention of macro functions.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Try this. It can be made a lot more efficient. Next time please put at least a psuedo code.

Handing students who have shown no effort at all on their assignment the answer is against the spirit of this forum, as evidenced by this prominent post at the top of the forum: http://www.daniweb.com/forums/announcement9-2.html

You are rewarding laziness and fostering incompetence.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Glad it worked for you.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Just recently the center portion of the User Control Panel has started clipping the right edge from the internal frames:


This is in Firefox 2.0.0.16, screen res 1280x1024.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, I found this statement about the new features in 6.0 Enterprise:
"TypeReader allows users to acquire multiple image files, specify a method of locating and recognizing, specify saving options and saving destination and complete the OCR process without any user intervention."

Have you looked into those batch processing features?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

With a text editor, of course.

Why don't you write a bit of pseudocode that outlines the general process the program must follow to complete the needed steps and post it here if you need some help with portions of it?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Here is the code I used to dump a "colorscan" display of some sensor data to an image file so I could fiddle with it in an external image processing package. Our component was using an offscreen Image buffer to draw on and then rendering with g.drawImage() in the paintComponent method, so I already had an Image of the panel, but I fiddled with the code just a bit and the following should work for you if you don't need to save the frame decorations (title bar, etc), just the contents .
The action listener code to save:

public void actionPerformed(java.awt.event.ActionEvent e){
    try {
        File saveFile = new File(jobFile+"_colorscan@"+centerSampleIndex+".gif");
        Image img = createImage(getWidth(),getHeight());
        Graphics g = img.getGraphics();
        paint(g);
        ImageIO.write(toBufferedImage(img),"gif",saveFile);
        JOptionPane.showMessageDialog(null,"Image saved to "+saveFile.toString());
        g.dispose();
    } catch (Exception ex){
        ex.printStackTrace();
    }
}

The method to convert the Image to a BufferedImage (which I found in some example somewhere):

// This method returns a buffered image with the contents of an image
private BufferedImage toBufferedImage(Image image) {
    if (image instanceof BufferedImage) {
        return (BufferedImage)image;
    }

    // This code ensures that all the pixels in the image are loaded
    image = new ImageIcon(image).getImage();

    // Determine if the image has transparent pixels; for this method's
    // implementation, see e661 Determining If an Image Has Transparent Pixels
    boolean hasAlpha = hasAlpha(image);

    // Create a buffered image with a format that's compatible with the screen
    BufferedImage bimage = null;
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    try {
        // Determine the type of transparency of the …
VernonDozier commented: Code worked perfectly. +5
darkagn commented: Great post with lots of useful info +1
Alex Edwards commented: You deserve a promotion, dude. Epic win. +2
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Nope.

You haven't even stated what it is supposed to do and what you are having trouble understanding. Just glancing at it, you've got a ways to go before this is complete.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Handing students completed solutions to their projects only enables laziness and incompetence. Limited examples, links to concept tutorials, and answers to specific questions are more appropriate.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Did you read through some of the work-arounds mentioned in that bug report to translate the color space?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Some of the info in this bug report might be of use:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4799903

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Consider the following for your KochComponent. All calculations are done outside of the paintComponent method (you don't need to override paint() at all). For each iteration, you need to add three intermediate points to each line segment to form the triangle portion.

public class KochComponent extends JComponent {

    List<Point> points = null;

    /** create the initial triangle */
    private void createTriangle() {
        points = new ArrayList<Point>();

        int length = Math.min(getWidth(), getHeight())*2/3;

        int x1 = (getWidth()-length)/2;
        int y1 = length/2;
        points.add(new Point(x1, y1));

        int x2 = x1+length;
        int y2 = y1;
        points.add(new Point(x2, y2));

        int x3 = x1+(length/2);
        int y3 = y1+length;
        points.add(new Point(x3, y3));

    }

    public void next() {
        numIterations++;

        List<Point> newPoints = new ArrayList<Point>();
        // generate the new points for each line segment
        for(int i = 0; i<points.size(); i++) {
            Point p1 = points.get(i);
            Point p2 = i==points.size()-1 ? 
              points.get(0) : points.get(i+1);
            newPoints.add(p1);
            newPoints.addAll(getKochPoints(p1, p2));
        }
        points = newPoints;
        repaint();
    }

    public void paintComponent(Graphics g) {
        // this is just to account for the fact that
        // the component has no initial width or height
        if(points==null) {
            createTriangle();
        }

        Graphics2D g2 = (Graphics2D)g;

        // Use this code to draw the actual poly
        // Polygon koch = new Polygon();
        // for (Point p : points){
        //   koch.addPoint(p.x, p.y);
        // }
        // g2.draw(koch);

        // This just draws unconnected points
        // for demo purposes
        for(Point p : points) {
            g2.drawRect(p.x, p.y, 1, 1);
        }
    }

    /** Generate the points to add for each segment
     * for each iteration.
     * I am …
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Ok, here is a small example of a multi-threaded server that I was playing around with a little while working on an auto-update launcher for an app here, maybe it will help. "Launcher" is the client portion. Each needs to be run separately on the same machine (since the client is connecting to localhost in the example)
Server:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.*;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class Server {
    final static int PORT = 12100;
    Thread processThread;
    
    public Server() {
        try {
            processThread = new ProcessThread(new ServerSocket(PORT));
            processThread.start();
        } catch(IOException ex) {
            ex.printStackTrace();
        }
    }
    
    private class ProcessThread extends Thread {
        ServerSocket server;
        ExecutorService requestPool;
        
        public ProcessThread(ServerSocket server){
            this.server = server;
            requestPool = Executors.newCachedThreadPool();
        }
        
        public void run() {
            try {
                System.out.println("server waiting to process..");
                while(true) {
                    Socket sock = server.accept();
                    // start an UpdateTask for this client
                    requestPool.submit(new UpdateTask(sock));
                    sleep(100);
                }
            } catch(IOException ex) {
                ex.printStackTrace();
            } catch(InterruptedException e) {
                   // Disable new tasks from being submitted
                   requestPool.shutdown(); 
                   try {
                     // Wait a while for existing tasks to terminate
                     if (!requestPool.awaitTermination(60, TimeUnit.SECONDS)) {
                       // Cancel currently executing tasks
                       requestPool.shutdownNow(); 
                       // Wait a while for tasks to respond to being cancelled
                       if (!requestPool.awaitTermination(60, TimeUnit.SECONDS))
                           System.err.println("Pool did not terminate");
                     }
                   } catch (InterruptedException ie) {
                     // (Re-)Cancel if current thread also interrupted
                     requestPool.shutdownNow();
                     // Preserve interrupt status
                     Thread.currentThread().interrupt();
                   }
                Thread.currentThread().interrupt();
            }
        }
    }
    
    public void shutdown(){
        if (processThread != null && processThread.isAlive()){
            processThread.interrupt();
        }
    }
    
    /** …
Alex Edwards commented: Thank you for providing an example =) +2
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

its a classpath error check your classpath.

No, it is not a classpath problem. It's a package declaration problem as already stated.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

>It seems like quite a few people here jump to conclusions that people are looking for homework help.

Hang around for a few months and see what conclusions you come to on such posts. If you still feel that people are unfairly jumping to conclusions about homework help, feel free to help all those posters as you see fit. Our time spent helping people here is completely voluntary and as such you can choose to help them or not, but your opinion regarding the conclusions others might draw on certain posts has absolutely no bearing on whether anyone else gives their time and effort to a particular request.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I haven't seen any tutorials for JSP , so I guess I will post this one link that I found.

http://www.visualbuilder.com/jsp/tutorial/pageorder/1/

Perhaps that is because JSP has it's own forum over in the Web Development section.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If you agree with it then what exactly is your point?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Vernon is completely correct. We volunteer our time helping people out as we see fit. Your current posting trend is leading you towards less help, not more.

VernonDozier commented: Here's some rep for agreeing with me :) and because you've written some good posts that I haven't given you rep for yet. :) +5
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Compare the arguments that you are using in the super() call to those in the Product constructor. They must match in type, order, and number. Yours don't.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Read the message: You are calling the super() constructor with arguments that do not match any declared constructor in the parent class.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I suspect it was merely an oversight and needs to be corrected on that page.