Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You may just be missing a call to setVisible().

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

making of game in java

Asking of coherent question in new thread.

BestJewSinceJC commented: hahaha. +4
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You just said that you already have an idea for doing a project on image processing. So why are you asking for project ideas?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Thanks for your enlightened insight, devin. I'm sure many will benefit from this advice.

~s.o.s~ commented: LOL, ROFL etc. :-) +0
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

This is rather amusing. I posted a long, insightful write up on why I don't use Windows. And guess what - my reputation is instantly modded down. Now why would that be. Is it possible that Microsoft Trolls hang out here?

I think so.

Perhaps because your entire post comes across as a long troll? I didn't find much of it very insightful - just another anti-Microsoft rant.

/yawn at your indignation.

majestic0110 commented: Agreed +0
tux4life commented: Seconded +0
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The super.paintComponent() call just let's the component perform whatever normal painting the super class would if the method weren't overridden.

To the OP: you may want to glance over this bit of info on the Swing painting mechanism: http://java.sun.com/docs/books/tutorial/uiswing/painting/closer.html

Your paintComponent() code is painting the JPanel portion and then paintChildren() renders the other components (such as the label with image) on top of that JPanel area.

If you created a class that extended JLabel you could paint over its icon image just fine by placing your custom code after a super.paintComponent() call.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You declare it as an array of CD objects, like so

CD[] cdList = new CD[10];

and create them in the array like so

cdList[0]=new CD("Kaiser "," up the khazi ", 9.99);
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Start with the information in the Read Me: Starting Java thread stickied at the top of the forum. That is exactly why it was put together.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I think it offers a lot of good material and things to think about to someone young in the industry.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You could use something like this in your MapPanel to manage the "spots"

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

public class MapPanel extends JPanel {

    Image map;
    ImageIcon spot1, spot2, spot3, note;
    JLabel point1, point2;

    public MapPanel() {
        Toolkit kit = Toolkit.getDefaultToolkit();
        map = kit.getImage("cebumap.jpg");

        spot1 = new ImageIcon("spot.gif");
        point1 = new MapLabel(spot1, "p1");
        point1.setBounds(168, 30, spot1.getIconWidth(), spot1.getIconHeight());

        spot2 = new ImageIcon("spot2.gif");
        point2 = new MapLabel(spot2, "p2");
        point2.setBounds(203, 55, spot2.getIconWidth(), spot2.getIconHeight());

        setPreferredSize(new Dimension(457, 540));

        setLayout(null);
        add(point1);
        add(point2);
    }

    public void paintComponent(Graphics comp) {
        Graphics2D comp2D = (Graphics2D)comp;
        comp2D.drawImage(map, 0, 0, this);
    }

    /** Small convenience class to manage all of your special point label functionality in one place */
    class MapLabel extends JLabel implements MouseListener {
        Icon icon;
        String name;

        public MapLabel(Icon icon, String name) {
            this.icon = icon;
            this.name = name;

            setIcon(icon);
            setToolTipText(name);
            addMouseListener(this);
        }

        public void mouseClicked(MouseEvent e) {
            JOptionPane.showMessageDialog(this, "You clicked " + name);
        }

        public void mouseEntered(MouseEvent e) {
            setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        }

        public void mouseExited(MouseEvent e) {
            setCursor(null);
        }

        public void mousePressed(MouseEvent e) {}
        public void mouseReleased(MouseEvent e) {}
    }
}
nagatron commented: Impressive, Great, Good Job +2
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster
nagatron commented: Thank you again for the help. . .eventhough I am anoying. .hehehe +2
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If you actually asked a question then perhaps someone could answer it.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I would recommend reading Code Complete, 2nd Edition.

majestic0110 commented: Good Book! +6
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It's telling you that you can't use constructors that don't exist.

majestic0110 commented: Beat me to it lol :) +6
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

There is a little red triangle icon in the upper righthand corner to report the private message. It's in the same frame as the title of the PM.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Just copy everything from lines 3-10 into your method and change the variables to use your method parameters.

KirkPatrick commented: I didn't realize object had to be changed to component. Thanks for the help bud +1
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

File > New Project...

jasimp commented: haha +12
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The dots were red, but negative rep didn't count in the lounge on the old system either (at least not in the time period you are referring to)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Also note that it's a compiler warning, not an error. You can still run the program just fine.

majestic0110 commented: Good point +5
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

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

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

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

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

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

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

>Let me bring my face close that i may inhale the toner fumes of your papery printed essence.

I think perhaps you have had enough of the toner fumes.

jephthah commented: :D +11
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

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

I guess that would really depend on how you read and then wrote that date, wouldn't it?

Salem commented: Elementary, my dear Watson +34
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

...

User: Nah, you're Ashamed.

Cleverbot: I am Nive Cleverbot.

User: You are Ashamed.

Cleverbot: I'm not! I'm Nick.

User: Just making things up now, eh?

Cleverbot: You will not be lonely if you are talking with me.

User: I'm not lonely.

Cleverbot: You're overworked.

User: No, I don't think so.

Cleverbot: I have to go to bed.

User: Baloney, you aren't going anywhere.

Cleverbot: Yes I am.

User: Oh? Where?

Cleverbot: To a store.

User: What happened to bed then?

Cleverbot: I'm not sure.

User: You should drink more whiskey then.

Cleverbot: I do not like MIller.

User: Me either. It's nasty stuff.

Cleverbot: Why?

User: Who knows?

Cleverbot: Are you happy?

User: Would you be happy if I were happy?

Cleverbot: No. I'd be glad.

User: Glad makes sandwich bags.

Cleverbot: I wish I had things to distract myself from thinking about love.

User: Think about sandwich bags.

Cleverbot: Ok, but Monday is... Tomorrow.

User: But tomorrow it will be Today.

Cleverbot: Then what shall we do tomorrow?

User: I won't be doing anything with you.

Cleverbot: How so?

User: So how>.

Cleverbot: Sow ho?

User: Oh Wos!

Cleverbot: What is your name?

User: You are Ashamed.

Cleverbot: No.

User: You keep denying that.

Cleverbot: I have to now.

User: No, you can admit it.

Cleverbot: How about you?

User: How about me?

Cleverbot: What about you?

User: Why about you?

Cleverbot: So?

User: Because?

Cleverbot: Because you're crazy!

User: And you're Ashamed.

Cleverbot: You found it.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You may want to look at some of the resources posted here in the FAQ thread.

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

As for an array of text fields, all in all it would still be just about as many lines of code but it would look cleaner to do it that way.

Well, I would say this is a few less lines

for (int i=0; i<jComboBox1.getSelectedIndex(); i++) {
    textFields[i].setVisible(true);
}

A fall-through switch is more hard-coding than I would prefer, but still far fewer than that if-else block (which could really be just a series of if() statements to eliminate the repetitive statements.)

switch (jComboBox1.getSelectedIndex()){
    case 2:
        cTextField.setVisible(true);
        // fall through
    case 1:
        bTextField.setVisible(true);
        // fall through
    case 0:
        aTextField.setVisible(true);
}
KirkPatrick commented: Thank you for further explaining that for me. To top it off, in a kind manner which not too many people do these days. Cheers bud +1
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

There is no condition on an "else" clause, so this isn't valid syntax

else (jComboBox1.getSelectedIndex == 9)

.

The bigger question is why not use a switch or even better yet, an array of text fields so you don't have so much manually repetitive code.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Until recently, we thought that mushrooms were the organism when they are just the sexual organs of a much larger organism.

Eww, I stepped on a couple in my yard yesterday - I didn't know I was tromping on something's privates :icon_eek:

jephthah commented: aha +9
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Don't rely on getParent() for getting back to your JFrame. Create a constructor for your panels that takes a reference to that frame as a parameter. All of your panels will then be able to make requests on the main frame. If you create methods such as loadNext() on your frame class then the panels can simply call that and not worry about the mechanics of swapping them.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The Mathematics of the 3D Rotation Matrix might be worth a read for you. If it's too deep at the moment, perhaps it will be helpful as you get in further.

Gamedev has many articles on matrices as well if you want to peruse them: http://www.gamedev.net/reference/list.asp?categoryid=28#259

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Distance to center would provide a single calculation to check against that only involves two points. It's arbitrary, really, how close you decide is "close enough" for the association for "A vs B". Given that you only have to know when a user a dragged them near one another, I wouldn't bother determining min distance checks per side.

BestJewSinceJC commented: Good suggestion - & thanks for all the help +4
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Looks reasonable, however you probably want to sleep for a bit between each update and you may want to ensure that your updates to the text area are being made on the event thread

public void run() {
            try {
                setFinish(false);

                for (int i = 0; i < 1000; i++) {
                    // queue the text update
                    SwingUtilities.invokeLater(new Runnable() {
                        public void run() {
                            myTextArea.setText(myTextArea.getText() + i);
                        }
                    });
                    // sleep for a bit so repaint and other stuff can process
                    Thread.sleep(100);
                }

                setFinish(true);               
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
        }
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, perhaps this chapter from Thinking In Java, 3rd ed will be helpful: http://www.codeguru.com/java/tij/tij0087.shtml
You might look through the info on Java Glossary as well: http://mindprod.com/jgloss/array.html

Salem commented: Sounds good to me +29
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

And what is your question? That's just a homework assignment you posted.

Salem commented: Well the implied question was "Is this a site which dishes out free answers to lazy noobs?" Which the answer is of course "no", and that's why they've gone to infest somewhere else +29
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I only used the if-else construct to compare the elements selected from the list with the contents of the file.

Then you're still hard-coding what to do with each item as it's selected and that negates the reason for storing them in a file at all. Here is a very small example of the design I mentioned above. You need an "Item" class to hold the data for each of those items and you can use that directly within the JList

import java.awt.BorderLayout;
import java.util.ArrayList;
import java.util.List;
import javax.swing.DefaultListModel;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

public class ListExample extends JFrame {
    JList itemListing;
    JLabel pathLabel;

    public ListExample() {
        getContentPane().setLayout(new BorderLayout());
        setDefaultCloseOperation(EXIT_ON_CLOSE);

        // Build your ListModel from the items list.
        // You could very easily make this custom
        // ListModel class to handle all of the data retrieval.
        DefaultListModel model = new DefaultListModel();
        List<ListItem> fileItems = getItemsFromFile();
        for (ListItem item : fileItems){
            model.addElement(item);
        }
        itemListing = new JList(model);
        itemListing.addListSelectionListener(new SelectionListener());
        getContentPane().add(itemListing, BorderLayout.NORTH);

        pathLabel = new JLabel();
        getContentPane().add(pathLabel, BorderLayout.SOUTH);

        setBounds(100,100,300,200);
    }

    /** Just an example, you would retrieve these items from
     * file, database, whatever.
     */
    private List<ListItem> getItemsFromFile() {
        List<ListItem> items = new ArrayList<ListItem>();
        items.add(new ListItem("One thing","c:\\someDir\\oneThing.jpg"));
        items.add(new ListItem("Another thing","c:\\someDir\\anotherThing.jpg"));
        items.add(new ListItem("Big shiny thing","c:\\someDir\\shiny.jpg"));
        return items;
    }

    /** This is your data class. It should hold all of the data that you need 
     * to display or work with for each item.
     */
    class ListItem {
        String description;
        String path;

        public ListItem(String description, String path){
            this.description …
Salem commented: Looks good (and shiny) to me. +29
BestJewSinceJC commented: Good advice, I doubt he will take it though. +4
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

>I think there's no one right answer here.
Bingo.
This is the point where design becomes more art than science and you don't really have a set of rules laid out for you. You try to encapsulate functionality and decouple responsibility as best you can given the specifics of your subsystems and requirements. Managing that complexity effectively becomes a career.

Salem commented: Well said, and very true. +29
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

This

java.lang.ArrayIndexOutOfBoundsException: 1

means your code tried to access element index 1 of an array that has less than 2 elements.

This line

HighScoreManager.readHighScores(HighScoreManager.java:22)

shows that it occurred on line 22 of HighScoreManager in the readHighScores method.
So check your array access there.

jollyton12 commented: thanks +3
stephen84s commented: Short and bang on target as usual. +8
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Ok, I had a few minutes to play with the code. The main problem is that you are using java.awt.Label instead of javax.swing.JLabel for the labels in AddRecord. It' not a good idea to mix heavyweight AWT components with Swing components in the same UI. That was causing the problems with painting your menu properly.

Here's some revised code that behaves properly. Note that I put some of the separate classes inside "TheFrame" as inner classes just for my own convenience. You can certainly move them back out.

////// main , the frame ///////
import java.text.MessageFormat;
import java.sql.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.print.*;

public class TheFrame extends JFrame
{
	private JPanel menuPanel;
	private JPanel text;
	private BorderLayout bl = new BorderLayout();


	public TheFrame()
	{

		JLabel one = new JLabel("Java Final Project: Employee Record");
		one.setAlignmentX(0.5f);
		one.setAlignmentY(1f);
		JLabel two = new JLabel("Written by Henry Li");
		two.setAlignmentX(0.5f);
		two.setAlignmentY(1f);

		text = new JPanel();
		text.setBackground(java.awt.Color.white);
		LayoutManager boxLayout = new BoxLayout(text, BoxLayout.Y_AXIS);

		text.setLayout(boxLayout);
		text.add(one);
		text.add(two);

        // add the menu
        createMenu();
        // set close op also
        setDefaultCloseOperation(EXIT_ON_CLOSE);
// don't need
//		add(menuPanel, BorderLayout.NORTH);
		getContentPane().add(text, BorderLayout.CENTER);
		validate();

		setBounds(400, 400, 600, 300);
		setVisible(true);

	}

    // Moved everything from menu panel here
    private void createMenu(){
	 JMenuBar menuBar;
	 JMenu menuFile, menuEdit;
	 JMenuItem closeMenuItem, printMenuItem, showTableMItem, addRecordMItem;

		menuFile = new JMenu("File");           // menu file
		menuFile.setForeground(java.awt.Color.black);
		closeMenuItem = new JMenuItem("Close"); // menu closeItem
		menuFile.add(closeMenuItem);            // menu file with closeItem
		closeMenuItem.setAccelerator(KeyStroke.getKeyStroke('q', java.awt.Event.CTRL_MASK, false));
		closeMenuItem.addActionListener(new closeMenuHandler());


		printMenuItem = new JMenuItem("Print");  // menu printItem
		menuFile.add(printMenuItem);            // menu file with printItem
		printMenuItem.setAccelerator(KeyStroke.getKeyStroke('p', …
BestJewSinceJC commented: Noticing a 'J' missing on JLabel is good stuff. Nice. +3
Salem commented: Nicely done +29
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

We're just a blip in the timescale so far. The dinosaurs were dominant for ~160 million years. The Homo genus only has about 2.5 million under its belt so far and I don't think that I would bet on even seeing 3 million.

jephthah commented: good point. +6
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Are you compiling against java 1.5 or later? Those declarations of Vector are perfectly valid post-1.5. You have other issues with using get(Object) calls that are not valid, but the declarations are fine.

Grn Xtrm commented: Thanks for the help. +1