Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Then read this one as well: http://en.wikipedia.org/wiki/Memory_address

Without understanding what is unclear to you, people are going to have a hard time addressing the question.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

This really has nothing to do with Java and a quick search would have yielded an answer: http://en.wikipedia.org/wiki/32-bit_processor

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Even the Angels in heaven don't know when the end of the world will be. I am sure man doesn't either.. :D

Ah, so they told you that? Personal phone call, letter, or did they text you? Any other wisdom from imaginary beings to relate?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

comjisu33, based on sukatoa's response it looks like your original code was quite different and you edited it after the response. If you make changes to the code, make a new reply with those changes instead of altering the original. After your edits, sukatoa's response seems to make no sense because that code is no longer there. Please leave the integrity of the thread in place so as not to cause confusion.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

This tutorial might provide a starting point on the design: http://www.javacoffeebreak.com/text-adventure/index.html

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Start with a simple tutorial on JTable: http://java.sun.com/docs/books/tutorial/uiswing/components/table.html

(These examples that you keep asking for are incredibly easy to locate with a very simple search. You should take a little initiative to find them before asking others to give them to you.)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

BufferedReader:

try {
    BufferedReader reader = new BufferedReader( new FileReader("yourFile.txt") );
    String line = reader.readLine();
    while (line !=null){
        // do your thing

        line = reader.readLine();
    }
} catch(Exception ex) {
    ex.printStackTrace();
}

String.split()

String lineOfText = "Here is a line of text.";
// splitting on a whitespace character, you could use other delimiters
String[] words = lineOfText.split("\\s");
for(String word : words) {
    System.out.println(word);
}

Those should give you an easy place to start.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Don't use StringTokenizer, use String.split().

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Perhaps she is too embarrassed that her husband stormed in to demand what is going on here.
:P

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, your instructions tell you to use the LinkedBinarySearchTree - so maybe that is a hint? You have read them, right?

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

I don't know what all you are swapping around there after the pause, but basically I was showing that you could swap out the game panel for the sad face panel and then swap them back. Any variations on that will depend on how you have specifically organized your components. Putting those UI changes on the event queue in separate Runnables with

EventQueue.invokeLater(new Runnable(){ ... });

allows the UI to be responsive to repaints, because those are processed on the same thread.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, the only piece of the code you wrote that will be of any use for that assignment at all is the Scanner (though a BufferedReader would be my own choice for that). The instructions are pretty clearly laid out and does tell you what you need to use from that jss2 folder.

You need to read the file line by line. The first line is the input to create the BST. For the rest of the lines you will need to parse and match the command token to the appropriate action to take on the BST. String.split() will be useful for that part to separate <command> <parameters>.

So time to crack the books and get a start on it. Post specific questions if you run into trouble. Good luck!

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I tried what you suggested to no avail. When I remove the static modifiers my IDE lights up like a christmass tree with compile errors, and when I actually run the program it runs but it doesnot store the data. I recieve a print format of count = 1, null, null, 0.00. Any advice?

Of course it shows many errors, because you are also accessing all of them statically in your methods

public void setName1(String name1) {
Employee.name1 = name1;
}

You need to use them as instance variables

public void setName1(String name1) {
this.name1 = name1;
}
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Yes, you need to create a method on the Employee class that uses the info it contains to calculate and return the weekly pay.

Your main() method should create a new Employee with the info that you are getting from the keyboard and then call the calcWeeklyPay() method that you added.

Also note that the variables in your Employee class should not be static, they should be private.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Guess I won't worry too much about Christmas shopping that year.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It's the swap, pause, and replace operations all occurring within a single event on the AWT dispatch thread that is causing your problem. If you want to fiddle with the UI, wait a bit, and then fiddle with it some more you need to spawn a new thread to manage that so the AWT dispatch thread is free to respond to your UI changes.

The following will work, though since you did away with the panel to contain the buttons you will have to remove all of them and add them again. It would be easier to put them back into a panel you could swap out. I'll call it "gamePanel" in the code below

public class ButtonListener implements ActionListener {

    public void actionPerformed(ActionEvent buttonEvent) {
        // start the swap thread
        BoomThread boom = new BoomThread();
        boom.start();

        int answer = JOptionPane.showConfirmDialog(null, "BOOOoooM!!! Would you like to play again?", "", JOptionPane.YES_NO_OPTION);
        // reset or whatever
    }
}

class BoomThread extends Thread {

    public void run() {
        // replace game panel with sad face
        // this queues your update onto the 
        // thread that handles UI events.
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                remove(gamePanel);
                add(sad);
                validate();
                repaint();
            }
        });
        // pause this thread
        try {
            Thread.sleep(3000);
        } catch(InterruptedException e) {
            Thread.currentThread().interrupt();
        }
        // swap game panel back in
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                remove(sad);
                add(gamePanel);
                validate();
                repaint();
            }
        });
    }
}

You will also need to create the "sad" panel in your initialization and have the reference …

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It looks like you are trying to execute that from the command line directly ("java Draw"). Applets cannot be run like that. They need to be embedded in a web page or run through the AppletViewer. You can find more info in the Applet tutorial: http://java.sun.com/docs/books/tutorial/deployment/applet/deployindex.html

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You need the mysql-connector jar in your class path. http://java.sun.com/javase/6/docs/technotes/tools/windows/classpath.html

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, I guess that depends on what you have covered in class so far. My guess would be simple file I/O with a BufferedWriter.

Review your class notes.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It won't work for you like that because you are trying to execute the frame display and the pause all on the AWT event dispatch thread. I'd recommend either swapping out the panel that displays the buttons with the sad face panel or use an icon for the sad face and set the bomb button icon (or the Boom! dialog icon) to that icon - unless you want to get into the threading issues that are preventing that code from working.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Post the "MySadFace" code as well.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Move the code that creates the buttons into the init() method and add the listener after you create the button. Leave the variables at the instance level where you have them, but put the myButton1 = new JButton("1"); part in init() so it only gets executed once.

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

Ok, several small things. In the setupGame() method, after you add the panel to the container, you need to call validate() for it to update it's component layout (this will also cause a repaint so you don't have to worry with that)

add(p1, BorderLayout.CENTER);
validate();

Second, you are setting the background colors on the buttons to white or black in the ActionListeners, but you don't set them back in setupGame(). Those will need to be reset to their default color. Additionally, you add the button listeners to the buttons in setupGame(), which means they get added each time you call that method. If you call it three times you end up with three listeners, all doing the same thing, on the buttons. This means the action will fire three times for a single click - not what you want. Add the listeners to the buttons just once in some other method. Perhaps a setupButtons() method or in init() for the moment.

It might reflect the program flow a little better if you had a setupButtons() method to build the buttons and attach the listeners. You may want a resetButtons method that changes all the background colors back to the start color. Then rename setupGame() to startGame() (yes, I'm picky on naming methods according to exactly what they do). Remove the code that adds the listeners from that code and place a call to resetButtons() before you place the buttons on the panel.

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

You have both DieDisplayInterface and DisplayDieInterface shown there - which is it?

The fact that the confusion arose at all is a clear sign that you should consider a better name for the interface. Is there more than one class that implements the interface? If not, will there be? If both answers are no then you don't even need a separate interface definition.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

That depends entirely on the constructors you have written for DisplayDie and DisplayPanel.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Like I said - it depends on your initialization code. There is not anything like a "reset()" method. You simply set your panels and controls back to whatever state they should have at the beginning of your game. If you post the code for "myFrame" we may be able to offer some more specific advice.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It doesn't need to be reloaded - it just needs to be reset. How to do that depends upon how you have structured the code that initializes it.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The demo class needs to create "Ages" objects and use the methods you have defined. As written your demo just defines some variables and prints the "avgAge" - which is still 0 because you haven't done anything with it.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The file just needs to be inserted as a blob data type if you wish to store it directly in the database. You can find an example of using JDBC to store a Blob here: http://www.java2s.com/Code/Java/Database-SQL-JDBC/BlobJDBCdealswithBinaryData.htm

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Your question is too vague. By "upload" do you mean with a JSP page or from a desktop Java application? (This is the Java forum by the way. There is a separate JSP forum here:http://www.daniweb.com/forums/forum24.html)

Without more information no one can really help you.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, most of the site is for technical discussions and problem solving. The "lounge" forums are just informal places for idle chatter. There certainly are not any "adult-only" type areas on the site, so beyond just chatting with people there isn't really much else to it.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Which method are you wanting to pass an object to? "idMethod" is getting a no-arg method and "getMethod" is getting this method getInstance(String) with this line

Method getMethod = Class.forName(ClassName).getMethod("getInstance", new Class[]{Class.forName("java.lang.String")});

. If you need getInstance(Object) the you need to use

Method getMethod = Class.forName(ClassName).getMethod("getInstance", new Class[]{java.lang.Object.class});

Your question is not very clear, so if that is not what you were asking you will need to clarify it a bit more.

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

It would help a lot if you either used [code=java], which would place line numbers in the listing or highlighted the line number in your code, since most can't just quickly pick out line 174. Here is that code with line numbers:

I can't figure out why it is saying (Vehicle.java:174: cannot find symbol) but there is a symbol, what is going on?

import java.util.Scanner;


public class Vehicle{
protected int hp;
protected int mileage;
protected int year;
public String make;
public String model;

Vehicle(){
hp = 0;
mileage = 0;
year = 0;
}

public void Set(int inputhp, int inputmileage, int inputyear){
hp = inputhp;
mileage = inputmileage;
year = inputyear;
}

//public static void Print(int hp, int mileage, int year){
/*
public  void Print(Vehicle carinfo){

System.out.println("Horsepower: " + carinfo.hp + "\n Mileage: " + carinfo.mileage + "\n Year: " + carinfo.year +
"\n Make: " + carinfo.make + "\n Model: " + carinfo.model);
}
*/



public  void Print(){

System.out.println("Horsepower: " + hp + "\n Mileage: " + mileage + "\n Year: " + year +
"\n Make: " + make + "\n Model: " + model);
}

/*public static void CheckYear(int year, Vehicle carinfo, int i, int yearcheck){

int count = 0;
for(i = 0; i < 1; i++){

if(yearcheck = carinfo[i].year){
System.out.println("The year inputed matches a " + carinfo.year + " " + carinfo.make + " " + carinfo.model + " in our database.");
count++;
										}
												}
												if(count = 0){
												System.out.println("There were no matches of that year");
												} …
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Because your toString() method is not returning a string, it's just printing stuff out to the console. It needs to build a string and return it.

Also, after 18 posts, you should learn to use [code] [/code] tags around code that you post.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You can do it with a custom cell renderer like so:

class CustomIconRenderer extends DefaultTreeCellRenderer {
    ImageIcon defaultIcon;
    ImageIcon specialIcon;

    public CustomIconRenderer() {
        defaultIcon = new ImageIcon(CustomIconRenderer.class.getResource("/images/defaultIcon.gif"));
        specialIcon = new ImageIcon(CustomIconRenderer.class.getResource("/images/specialIcon.gif"));
    }

    public Component getTreeCellRendererComponent(JTree tree,
      Object value,boolean sel,boolean expanded,boolean leaf,
      int row,boolean hasFocus) {

        super.getTreeCellRendererComponent(tree, value, sel, 
          expanded, leaf, row, hasFocus);

        Object nodeObj = ((DefaultMutableTreeNode)value).getUserObject();
        // check whatever you need to on the node user object
        if (((WhateverNodeObjectClass)nodeObj).someProperty) {
            setIcon(specialIcon);
        } else {
            setIcon(defaultIcon);
        } 
        return this;
    }
}
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

Each panel can keep all of it's layout setup completely internal (and should). The code that puts together the main frame should place the panels wherever they need to go.

Edit: Fireworks panel can still have as many internal panels as it wants to group components together. The main frame can still just treat it as a single component. If FireworksPanel has two internal panels, one for the screen and one for buttons, that won't affect the main frame at all. You don't have to put each piece into the frame - panels can have panels within panels within panels ad nauseum, so don't think each piece has to go into the top level container.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Maybe something along these lines would work for you

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

public class FrameExample extends JFrame {

    JPanel panNorth;
    JPanel panSouth;
    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 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);

        // set up bottom panel
        panSouth = new JPanel();
        panSouth.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
        panSouth.setLayout(new FlowLayout());
        JButton btnFirst = new JButton("Button 1");
        // if preferred size is not set then the button will size to fit the text on it
        btnFirst.setPreferredSize(new Dimension(100,18));
        panSouth.add(btnFirst);
        JButton btnSecond = new JButton("Button 2");
        btnSecond.setPreferredSize(new Dimension(100,18));
        panSouth.add(btnSecond);
        add(panSouth, BorderLayout.SOUTH);

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

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

You can probably use a BorderLayout for the main frame with your main panel in CENTER and a button panel in SOUTH. The button panel could use FlowLayout or GridLayout perhaps. Neither of those is too complex.

GridBagLayout would be more flexible, but it can take a little work to get comfortable with it.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

This tutorial has examples of working with the available layout managers: http://java.sun.com/docs/books/tutorial/uiswing/layout/index.html

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Too late to edit the previous. You're right, it makes no difference for primitives :)
I never worried about it enough with primitives to get a "final answer".

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Actually, the space for the variables is allocated at the "method" level. So, declaring a variable before the loop, or in the loop, has no additional effect what-so-ever. ;-)

The part that I haven't found a definitive answer on is whether that space is re-initialized if the declaration is within the loop. Many older tips on tuning recommend declaring the variable before the loop rather than inside it, but I think more recent compilers will make that optimization on their own. Out of habit, I usually declare such variables just prior to the loop regardless.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

So, readability aside, it is more efficient to do a fairly simple calculation two or three times than to store the result?

No, in all likelihood it is not, though allocating such variables in loops can lead to excess GC activity - and even in that case there is a good chance the JIT compiler will re-use a single reference instead of creating a new one each time anyway unless subsequent assignments make that impossible. The short answer is store the calculation in a local variable.

The code in question is going to be called every time the paintComponent method is called on a particular JPanel. So far, it refreshes instantaneously. However, I still have a lot of code to add, and I would like to keep things as efficient as possible, even at the loss of readability.

This is premature optimization at the level you are examining it. The best guideline for tuning painting code is to try to minimize the calculations needed to render. Repaints can occur for many events besides the ones that you are generating in your own code. Updating the variables, either primitives or objects, in the methods that alter them (such as a mouse listener, animation loop, button listener, etc) and letting paint code use those variables is your best choice.

Finishing the code to work correctly with a clean and clear design is much more important at your current stage than worrying about milliseconds of optimization. If you find you do …

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The general guideline is to write the code in the clearest, most effective way and worry about optimization only if poor overall performance and code profiling warrant changing it.

That said, if you're using the result of a calculation more than once you should probably store it into a variable for consistency and clarity. If that calculation needs to be performed more than one or two times or in different contexts, move it into a method of it's own.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If you are using java 1.5 or above, the java.awt.Container class (which pretty much every Swing UI component extends from in it's hierarchy) has a method setComponentZOrder(java.awt.Component, int) that you can use for this.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Your question is not clear. Perhaps if you restate it with a little more detail it would help.