Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You might consider:
a) Sticking with the thread that you already started for this: http://www.daniweb.com/forums/thread212868.html

You didn't bother to inquire further about anything mentioned in that thread. Show some consideration on the matter.

b) Using code tags when you post code so it doesn't come out one big left-aligned wall of text.

BestJewSinceJC commented: seconded. +8
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

And pick a location for your thread and stick with it:
http://www.daniweb.com/forums/thread210653.html

All further discussion should be directed to that thread please.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I looked around here at work for the solution manual for my job, but never found it either.

Life's a bitch sometimes.

sknake commented: hah +9
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

In many (most?) locales, Sunday is the first day of the week, thus Wednesday is the fourth. From the Calendar.java source:

/**
     * Value of the {@link #DAY_OF_WEEK} field indicating
     * Wednesday.
     */
    public final static int WEDNESDAY = 4;

You can set the first day of week to be whatever you want on your calendar object with setFirstDayOfWeek(int) (whether you should is another question altogether).

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

As to the question, I think you at least need to get up to speed with some GUI programming in Java before you head into graphics:
http://java.sun.com/docs/books/tutorial/uiswing/index.html

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You already have an active thread on this in which you ask the same thing: http://www.daniweb.com/forums/thread213720.html

Please do not create new threads to re-ask questions unless they are veering too far from the original topic to remain in the existing thread.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

How can I do this because right now if the class is run without an initial image, there will be an error.

Well, then make sure your code is not dependent on that image reference being set. A few null checks or whatever you need. It's your code, so "there will be an error" only comes into play if you let it.

After that is squared away, create a method setImage(Image) that let's you set the image on the panel.

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

It looks like Launch4j might be able to help with that. I've never used it myself though.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Welcome!
Please keep in mind we strive to be a community geared towards the professional. We strongly encourage all posts to be in full-sentence English. Please do not use "leet" speak or "chatroom" speak.

Enjoy the community!

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Try including E.printStackTrace(); as well. You are discarding the more detailed info from the exception.

I agree with Peter though. You probably don't have that jar on your classpath.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

1. Do most people still use Eclipse as an IDE for Java? (The best?)

I'm using Netbeans personally. Eclipse is good as well, but I can't speak to what "most" are using. Both are highly functional, so try one or both and stick with the one you prefer.

2. Is there a definitive website for OpenGL in Java programming?

JOGL is just a set of wrappers for the OpenGL library and the function names are as identical as they can make them. You shouldn't have any trouble "translating" the code from any OpenGL site or tutorial. I started out with the NeHe tutorials and the red book. The JOGL user guide has some general getting started info that is specific to JOGL and this link from that page will get you up and running quickly with a basic object framework for using GLDrawable.

3. Will I be limited to webapps similar to Runescape when programming OpenGL with Java, or can I make executables that run when installed as well?

You can create executable jar files that run on the desktop. You are not limited to web apps.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I've not personally had any problems running Firefox 3.5.2 on 64-bit Vista. I've only had that system about a week though.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You really shouldn't need to install OpenGL. Your video driver should support it. You should be able to grab the JOGL library and be off and running with OpenGL in Java.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

But I think that the people who become 'regulars', aren't here for blocks or stars, ...

Blocks and stars are my only raison d'être. My soul will die without them.

~s.o.s~ commented: For your soul :-) +29
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

We have too much government. They should not have control of your site.

You should write a letter and shake your fist a lot.

Nick Evan commented: and stop eating meat and start hugging trees ;) +26
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Take a look at the Robot class.

TheWhite commented: thaks! +2
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Actually, I would agree. Moving...

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Here is a small function that will extract a single entry from a jar file. The "jarEntry" parameter is simply a string path like "com/myPackage/MyClass.class" that denotes the entry you want to extract

public static void extractFromJar(String jarEntry, File jar, File outputFile) throws IOException{
        JarFile jarFile = new JarFile(jar);
        JarEntry entry = jarFile.getJarEntry(jarEntry);
        if (entry!=null){
            InputStream jarEntryStream = jarFile.getInputStream(entry);
            FileOutputStream outStream = new FileOutputStream(outputFile);
            byte[] buffer = new byte[1024];
            int bytes;
            while ((bytes = jarEntryStream.read(buffer)) != -1) {
                outStream.write(buffer, 0, bytes);
            }
            outStream.close();
            jarEntryStream.close();
            jarFile.close();
        }
    }

As for your path question, you can use getResource() as you did above to search for a resource location in the class path or you can use System.getProperty("user.dir") to obtain the path that the app is currently executing in.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

which of course doesnt work..

So don't do that.

btw, I know the way I did this was all jacked up. Can anyone help me? I'm sure theres a better way. I can try to explain more if I can.

Extract the file before you run it. Look at the JarFile class and specifically the getInputStream(java.util.zip.ZipEntry) will let you get an input stream for a particular entry, which you can then write to an output stream.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Look at the methods available on the String class.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You don't insert JLabels into JLabels. Put them in a panel. Use a loop and an appropriate layout manager.
http://java.sun.com/docs/books/tutorial/uiswing/layout/using.html

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

You're missing the parenthesis

public void start(){

on that method and another after it.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

By caling JLabel.setIcon() in whatever event you're using to process input.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

From series of PMs on this:

Hi, I have implemented the dragging however because in the example you gave me the paint draws everything in the shapes arraylist so when i drag a shape the orignal position is drawn. Also the path which the circle is dragged is also drawn. I don't know why that is. I'm also not too sure how to use your hitTest method. If it returns the shape under the cursor how would i then use that to select the shape, for example by colouring it a different colour and then implementing the move? Sorry for so many questions. I really hope you can help. Thank you for the help you'v given so far.

My example showed how to select one of the shapes with the mouse click and move it when dragged. Your current code adds a new shape on click. You need to decide which you want to do, because you can't do both at the same time. You could use right/left click or modifiers like shift to separate the operations.

That is the problem I am having. I need to be able to draw the circle where the mouse is clicked. Then be able to select the circle and move it to a new position. I don't know how to do that.

And I alrady explained that you need to separate the two actions into two different mouse events, unless you want to first do the hitTest to check for a …

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Here's a small example of a custom JPanel class that keeps a List of Shape objects and lets you drag them with the mouse. Perhaps it will clear up some of your uncertainties

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Shape;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;
import java.awt.geom.RectangularShape;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class DraggableGraphic extends JFrame {
    
    private JPanel paintPanel;

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

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

    class PaintPanel extends JPanel implements MouseMotionListener,MouseListener {
        private List<Shape> shapes;
        private Shape mouseOverShape=null;
        
        public PaintPanel(){
            super();
            addMouseListener(this);
            addMouseMotionListener(this);

            shapes = new ArrayList<Shape>();
            shapes.add(new Ellipse2D.Float(25, 15, 60, 30));
            shapes.add(new Ellipse2D.Float(75, 35, 60, 30));
        }
        
        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D)g;
            for (Shape s : shapes){
                g2.draw(s);
            }
        }

        public void mouseDragged(MouseEvent e) {
            if (mouseOverShape!=null){
                if(mouseOverShape instanceof RectangularShape){
                    // Move the shape center to the mouse location
                    RectangularShape rShape = (RectangularShape)mouseOverShape;
                    float width = (float)rShape.getWidth();
                    float height = (float)rShape.getHeight();
                    rShape.setFrame(new Rectangle2D.Float(e.getX()-width/2, e.getY()-height/2, width, height));
                }
                repaint();
            }
        }

        public void mouseMoved(MouseEvent e) {}

        /** returns the first Shape that contains Point p or null if none contain p */
        private Shape hitTest(Point p){
            Shape hitShape = null;
            for (Shape testShape : shapes){
                if (testShape.contains(p)){
                    hitShape = testShape;
                    break;
                }
            }
            return hitShape;
        }


        public void mousePressed(MouseEvent e) {
            // figure out what shape, if any, that we are clicking on
            mouseOverShape = hitTest(e.getPoint());
        }

        public void mouseReleased(MouseEvent …
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You should restructure your code a bit to override the paintComponent() method of the JPanel objects you wish to draw to, rather then calling getGraphics() to obtain the graphics context. I gave an example above of how paintComponent() can loop through and render the shapes. Your mouse methods just need to create or modify shapes in the List and call repaint to update the graphics.

I'd recommend looking through this short tutorial on custom painting in Swing to see how to override paintComponent().
http://java.sun.com/docs/books/tutorial/uiswing/painting/index.html

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

In your mouse listener methods, create the Shape objects instead of drawing them directly to the screen.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If you maintain a list of shapes

List<Shape> shapes = new ArrayList<Shape>();

You can override the paintComponent method to paint them like so

public void paintComponent(Graphics g){
    Graphics2D g2 = (Graphics2D)g;
    for (Shape s : shapes){
        g2.draw(s);
    }
}

If you want to move one of the shapes, your mouse routines first need to determine which shape is under the cursor. You can do that easily by checking the contains() method of each Shape against your mouse coordinates. Here is a method you could use to check them

private Shape hitTest(Point p){
    Shape hitShape = null;
    for (Shape testShape : shapes){
        if (testShape.contains(p)){
            hitShape = testShape;
            break;
        }
    }
    return hitShape;
}
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

And don't forget about the Sun tutorials:
How to Use Progress Bars

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

i clicked it on accident. So im guessing you wont help me because youre an A hole.

I think your technique on asking for help could use a little work.

Salem commented: Dunno, early identification of idiots is kinda useful ;) +36
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You don't need the path equation. You just need the distance between the points.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Closing this thread since you already have the other active thread on this issue.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Take care of yourself and good luck with everything :)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Why? Sounds boring to me.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

HTML is a subcategory under Web Design, for future reference in finding it :)
Moving this there.

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

Moving an actual component would trigger a repaint automatically, but it looks like he is "dragging" a shape that's been painted on the component, which would require a repaint() to update the location.

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

Someone didn't take their meds today.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You need to initialize the array before you can use it.

books = new Book[MAX_BOOKS];

where MAX_BOOKS would be whatever initial size you wanted to make the array.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

http://en.wikipedia.org/wiki/Shrink_wrap
It's great stuff with many applications.
Good luck on your test.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

That could be done if you stored a unique JComboBox instance in that column value for each row, which is somewhat equivalent to storing a List in that cell. You will probably have to deal with forwarding click events through the JTable down to the embedded component if you do store a combo box as a data item.

Honestly, the best way to handle these "but could I..." questions is to code them up and try them. It seems like an awkward way to handle that data to me, but it's your app and you're free to display it any way you choose.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Oh, I'm sure you could do it given how flexible JTable and related models are. You would probably need to alter your table model to store a List in that column and use a JComboBox as the renderer for that List. You'll have to update the combo box's model to reflect the List value for each row.

It's not as quick and simple as using a combo box as an editor for a single value though.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

>I want all the values visible, just in a 'clean' atmosphere so that the table doesn't look crammed/jumbled
Putting them into a combo box is not keeping them visible. The user must select the drop down portion to see them. This is a selection choice which would just as easily drive another list or table that listed the additional details.

Why not simply put the table in a scroll pane and let the user scroll over to those additional columns whenever they want to see them?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If you don't want all of the values visible at once as a table, I would personally probably go with a list or second table that loads the additional entries as the primary table selection changes.

The specifics of how you need to view and work with the data ultimately drive choices like that.