Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

By adding a repaint() call in mouseDragged() as well.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Your clock viewer component currently has no size because it's an empty container and you have used the default flow layout. It's drawing on the panel, you just can't see it because it has no dimensions. Here's an alternate layout and setup for that panel that does show the clock.

private void createPanel() {
      panel = new JPanel(new BorderLayout());
      
      JPanel controlPanel = new JPanel();
      controlPanel.add(hourLabel);
      controlPanel.add(hourField);
      controlPanel.add(minuteLabel);
      controlPanel.add(minuteField);
      controlPanel.add(button);
      
      panel.add(controlPanel, BorderLayout.NORTH);
      panel.add(component,BorderLayout.CENTER);
      add(panel);
   }

You can learn more about using the various layout managers that are available here: http://java.sun.com/docs/books/tutorial/uiswing/layout/index.html

Edit: Doh! Vernon beat me to the post.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Like any other image comparison, it depends on what you are wanting to accomplish. Read through the wiki on Computer Vision and figure out which area you are trying to work in. Then seek out further information on that particular branch.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

A parser is an application that scans through text data and extracts certain pieces of information. Regular expressions are useful for that because they are extremely flexible in defining patterns for matching against that data and specifying what information is gathered when a match occurs.

You can read through a couple of tutorials on them here if you like:
http://java.sun.com/docs/books/tutorial/essential/regex/index.html
http://www.regular-expressions.info/java.html

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It is a full-time job and the ongoing expansion of business lines, data acquisition technology, and customer requirements has kept four developers busy for over five years. It does not show any signs of abating soon.

>Why do you spend so much time on daniweb helping people like myself?
I enjoy it.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I am curious if anyone here is a java developer and actually makes good money at it?

Yes and yes.

Basically I would like to know what kind of stuff you do, where you work from, office, home, etc.

I work in a small office with three other developers on an internal data analysis desktop application.

PhiberOptik commented: Thanks! +2
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

By the way, I just noticed that the person who send me that PM has the flag "Banned" under his name.

That means the issue has been addressed :)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It sounds like you just want the x postions. Your y positions are fixed. Since you already capture startPoint and endPoint in your mouse listener routines, you have all of the coordinates you need.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

From your example, the start and end values just look like x values. I don't see where you have any other scale your trying to translate to. You say "not X and Y coordinates" but your example only shows x values and it would appear you are just trying to capture startPoint.x and endPoint.x, with no need for the ratio calculation.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If you're only working with 1400-1500 lines I would read them into another structure for the comparisons or you could use random access files.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

So you have some object start/end values for each rectangle (not screen x coordinates) that you need to compare against?

If that is the case, you'll need to test for containment of your start point and end point as you did in the mouseMoved() method. Once you know which rectangle contains a point, you can use the ratio of of the user drawn x to the containing rectangle's start and end x coordinates to calculate your "object start" value:

val=10               20
     #################
     #               #           < existing rect
     #################     
x=  30               80

new val= 12
          ###################       < rect drawn  by user
  user x=40
        
new val = val1 + ((userx-x)/(x2-x1) * (val2-val1)) = 10 + ((40-30)/(80-30) * (20-10)) = 12

Repeat for the end point rectangle.

Is that what you're looking for?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Just adding

class PaintPanel extends JPanel implements MouseMotionListener[B], MouseListener[/B] {

and the mouseClicked(), mouseEntered(), and mouseExited() method signatures (empty implementations) will get you a lot further along. The rectangle drag and paint code that you wrote does work. You just missed the additional listener to tie it in. Don't forget to add

addMouseListener(this);

as well, after your other listener registration.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You would probably need to reset() the stream to get that to work. After it's read all the way through the file, seLine=seReader.readLine() is going to remain null - it's done reading.

Unless your files are so large as to cause memory problems, you'd get a lot better performance reading those comparison values into a collection from the file and using that collection for your line item comparisons.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

No, your class def only states that it implements MouseMotionListener. It also needs to implement MouseListener as adatapost says and it needs to register itself with addMouseListener().

edit: You'll need to add mouseClicked(), mouseEntered(), and mouseExited() methods as well to fulfill the implementation.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I'd say just let the timer keep running then. You can handle the delay before restart and the reset to 60 easily

class CountdownTimer implements ActionListener {
    final int TOTAL_TIME = 60;
    int counter = TOTAL_TIME;
    javax.swing.Timer refreshTimer;

    public CountdownTimer(){
        refreshTimer = new javax.swing.Timer(1000, this);
    }

    public void actionPerformed(ActionEvent e) {
        counter--;
        if (counter>=0){
            System.out.println(counter);
        }
        if (counter == -2){
            reset();
        }
    }

    public void start(){
        refreshTimer.start();
    }
    public void stop(){
        refreshTimer.stop();
    }
    public void reset(){
        counter = TOTAL_TIME;
    }
}
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

How are you wanting to reset it? Is there some action that should prompt the reset or should it just start counting from 60 again? You don't have to stop the timer if you don't want to when zero is reached.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I would second JamesCherill's suggestion of subdividing the pixel array into a smaller number of regions, perhaps 10x10, with each region assigned the average of those pixels. Then subtract the two arrays and compare the result against some tolerance threshold value to determine if they are "the same enough" for your purposes.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

CountdownTimer can just be a private inner class of StatusBar. It's only a helper object to manage your timer count down and doesn't need to be a top-level public class. As an inner class, it has access to everything in StatusBar so setting the label text is no problem.

Edit: You were already effectively using two anonymous inner classes to manage this functionality in your first version. This just combines them and encapsulates the function into one small helper class.

jasimp commented: It feels goood to be back, and see that you're still helping out. Maybe I can lighten the load a little again ;) +10
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You actually want to set the label's text from within your actionPerformed() method of the timer, so change the System.out.println() to

public void actionPerformed(ActionEvent e) {
        counter--;
        [B]countdown.setText(String.valueOf(counter));[/B]
        if (counter==0){
            stop();
            reset();
        }
    }
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If it's an inner class, it can still access your JLabel just fine.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It would be a bit cleaner if you just combined them into a small class

class CountdownTimer implements ActionListener {
    int counter = 60;
    javax.swing.Timer refreshTimer;

    public CountdownTimer(){
        refreshTimer = new javax.swing.Timer(1000, this);
    }

    public void actionPerformed(ActionEvent e) {
        counter--;
        System.out.println(counter);
        if (counter==0){
            stop();
            reset();
        }
    }

    public void start(){
        refreshTimer.start();
    }
    public void stop(){
        refreshTimer.stop();
    }
    public void reset(){
        counter = 60;
    }
}
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Math.abs(a-b) < 2

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, yes, if you put it outside the listener like that - so don't do that. Place the check and the reset in the actionPerformed() method. You can stop the timer there also.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

When your counter gets to zero, stop the timer and reset the counter to 60.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Did you add that refreshListener to something? Just glancing at it, what you wrote looks as though it should work fine (except for the syntax error "counteLimitr"), though it won't stop at zero.

KirkPatrick commented: You've been very helpful throughout the whole thread, I appreciate it very much +1
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

MouseOverExample is just the top level frame class and has nothing at all to do with the Glyphs. It's just a window for the PaintPanel. There is no need for the constructor you're created for it and no need to create additional instances of it in your code.

As far as the GradientPaint, you cannot simply replace the Rectangle instance inside the Glyph class with a GradientPaint and expect everything to work the same. Those are two completely different things. The Rectangle is a Shape, which you are drawing. The GradientPaint is the paint used to render that shape. Here is the Glyph class modified to use a GradientPaint to fill the rectangle.

class Glyph {
    private Rectangle bounds;
    private Color color;
    private Paint paint;
    private String label;
    private boolean showLabel = false;

    public Glyph(int x, int y, int width, int height, Color color, String label) {
        bounds = new Rectangle(x, y, width, height);
        this.color = color;
        // create GradientPaint that runs top to bottom from 'color' to white
        this.paint = new GradientPaint(x, y, color, x, y+height, Color.WHITE);
        this.label = label;
    }

    public void draw(Graphics g){
        Graphics2D g2 = (Graphics2D)g;
        //g2.setColor(color);  /** Use setPaint() instead */
        g2.setPaint(paint);
        //g2.draw(bounds); /** Use fill() instead */
        g2.fill(bounds);
        if (showLabel){
            g2.setColor(Color.BLACK);
            int labelWidth = g2.getFontMetrics().stringWidth(label);
            int fontHeight = g2.getFontMetrics().getHeight();
            g2.drawString( label, 
                (int)(bounds.getX() + (bounds.getWidth()-labelWidth) / 2), 
                (int)(bounds.getY() + (bounds.getHeight()+fontHeight/2) / 2d));
        }
    }

    public boolean contains(int x, int y){
        return bounds.contains(x,y);
    }

    public void showLabel(boolean show){
        showLabel = show;
    }
}
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

No, a statement is a single SQL statement. You can batch them into transactions and commit them as a unit if you wish, but each statement still needs to be executed individually. You could write a stored procedure and call it with a CallableStatement if you wanted to go that route.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

As I already posted, and so did javaAddict:
use executeUpdate().

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

For a quick all-in-one installation, I'd recommend WampServer or XAMPP.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, the first hint would be the exception itself, which you did not specify here.

I would recommend using executeUpdate() which returns the number of rows affected instead of executeQuery(), which return a result set.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Ok, here's a small example using a Glyph class that internally uses Rectangle to manage its bounds and shows a label when moused over:

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class RectangleMouseover extends JFrame {
    
    private JPanel paintPanel;

    public RectangleMouseover() {
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setMinimumSize(new Dimension(300, 300));

        paintPanel = new  PaintPanel();
        getContentPane().add(paintPanel, BorderLayout.CENTER);
        pack();
    }

    class PaintPanel extends JPanel implements MouseMotionListener {
        private List<Glyph> glyphs;
        
        public PaintPanel(){
            super();
            addMouseMotionListener(this);

            glyphs = new ArrayList<Glyph>();
            glyphs.add(new Glyph(25, 15, 60, 30, Color.BLUE, "Blue node"));
            glyphs.add(new Glyph(75, 60, 50, 60, Color.ORANGE, "Orange node"));
        }
        
        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            for (Glyph glyph : glyphs){
                glyph.draw(g);
            }
        }

        public void mouseDragged(MouseEvent e) {}

        public void mouseMoved(MouseEvent e) {
            for(Glyph g : glyphs){
                g.showLabel( g.contains(e.getX(), e.getY()) );
            }
            repaint();
        }
    }

    class Glyph {
        private Rectangle bounds;
        private Color color;
        private String label;
        private boolean showLabel = false;

        public Glyph(int x, int y, int width, int height, Color color, String label) {
            bounds = new Rectangle(x, y, width, height);
            this.color = color;
            this.label = label;
        }

        public void draw(Graphics g){
            Graphics2D g2 = (Graphics2D)g;
            g2.setColor(color);
            g2.draw(bounds);
            if (showLabel){
                g2.setColor(Color.BLACK);
                int labelWidth = g2.getFontMetrics().stringWidth(label);
                int fontHeight = g2.getFontMetrics().getHeight();
                g2.drawString( label, 
                   (int)(bounds.getX() + (bounds.getWidth()-labelWidth) / 2), 
                   (int)(bounds.getY() + (bounds.getHeight()+fontHeight/2) / 2d));
            }
        }

        public boolean contains(int x, int y){
            return bounds.contains(x,y);
        }

        public void showLabel(boolean show){
            showLabel = show;
        }
    }

    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() …
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

He isn't referring to the space between the type and the variable name.

String name;

is just fine.
It is these

int item number;
    int number of units;
    int price per unit;

that are not allowed.
Generally they would instead be written

int itemNumber;
    int numberOfUnits;
    int pricePerUnit;
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You may find a few different ways to accomplish it, but basically it's going to involve steps similar to that example.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Anything like that is going to be a custom header renderer - which as you noted is "hundreds of lines". It's not a trivial thing that you do in a couple of lines of code. I assume you ran across this implementation: http://www.esus.com/docs/GetQuestionPage.jsp?uid=1272

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

That is the online version of the same book linked above. It can also be downloaded as html or pdf. (http://java.sun.com/docs/books/jni/)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You've defined your own Rectangle class, so you can't expect to use the java.awt.Rectangle method contains() for a hit test on that. You could change your class a little to keep a java.awt.Rectangle internally for it's bounds and use that for the hit testing and stuff.

For the tooltip behavior, I think you'd have an easier time just using JLabels for your rectangles, which already have a tool tip that you can just set directly, instead of your custom class. You can also set their size, location, text, and background color directly on JLabels and you inherit a ton of JComponent methods for handling other UI behaviors if you need them.

If you decide to stick with a class that uses a Rectangle and rendering it yourself, I would recommend moving the rendering code into the class itself by adding a draw(Graphics g) method and passing in the graphics reference. You can then draw the label string yourself if need be and your frame class doesn't have to keep track of all of the pieces. Your paintComponent() methods would just loop your List and call draw() on each of them.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

There are also other text components depending upon the functionality you need. You can read more about them here: Using Text Components

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Post your initial code that is drawing the rectangles. As a general suggestion, keep a List containing java.awt.Rectangle objects for each entry you have to draw. Your mouseMoved and mouseClicked method implementations can easily test against those Rectangle objects by their contains() methods.

Alternately you could use a null layout and JLabels or a small JComponent class for your rectangles, which would manage some of the mouseover handling for you.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

First, you need to realize that Java != Javascript. There is a separate forum for Javascript. I've requested that one of the mods for this section move it there for you.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Have you read through the documentation on the SQLite site and the SQLite Wiki FAQ? What other questions do you have about it? The DB itself is just a set of files. How you interface with the database will depend on what language you are using for your application.

Edit: I guess you found what you needed while I was posting :)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Moved to PHP.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

1) I said move, not remove.
2) Yes, unless you want 'number' to be set to the number of bytes read on each invocation of that statement in your loop - which negates the whole point of incrementing it inside the loop as a counter.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The value of 'number' is what you are wanting to return, since that is your counter variable. Of course, you will have to declare it above the try-catch block to do so... and not reset it every read iteration with this part number = stream.read()

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You defined number in the try block. It is out of scope in the finally block. Even if it weren't, it's the stream that you want to check for null - not the number.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You read from 'stream'. That is your InputStream object that is being passed into the method.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You have those backward. I don't think you intend to read() from 'number'.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Ok, change your Window class constructor just a bit to this

public Window(){
        super();
        scene=new Scene();
        getContentPane().setLayout(new BorderLayout());
        getContentPane().add(scene,BorderLayout.CENTER);

        setSize(400,600);
        setLocation(300,100);
        setVisible(true);
        setResizable(false);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        requestFocus();
    }

The main difference is adding your "Scene" panel to the content pane of the JFrame and doing it before the setSize() and setResizable() calls.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Try adding the entire path to your image file. It may just be a resource location issue. If that works, you may want to use getResource() for locating the file resources as discussed in this tutorial: http://java.sun.com/docs/books/tutorial/uiswing/components/icon.html#getresource