Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Changing that code to use getClass().getResource() works perfectly on my machine. Attaching the revised jar (I had to put it in a zip file since it won't allow me to attach a .jar)

TheWhite commented: tank you! +1
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Use getResource() to load the images instead of the simple path

ImageIcon qmarkIcon = new ImageIcon(getClass().getResource("images/mark.gif"));

More info on this here if you want to understand the nuances: http://java.sun.com/docs/books/tutorial/uiswing/components/icon.html#getresource

majestic0110 commented: Know it all lol! Great help! +2
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

This one has really gotten too long by now. Most aren't going to review the other 142 pages if they do respond. A new thread for a new discussion is probably better.

~s.o.s~ commented: Absolutely! +21
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Bleh, got back to this thread just a little too late I guess, but perhaps you will still see this post.

If you wish to organize the UI sections in a more modular and manageable way, you might consider this arrangement

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

public class Interface extends JFrame {

    public Interface() {
        displayMenu();
        setSize(600, 500);
        setVisible(true);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
    }

    public void displayMenu() {
        setTitle("Mp3 database: Please select Function");
        Container pane = getContentPane();
        pane.removeAll();
        pane.add(new MenuPanel(this));

        pane.validate();
        pane.repaint();
    }

    public void addNewSong() {
        setTitle("Enter Song Info");
        Container pane = getContentPane();
        pane.removeAll();
        pane.add(new SongDataPanel(this));
        pane.validate();
        pane.repaint();
    }

    /** Main menu UI */
    private class MenuPanel extends JPanel {

        private Interface programFrame;
        private JButton newSongB, exitB, deleteSongB, playlistB, searchB;
        private NewSongButtonHandler nsHandler;
        private DeleteSongButtonHandler dsHandler;
        private PlaylistButtonHandler plHandler;
        private SearchButtonHandler sbHandler;
        private ExitButtonHandler ebHandler;

        public MenuPanel(Interface programFrame) {
            super();
            this.programFrame = programFrame;

            setLayout(new GridLayout(5, 0));

            newSongB = new JButton("Enter New Song");
            nsHandler = new NewSongButtonHandler();
            newSongB.addActionListener(nsHandler);
            add(newSongB);

            deleteSongB = new JButton("Delete Song");
            dsHandler = new DeleteSongButtonHandler();
            deleteSongB.addActionListener(dsHandler);
            add(deleteSongB);

            playlistB = new JButton("Playlist");
            plHandler = new PlaylistButtonHandler();
            playlistB.addActionListener(plHandler);
            add(playlistB);

            searchB = new JButton("Search Database");
            sbHandler = new SearchButtonHandler();
            searchB.addActionListener(sbHandler);
            add(searchB);

            exitB = new JButton("Exit");
            ebHandler = new ExitButtonHandler();
            exitB.addActionListener(ebHandler);
            add(exitB);

        }

        private class NewSongButtonHandler implements ActionListener {

            public void actionPerformed(ActionEvent e) {
                programFrame.addNewSong();
            }
        }

        private class DeleteSongButtonHandler implements ActionListener {

            public void actionPerformed(ActionEvent e) {
            }
        }

        private class PlaylistButtonHandler implements ActionListener {

            public void actionPerformed(ActionEvent e) {
            }
        }

        private class SearchButtonHandler implements ActionListener {

            public void …
peter_budo commented: Beautiful work as always +7
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I tried

remove(myButton);

but it says that the the method remove JButton is undefined for the type Runnable

This error is likely a result of where you located the inner class BoomThread. Inner classes have access to the methods of their enclosing class, so if it were in the class extending Frame it would be able to call that method.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You just used the wrong method call for the Frame sizing - easy to fix. setSize() will take either a (width,height) or a Dimension argument. There is another method setBounds() that takes (x,y,width,height), which is probably the one you are trying to use.

darkagn commented: As always your advice is good :) +1
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Hi guys...

This is a petition against the live skinning of cats,dogs and other animals in China.

Of course it's live skinning - the dead have a hard time handling knives.

Please be aware if you click on the video it is VERY GRAPHIC - the most disturbing,graphic video ever

Ever? or EVVAAAARR?

Please take a few minutes and help try to make a difference.....

I could see helping to make a difference or trying to make a difference, but to "help try" seems rather lame... like the petition itself.

Thank you and god bless all

Not garnering much support from the atheist corner here. ;)

scru commented: Not ganerning support from the Cristian corner either. He didn't captialise "God". +3
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

As far as managing the entire game state, here are some things to consider that would make it much easier on you if you wish to tackle them.

1) Use an array for all of the buttons

JButton[] buttons;

Your setup code just needs to loop that array and create a new button for each element.

2) You only need one button listener for all of the buttons. The only part of the code that differs is the response for a bomb or a win.

public class ButtonListener implements ActionListener {
        public void actionPerformed(ActionEvent e) {
            boolean gameOver = false;
            JButton clickedButton = (JButton)e.getSource();
            if(clickedButton==bombButton) {
                // you got the bomb - see #3 on this
                ...
                gameOver = true;
            } else { // for you to figure out

The part for you figure out is how to tell a win. Hint: The number of plays (button clicks) will equal the number of buttons if you only count clicks on buttons that haven't been played before.

3) A single reference for the current bomb button. Since you have all of the buttons in an array, you can choose a random number against the array length and assign that button to a reference for that game

JButton bombButton;

On a new game, choose a new random array index and set the bombButton to that button.

bombButton = buttons[ yourRandomInt ];

If you do those things, you don't have to randomize the actual buttons at …

jasimp commented: You are the main source of accurate help in the Java forum +6
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

All of this portion could go into a method called setupGame()

JPanel p1 = new JPanel(new GridLayout(3, 3));
		int randomNumber = (int)(Math.random()*9)+1;
		
		if(randomNumber == 1){
			p1.add(myButton1);
			p1.add(myButton2);
			p1.add(myButton3);
			p1.add(myButton4);
			p1.add(myButton5);
			p1.add(myButton6);
			p1.add(myButton7);
			p1.add(myButton8);
			p1.add(myButton9);
		}
		
		if(randomNumber == 2){
			p1.add(myButton2);
			p1.add(myButton1);
			p1.add(myButton3);
			p1.add(myButton4);
			p1.add(myButton5);
			p1.add(myButton6);
			p1.add(myButton7);
			p1.add(myButton8);
			p1.add(myButton9);
		}
		
		add(p1, BorderLayout.CENTER);
		
		myButton1.addActionListener(new ButtonListener1());
		myButton2.addActionListener(new ButtonListener2());

Keep an instance-level reference to the panel which is to contain the buttons. Before the statement that creates the panel, place a call to remove that panel first like so

if (gamePanel != null){
          remove(gamePanel);
      }
      gamePanel = new JPanel(new GridLayout(3, 3));

(Yes, I renamed the panel "gamePanel" because "p1" means absolutely nothing. Use meaningful names for variables so you remember what they are for.)

As for the button code, they really could share the same listener since they do the same thing. Also, you can just create an array of JButton[] to hold them and randomize the index selection to place them on the screen instead of hard-coding all of that.

majestic0110 commented: This guy is the best! +2
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The row must be added to the TableModel, not the JTable as you are attempting. In particular, that method is provided by DefaultTableModel and is not in the general TableModel interface, so you will either need to keep a reference to the DefaultTableModel that you are creating

DefaultTableModel tableModel = new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null},
{null, null}
},
new String [] {
"Kode group", "Nama group"
});  // plus all of your other extension code of course
tblGroupAnggaran.setModel(tableModel);

(though that reference will actually need to be an instance-level reference, not local as in this example) or get the model from the table and cast it to DefaultTableModel

((DefaultTableModel)tblGroupAnggaran.getModel()).addRow(data);

I would also recommend making your DefaultTableModel extension it's own separate inner class. It would be much easier to read and maintain over the anonymous inner class you are currently using.

Kusno commented: Clear explanations +1
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Use "Case Else":

Select Case Me.Text1.Text
    Case 1
        MsgBox ("U Entered 1")
    Case 2
        MsgBox ("U entered 2")
    Case 3
        MsgBox ("u entered 3")
    Case Else
        MsgBox ("Default")
End Select
sujimon commented: useful +1
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

First you'll want to get a BufferedImage object for the input image. Example code for this here: http://exampledepot.com/egs/java.awt.image/Image2Buf.html?l=rel

BufferedImage will allow you to access the grid of pixels (http://exampledepot.com/egs/java.awt.image/ImagePixel.html?l=rel). You may be able to apply a thresholding function to the pixels to create an array map of the identified paths, perhaps just a binary mapping 0 or 1 to mark available paths.

From there, apply your pathfinding algorithm to the binary map and update the corresponding pixel values on the BufferedImage based upon the desired path and then save it back out to a new file (saving: http://www.exampledepot.com/egs/javax.imageio/Graphic2File.html)

Good luck!

darkagn commented: Really good explanation :) +1
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

This should give you a pretty good idea on how to set them up.

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import javax.swing.*;

public class FrameExample extends JFrame {

    JPanel panNorth;
    JPanel panWest;
    JPanel panCenter;

    public FrameExample() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        setLayout(new BorderLayout());

        // set up top panel
        panNorth = new JPanel();
        panNorth.setLayout(new FlowLayout());
        panNorth.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
        JLabel lblUpper = new JLabel("Upper Panel");
        panNorth.add(lblUpper);
        add(panNorth, BorderLayout.NORTH);

        // set up left panel
        panWest = new JPanel();
        panWest.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
        panWest.setLayout(new GridLayout(2, 1));
        JButton btnFirst = new JButton("First");
        panWest.add(btnFirst);
        JButton btnSecond = new JButton("Second");
        panWest.add(btnSecond);
        add(panWest, BorderLayout.WEST);

        // set up center panel
        panCenter = new JPanel();
        panCenter.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
        panCenter.setLayout(new BorderLayout());
        JLabel lblMiddle = new JLabel("Middle thing");
        lblMiddle.setHorizontalAlignment(JLabel.CENTER);
        panCenter.add(lblMiddle, BorderLayout.CENTER);
        add(panCenter);

        setSize(300, 300);
        setVisible(true);
    }

    public static void main(String args[]) {
        new FrameExample();
    }
}
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Just use a BufferedReader for the read. Example here: http://www.exampledepot.com/egs/java.io/ReadLinesFromFile.html

jasimp commented: tirelessly helping those that need it in the java forum +6
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Multiplying at those magnitudes are putting you beyond the precision of double. Use BigDecimal instead.

double a = 1.190597027811988E-273;
double b = -2.513498651481222E-273;
System.out.println("double: "+(a*b));
// double: -0.0

BigDecimal c = new BigDecimal(a);
BigDecimal d = new BigDecimal(b);
System.out.println("BigDecimal: "+new DecimalFormat("0.#######E0").format(c.multiply(d)));
// BigDecimal: -2.992564E-546
majestic0110 commented: A great poster, always helpful +2
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You might want to take a look at the free online book Thinking In Java, 3rd Edition. It is a bit dated since it doesn't cover any of the Java 1.5 or 1.6 changes, but the language basics are still solid and you'd probably find it a good reference for questions like this.
If you prefer an offline copy, you can download it as a PDF here: http://mindview.net/Books/TIJ/DownloadSites

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

...I am using the java.awt.Graphics.drawString and drawImage methods to draw each part of my object. If I have set my graphics component's font to have a size of 12 say, does this mean that each character takes up 12 x 12 pixels?

No, it's a little more complicated than that, but still easily available. You'll need to call Graphics.getFontMetrics() to obtain the font metrics for the current font. FontMetrics provides methods for obtaining dimensions of a particular string for that font and graphics context, such as getHeight() and stringWidth(java.lang.String). That should be all you need to center up any given string on your image.

Edit: You can find more detailed info on FontMetrics and handling text in the graphics context if you need it in the 2D graphics tutorial: http://java.sun.com/docs/books/tutorial/2d/text/measuringtext.html

darkagn commented: Thanks for the tips :) +1
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, you don't say what labels you are having trouble updating, but some things really stand out as a problem. In your constructor

JPanel playerpan = new JPanel();

You're defining this as a local variable - not initializing your class level "playerpan" variable. Same with the other panels. This means that you essentially have no reference to those panels outside the constructor. Aside from that, why does player extend JPanel but refer to components in the enclosing class? The only variables in "player" are two strings. This is a rather odd tangle of component classes.

As for the label update, this is most likely due to this line in your button handler

player update = new player();

You are creating a new separate "player" instance and calling the update method on it - not the one that you actually added to your JFrame.

toomuchfreetime commented: Great help thanks a lot!! +2
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

StringTokenizer is considered a legacy class now and it is recommended to use String.split(java.lang.String) or the java.util.regex classes for this now.

With split() you could first split on the math operator, giving you the two operand strings, and then spilt those into the whole and fractional strings, and then split the fractional into it's numerator and denominator. The one issue you may face doing that is your fraction separator "/" is the same as the division operator "/". If you can be certain that the operator will have blank spaces on both sides, it becomes much easier.

Give that a try and see how it goes. Even if you must use StringTokenizer due to some professor insisting you use legacy classes (does he know it's a legacy class?), still it may help if you consider that you don't have to parse the string in one shot from left to right. You can parse it into separate pieces and then parse those pieces into other pieces and so on, which can make the problem much cleaner to approach.

darkagn commented: good tip +1
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Some (most) design patterns in Java are done for getting around the inherent limitations of the language. Java tends to make a big deal out of little things. Many other languages don't need them (or don't consider them anything worthy of being called a fruity name). But some basic universal patterns (like the interpreted utility language pattern ^_^) are seen elsewhere.

Oh, and that is the reason the canonical GoF Design Patterns book used C++ and SmallTalk for their examples? To present patterns to work around limitations in Java? Sure, that makes sense.

The book was published in 1994. Java was released in 1995.

~s.o.s~ commented: Bingo! +20
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster
double d = 32.456;
System.out.println( (int)d );
System.out.println( d-(int)d );
peter_budo commented: Somebody please give him something complex, he is getting borred... ;) +7
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

See comments in the code

import java.awt.*;
import java.awt.event.*;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.*;

public class HeartLandHomeFinance2 extends JFrame {

    JPanel Panel;
    JLabel lb1, lb2, lb3, lb4, lb5, lb6, lb7, lb8, lb9, lb10, lb11, lb12, lb13, lb14,
      lb15, lb16, lb17, lb18, lb19, lb20, lb21, lb22, lb23, heading, lb24;
    JTextField jt1, jt2, jt3, jt4, jt5, jt6, jt7, jt8, jt9, jt10, jt11, jt12, jt13, jt14, jt15, jt16, jt18, jt17;
    JButton bt1, bt2;
    GridBagLayout gb;
    JScrollPane jscrollpane;
    GridBagConstraints gbc;
    JComboBox combo1, combo2, combo3, combo4, combo5, combo6;
    Connection con;
    PreparedStatement stat;
    Statement stmt;
    ResultSet rs;
    Font f;

    // this constructor was not valid - constructors don't have a return type
    // explicitlly stated, because they always return an instance of the class
    public HeartLandHomeFinance2() {
        // you don't need a new Frame here
        // your class is a JFrame
        // I moved the frame calls into createAndShowGUI() as well
        createAndShowGUI();
    }

    public void createAndShowGUI() {
        setTitle("Heart Land Home Finance");
        setDefaultLookAndFeelDecorated(true);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        
        Container contentPane = getContentPane();
        // you have to initialize gb before you make the setLayout call
        // you were using a null layout because gb was null
        gb = new GridBagLayout();

        Panel = new JPanel();
        Panel.setLayout(gb);
        Panel.setBackground(Color.RED);

        gbc = new GridBagConstraints();

        f = new Font("Monospaced", Font.BOLD, 24);
        gbc.gridx = 1;
        gbc.gridy = 0;
        gbc.gridwidth = 3;

        heading = new JLabel("Heart Land Home Finance");
        heading.setForeground(Color.black);
        heading.setFont(f);
        Panel.add(heading, gbc);

        gbc.gridx = 0;
        gbc.gridy = 1;
        gbc.gridwidth = 5;

        lb1 = new JLabel("Please Fill All The Fields in CAPITAL LETTERS"); …
tactfulsaint commented: your gud +1
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You should update the image, repaint, and sleep in a separate thread or a Swing Timer. This animation tutorial might help:http://www.developer.com/java/article.php/893471
The important concept is that the AWT Event Queue needs to be allowed to repaint after you have altered the image.

CaffeineCoder commented: Very helpful, has good information to contribute. +1
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You can do this easily with a Timer.

tactfulsaint commented: Your The Best +1
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, you know that the rank will be 1 or 2 characters. The suit will always be a single character at the end. Using the substring() and length() methods of String, you should be able to separate the string easily into the two portions that you need.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Yoga is the answer.

And the real trick is finding the question...

~s.o.s~ commented: Haha :-) +20
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I consider being called "a despised cocky kid" and insult! Watch your poor manners!

Perhaps you should consider your own. They aren't exactly shining here.

Sulley's Boo commented: :D +4
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster
public class Card
{
[B]getSuit();  // These are invalid calls - you cannot do this here
getRank();[/B]

[B]// you have not declared rank and suit member variables

// you can have a static array for the rank values here and initialize it with 
// a static block.[/B]

publlic Card(int rankNum, String suit)
{
      [B] // this won't really do anything for you at all and will
       // not compile because rank is not defined[/B]
       for (int i=1; i<14; i++)
       {
      rank = Integer.toString(i);

      }

     [B] // with the static rank value array you can assign the value of the rank string
      // with a simple array lookup
      // rank = rankValues[ rankNum ];[/B]
     
}

public String getSuit()
{
[B]// just needs to return the suit string - no array here[/B]
String  suit [4]={"spades","hearts","diamonds","clubs"};
return suit;
}

public String getRank()
{
[B]// Same here - return rank - no array needed here[/B]
String  suit [13]={"ACE","2","3","4","5","6","7","8","9","10","Jack","Queen","King"};
return rank;
}
piers commented: you have helped me a lot with java thnx +1
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You cannot declare a method within a method like that, which is what this line is trying to do

public void actionPerformed_Plus()
nljavaingineur commented: Promply helpful +1
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, which one has no context without the other? Does a listener have any useful function without a GUI? What about the GUI? It seems to me the GUI can exist without a listener, but it just won't do much until it has one. So you could create the GUI and then create the listener passing a reference to the GUI.

On the other hand, if your listener is really a dispatcher, which it kind of appears to be, it can exist and function without anything to pass message along to - it just ends up trying to send a message to an empty list until receivers register.

Consider also that maybe you don't really need those classes to be explicit singletons. They may only ever have one instance in the context of your app, but that doesn't mean it has to be enforced by the class design. Singletons can cause a lot of headaches down the road if you aren't absolutely certain of their singularity.

darkagn commented: Good explanation :) +1
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It's possible to lead a cow upstairs, but not downstairs.

I pity the person who verifies that one. No one wants a whole bunch of cows upstairs :(

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Actually, they'll believe anything printed shoved in front of their noses and never bother to conduct even the slightest bit of independent research.

I believe you.
...

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

people who hate people who hate rap.

rap/hip-hop = anoying

country + rap = crap

So

annoying = (crap - country) / hip-hop

and

crap = country + (annoying * hip-hop)

and

(country + (annoying * hip-hop)) / crap = unity

... interesting.

~s.o.s~ commented: Heh +20
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Even so, the same idea applies to both situations. I personally believe there is nothing wrong with pirating, and so I will continue to pirate despite what the law or the government says. Besides, I am not stealing anything. All I do is download stuff from people who give it out. I do not upload anything, and therefore I am not breaking any copyright laws. How am I to know that the program I am downloading is not legit? I am simply an innocent bystander in this whole mess.. :P

Actually, yeah. What do insurance companies do after a police investigation of a burglary reveals that the owners didn't lock up? The owners get NO compensation whatsoever (in most cases). It's the same thing with software. If you do not make it safe enough to be released, then you have not done your job properly.. and thus I shouldn't have to pay. If you don't lock up, then you deserve to be robbed!

What a load of crap. You can justify it to yourself all you want to. You're stealing, plain and simple. If you have no moral qualms with it, then that's up to you I suppose. No one here can make you believe stealing is wrong. But you are taking for free something that someone spent a lot of time producing and denying them any compensation - no different than if your employer decided to not give you your paycheck because he simply didn't feel like it.

Ancient Dragon commented: Exactly right. +21
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

JInput can be used for other input devices: https://jinput.dev.java.net/

This article discusses using it for a gamepad: http://fivedots.coe.psu.ac.th/~ad/jg2/ch11/index.html

darkagn commented: great links! +1
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It's getting closer, but it looks like you are still a little bit confused on using methods and classes. I think it we rename a few things it will clarify their intent.

Class names are usually nouns, because they represent "things". Let's rename the DrawImage class to ImagePanel, because that is what it actually is: a panel that shows an image. DrawImage sounds a bit like a method that would draw an image and is a little misleading.

Method names should be verbs, because they represent actions you wish to take. Methods "do "stuff", so we name them to clearly indicate what they do. So let's rename the imageLoader() method to loadImage() or perhaps getImage(). It's now clear that we are performing an action to load an image when we call that method. Let's also move the method into the ImagePanel class since that is the "thing" that really needs to load an image. The PhoneInterface doesn't need to load an image itself and shouldn't have to worry about what the image panel needs to do for itself. That's why we create separate classes in the first place: to group together specific pieces of functionality with clearly defined roles and responsibilities. One class should keep out of other classes' business as much as possible.

So now we have an ImagePanel that has a method to load an image from a file. The ImagePanel has a variable to hold that image so it can paint it whenever it …

darkagn commented: Great explanation of methods and classes, Ezz +1
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Hi Ezzaral, Frederik, all,

I don't think I can use the getImage() method as I have to use swing to build my interface. So getImage() isn't defined for my ImageLoader class, as it is a child of JFrame. Any other ideas??

You can add any method you like to ImageLoader - it's your own creation. The entire reason for extending a class is to add additional functionality to it. That said, I still don't see why ImageLoader should extend JFrame for that matter. What does image loading have to do with a frame, especially if you are using it to load an image to place into a different panel class?

Using Swing for your application in no way implies that every one of your classes needs to extend a Swing component. Most of your classes will be dedicated to handling state and behavior that is completely independent of a visual presentation component.

Is ImageLoader supposed to do anything except get an image from a file? If not, then it really doesn't even need to be a class at all. Just make it a method in your other class that returns an Image for a given file name parameter.

g_loughnan commented: Helpful! +1
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If you take a look in your JDK installation folder under "demo\jfc\TableExample", there are several table example programs, including a TableSorter.

I've also attached a zip file containing a JSortTable implementation from Java Pro magazine. I was going to link to it in the archives, but it seems Java Pro got swallowed up by another company and I can't locate the archives.

Edit: Oops, guess you found something hehe. Didn't know they had rolled that into the api in 1.6.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Just randomized the sign of the speed as well.

-1 + (Math.random() * 2)

or something like that should do it. Whatever you want your neg range to start at and then add random() times twice the speed range.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Perhaps some of the info in this post might help:
http://forum.java.sun.com/thread.jspa?threadID=5137992&messageID=9506454

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Everyone working with Java should take the time to read the Java coding conventions published by Sun: http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html
Coding to the common conventions will ensure a consistency that greatly aids both the coder and others reading that code.

Anyone designing programs that involve more than one or two classes could benefit from familiarizing themselves with design patterns. An excellent introduction to this is Head First Design Patterns. Design patterns may or may not be appropriate for a given application, but learning about them and their usage will teach you to look at your program organization in a more critical manner from perspectives that you may not have considered at the outset.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Yes, EatDot() needs to be called before repaint() in your KeyAdapter to evaluate if a dot is eaten.

Also, your collision function in EatDot() needs to check the absolute value of the coordinate differences

if ((Math.abs(xcoords - dot[i].x) <= 5) && ((Math.abs(ycoords - dot[i].y) <=5)) && !dot[i].isEaten()) {

and lastly you need to reevaluate your offsets from xcoords and ycoords in your placement and drawing of the pacman arc. Offsetting -50 from x and y are causing your pacman to be drawn in the wrong location relative to xcoords and ycoords values you are checking against the dot coordinates.

You are close. You just need to check your relative coordinate and bounding box usage to fine tune it.

You might want to also use an ArrayList for the Dots instead of a fixed 1000 element array and remove a dot when it is eaten, rather than leaving it in an array and continuing to check it after it's long gone.

darkagn commented: Good points all +1
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

And btnA2 is not displaying "pic"? Or are you expecting btnA1 to no longer show that pic as well?

Black Box commented: Just because you deserve it too :) Helping out new people can sometimes be a pain. :p +1
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It depends on how you need to access the data, but I would imagine the simple file would suffice. You don't mention what the data is, but basically you have the equivalent of a single table. With file-based storage you will need to write the methods yourself if you want to query the data in any manner. If such queries are straightforward, such as just finding a couple entries based on simple criteria, you really don't need the database.

That said, if you expect to grow to have several other tables of information and will need to correlate information between them in a variety of ways, you should go ahead and start with a database.

McKoi and H2 are a couple of good open-source Java embedded databases (they don't need a separate installation on a server) if you decide you want to use the database.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Here is a small example with a view controller. The two view classes defined have essentially the same code here (which you would never want to code into a real app), but since they just represent your other two frames I made them separate for clarity of the example.

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashMap;
import javax.swing.JButton;
import javax.swing.JFrame;

public class FrameExample {
        
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                Controller viewController = new Controller();
                MainView main = new MainView(viewController);
                DetailView detail = new DetailView(viewController);
                viewController.showView("Main");
            }
        });
    }
    
    static class Controller {
        HashMap<String,JFrame> views;
        
        public Controller(){
            views = new HashMap<String,JFrame>();
        }
        
        public void registerView(String name, JFrame view){
            views.put(name,view);
        }
        
        public void showView(String name){
            if (views.containsKey(name)){
                for (String key : views.keySet()){
                    views.get(key).setVisible(key.equals(name));
                }
            }
        }
    }
    
    static class MainView extends JFrame {
        final Controller viewController;
        
        public MainView(Controller controller){
            super();
            this.viewController = controller;
            
            setTitle("Main");
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            
            getContentPane().setLayout(new BorderLayout());
            JButton button = new JButton("Show Detail");
            button.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    viewController.showView("Detail");
                }
            });
            getContentPane().add(button, BorderLayout.SOUTH);
            pack();
            setSize(200,200);
            viewController.registerView(getTitle(), this);
        }
    }
    
    static class DetailView extends JFrame {
        final Controller viewController;
        
        public DetailView(Controller controller){
            super();
            this.viewController = controller;
            
            setTitle("Detail");
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            
            getContentPane().setLayout(new BorderLayout());
            JButton button = new JButton("Show Main");
            button.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    viewController.showView("Main");
                }
            });
            getContentPane().add(button, BorderLayout.SOUTH);
            pack();
            setSize(200,200);
            
            viewController.registerView(getTitle(), this);
        }
    }    
}

This in itself is still probably not a solution to your needs, but without any more information on the relationship between your …

peter_budo commented: Nice example, what more can I say :) +6
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

One more very handy site for code snippet examples on many things:
Java Examples from The Java Developers Almanac 1.4

emaan.gseo1 commented: nice post +0
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You just have the boolean values reversed in the conditions

if ( numerator != -99) {
                    int result = quotient( numerator, denominator );
                    System.out.printf( "\nResult: %d / %d = %d\n", numerator,
                      denominator, result );
                    //continueLoop = true;   don't even need this one
                } else {
                    continueLoop = false;  // set to false if -99
                }
DeadJustice commented: Thanks again! +1
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

They can be useful as small data structures or "helper" objects that only have applicability in the context of their enclosing class. S.O.S. posted an example of such a case above. The 'Entry' is really only useful with the HashMap. It could be published as a full public class, but if it is not used by other classes then it just clutters the API. As a static inner class of HashMap, its usage is clearly scoped.

Jishnu commented: This was helpful. +2
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Heh, Heh - welcome to posting twit-hood.

He achieved that status on his first post. Those following were merely additional cement.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

>these programming languages would be like everyday english
I don't see why this would be some great advantage to make programming more accessible. Most people can't use "everyday English" properly either.

Salem commented: Got that right! +13