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

Thank u for helping me.
I knew this is sorting , but I didn't know how we wrote it .

Can u explain for me that, please?

Thank u.

You have the code right in front of you, just read it. Trace the loops if necessary to see how the elements are being compared and sorted. Add more println output to show you what is going on in the inner loop. You'll learn more if you walk through and understand it on your own.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

He does want to learn OO. He was saying he has had a little experience in programming but nothing OO before.

Ah, my bad, sorry. I misread it.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Hello everyone,
I was wondering what a good book to start learning Java would be. I know a little about programming like variables, function, etc. , but not object-oriented stuff. I was thinking of buying Learning Java, 3rd Edition, but I'm not sure. What do you think is the best book for me:icon_question:

You can't learn Java to any useful degree and not learn "object-oriented stuff". Java IS object-oriented and the entire API is built upon that. You won't get beyond anything trivial in the language without some understanding of OO concepts.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Coding every little thing from scratch is useful when learning the language. When you are employed developing an application with 800+ classes, anything that saves time is very beneficial. Things such as code completion, auto-generation of getters/setters and overriding methods, automated refactoring, GUI builders, debugging and profiling tools, and many more. At that level, it's a matter of productivity and if you aren't using the tools available then you're wasting time.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I use Netbeans. Eclipse is just fine as well, but I never really took to the Perspectives thing. Also, ctrl-k for word completion is very addictive for a lazy typist like me :)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Clearly, I have a great deal to learn about Java programming.

A working programmer doesn't ever stop learning :)

Two books that might help you get from Fortran to Java easier are Head First Java and Head First Design Patterns.
Object-oriented programming is quite a different beast than procedural Fortran.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Just to be clear, the "Java" = J2SE right?

Generally speaking, yes.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You still don't show the Circle or Triangle code, which contain the slowMoveVertical(int) code you are calling.

(And your attitude isn't going to garner an overwhelming desire to help out on this.)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

A general suggestion would be to encapsulate postional info in the objects, put the code to update positions in one method, and the code that renders them in another.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Given that you haven't posted what the slowMoveVertical(int) method you are calling on each does, how could we possibly say?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

J2EE is built on Java. It is an extended architecture of components and services for network-based server-side applications and services. So it is still Java at it's core, but with an extended API for building a certain class of applications.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, the slash is pretty unclear as it stands, but yes, J2EE specifically refers to a separate platform of server-side service-oriented components:
http://java.sun.com/javaee/

You would need to inquire about their specific expectations for the job to be more precise. Knowing standard Java does not bring with it any experience at all with J2EE development, but they may be willing to train in someone who has enough Java experience.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Ok, that is because you left the Controller nested in FrameExample. Really each of those static classes should be moved up to their own top-level public classes. You don't want the Controller nor the main view to remain nested in FrameExample.

You can leave main() as it is in FrameExample, but make each static class it's own file in that same package and it'll be fine.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

W A P to find prime number in c language

PEBKAC

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

do you think he actually knows the offensive meaning?

He seems to like to just bang on the keys without a coherent thought in his skull.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Why on earth would you have two separate classes for that? Why does the first class not submit to the database?
Post the code that you have written also. You do have some, yes?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If the classes are in the same package (directory) then you should not need the import statements. In Netbeans, you can also right click in the code editor and "Fix Imports".

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

What are the Controller errors you are getting? I have no trouble putting them in separate files here. Are you placing the classes in the same package? If they are not in the same package you will need to add import statements for those classes. Beyond that I can't see where you would get errors with those classes.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

And besides, don't the foolish deserve representation in the government as well?

Well, "deserve" may be a subject of debate, but the foolish have certainly carried the day with our current representation :P

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Yes definitely. I only included all of those as static inner classes for compactness of the example. Each of those would normally be an independent class on it's own. You will noticed that I used them as such in the main() method.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

As far as the score, it will depend on how you wish to delineate the class responsibilities. Should Saucer report its score to the menu when the game is finished or should the menu have to ask Saucer what the score was after the games is ended. This leads to the question: does SaucerMenu know when a game is running and when it ends?

Deciding upon clear responsibilities for the entities (classes) in your program and ensuring that those entities maintain that contract of separate responsibility in their interactions is an important part of program design.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You seem to have misunderstood my suggestion to incorporate the Saucer game class into the SaucerMenu. I was implying that you really only need a single frame for the menu and game. Just moving the Saucer class definition to be an inner class of SaucerMenu doesn't really help you much as you are still managing two frames and now you have even more nested class levels to keep straight.

Of course, Saucer does have direct access to the internal methods and state of SaucerMenu now, but it probably shouldn't from a design standpoint if you intend to keep it as a separate class and you are still using it as such. If you wish to keep the menu and game frames separate, you may as well put Saucer back into its own file for clarity and to avoid the unnecessary scope nesting of multiple inner classes.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

i'm quite new to forums so need help ... is there nothing like online chat ... so i cud chat directly wid some1 online ... how do i view replys posted to my threads .. easily .... plz do reply to my mail account [email]email removed[/email] ...

Some "1s" may not necessarily be so keen on chatting "wid u directly online".

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

all talk abotu runescape and get your rep up! :)

I think that may be working against you instead.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Forcing people to vote when they are completely uneducated on the issue does not help a thing. If, by law, they had to go in and make a choice then it would just add random noise to the data or, even worse, ruin some elections that truly should go one way or the other on a broad consensus of educated individuals.

When the ballot is merely a random choice list presented to uninterested, uneducated fools who are forced to participate against their will, democracy is subverted far worse than by a lack of participation.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

This is your final project to get a degree. It is expected to demonstrate that you have learned enough to warrant that degree. Asking how to do that project calls into question whether you actually have acquired sufficient knowledge and the ability to research and work through the tasks you undertake. There is a level of self-direction necessary to work in the field beyond asking how to do everything on a forum won't cut it in the real world.

I say that merely as advice to you - not to be mean-spirited about it. You really need to work through this project on your own to prepare for employment in any development capacity.

Good luck!

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Ok, here are some basic changes to get you started in the right direction. Saucer now takes a reference to its SaucerMenu from the constructor, so it can interact with the menu. I've put a returnToMenu() function in that is called when the Saucer frame closes and from showScore().

showScore() was always getting called regardless of whether (lives==0) because you had a semi-colon after the if() condition - essentially an empty statement and what should have been a conditional block was just a regular nested block.

I've put a couple of comments in where I altered things. Now you will need to create some method in SaucerMenu that Saucer can call to report the game score when it closes. That method can also check against a collection of high scores and update it if needed. You'll probably want to write that to a file when the program closes and read it on start up.

Another consideration is just making the game panel be part of the SaucerMenu class instead of a free-standing JFrame, which would do away with the need to interact between the two altogether.

I see that you still have game logic in your paint() method as well. That really should be moved to it's own method separate from the rendering. Your game loop (the animation thread) needs to evaluate the game logic each iteration, update game state, and then trigger repaint. Clean separation of these responsibilities will make your code easier to manage.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Thanks! I got it start actually growing but I couldn't get it lined up. I was wondering how the (int) and (float) work in this line of code:

int offset = (int)(r*(j*(1/(float)(count))));

Those cast variables or ( ) blocks of calcs to a specific type. The inner (float) casts the int variable "count" to a float value, so that the fractional calc is performed correctly. The outer level (int) casts the entire calc back to an int value so that it can be assigned to the int offset variable.

Without the cast, an int divided by a larger int will always result in zero because the fractional portion of the value is truncated (0.1 => 0).

Hope that explains it okay.

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

Just a couple of minor changes and you're good to go. First off, int division got you on the 1/count part. This stays zero unless you cast "count" to float. I moved the calc to a variable called "offset". Also, since it was changing by a percentage of diameter, you need to multiply by "r" to get the effect you wanted and I removed the divide by 2, so it filled the area evenly.

The only other changes here are that I moved the drawing call to be after the setColor(), which is usually what you want to do, and I changed it to fillOval() instead of drawOval() so it wasn't just line drawings.

public static void bullseye(Graphics g, int x, int y, int diam, int count) {
    int r = diam;   // because fillOval uses width and height, use diam here
    int xloc = x;
    int yloc = y;

    boolean change = true;
    for(int j=0;j<count;j++) {
        // must cast int divisor to float
        // then cast the final result back to int.
        // also multiplying by r so it's a percentage of diam
        int offset = (int)(r*(j*(1/(float)count)));
        if(change) {
            g.setColor(Color.BLACK);
            change = false;
        } else {
            g.setColor(Color.RED);
            change = true;
        }
        g.fillOval(xloc+offset/2, yloc+offset/2, r-offset, r-offset);
    }
}
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Either make sure the balls can get there or don't let the user go that far into the corners.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

yup. Doing everything in one thread, and that being the Swing Event Dispatcher thread.
Guaranteed to cause application locks while waiting for things to happen on the network.

++
Exactly. If you don't want longer-running tasks tying up your GUI, you'll have to execute those in a separate thread.

Keep in mind also, don't try updating your GUI from that separate thread either or you'll see inconsistent behavior of your GUI components. Any code running in a separate thread that needs to update GUI components should be pushed on to the event dispatch thread as a new Runnable() via EventQueue.invokeLater().

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Looks good. One additional change I would suggest though: put the code that updates the ball postions and creates a new one when needed over into a separate method like "updateBalls()" and call that before repaint in your animation loop. Repaint should generally make as few calculations as possible, since it gets called for all sorts of reasons at any time (window resizings, parts of the window becoming occluded, etc). You have the ball coordinates all encapsulated in the Ball class, so this should be very easy to extract to a new method.
Your paint() method can just loop the array list and draw each ball as needed. Always try to keep paint() (or paintComponent() ) as narrowly focused on it's task of just rendering things as possible and your interface will be much happier and lag-free.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I initially learned a lot from Core Java2 v1 and v2 also. I haven't read Head First Java, but I've heard good things about it. I have read Head First Design patterns and thought they did a great job on that one.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

i thought of doing it in that way but it still doesnt works.
Anyone that can help me???
Thanks.

import java.util.Scanner;
import java.util.*;
public class grid
{
    
    private int rows;
    private int columns;
    private ArrayList<String> myArray;
    
    //static Scanner sc = new Scanner(System.in);
    private int row;
    private int colu;
    
    public void RowColumns(int rows, int columns)
    {
        ArrayList[][] myArray = new ArrayList[rows][columns];
    }
    //public void write(String r, String c)
    //{
      //for (int i=0; i<= columns; i++){
    //}
    public void addString (int row, int column, String myString) {
        for (int i=0; (i<columns);i++);{
            for (int j=0; j<rows;j++);{
                myArray[columns][rows]= Console.readLine();
            }
        }
        //myArray[rows][columns] = myString;
    }  
}

Ok, you got closer on some parts and further away on others. First off, you need a array of String[][] - not ArrayList[][], which is an array of ArrayList objects. So change the array definition to be String[][].

You do need the Scanner to read the input, uncomment that.
If you need to read the input for a single row-column cell in your addString method, then you don't need to loop all of the array. You just need to read the single entry

System.out.println("Enter string:");
myArray[row][col] = sc.readLine();

and that is all. You don't need the myString parameter on the method, just the row and column. Whatever method is calling addString() is the one that needs to loop through all rows and columns, calling addString() for each position.
I think you need to step back a little and think about the steps …

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Here are the minimal changes to get it running as a JFrame

/*Main Menu Graphical User Interface
 * Phillip Wells 10/12/07
 */

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


public class MenuGUI extends JFrame 
{
    public static void main (String [] args)
    {
    new MenuGUI();
    }


private JButton buttonnew, buttonexit;
private JLabel label1;

public MenuGUI()
    {
    this.setSize(250,100);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setTitle("Game");
    
    ButtonListener b1 = new ButtonListener();

    JPanel panel1 = new JPanel();
    buttonnew = new JButton("New Game");
    buttonnew.addActionListener(b1);
    panel1.add(buttonnew);
    this.add(panel1);
    
    buttonexit = new JButton("Exit Game");
    buttonexit.addActionListener(b1);
    panel1.add(buttonexit);
        
    label1 = new JLabel("Phillip Wells");
    panel1.add(label1);
      
    this.setVisible(true);
    }

private class ButtonListener implements ActionListener
    {
        public void actionPerformed(ActionEvent e)
        {
            if (e.getSource() == buttonnew)
            {
                NotPong game = new NotPong();
                game.init();
            }    
            else if (e.getSource() == buttonexit)
            {
                System.exit(0);
            }
        }
    }    


}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.geom.*;
import java.util.concurrent.*;

public class NotPong extends JFrame {
    public static final int WIDTH = 400;
    public static final int HEIGHT = 400;
    
    private PaintSurface canvas;
    
    public void init() {
        this.setSize(WIDTH, HEIGHT);
        canvas = new PaintSurface();
        this.getContentPane().add(canvas, BorderLayout.CENTER);
        ScheduledThreadPoolExecutor executor =
                new ScheduledThreadPoolExecutor(3);
        executor.scheduleAtFixedRate(new AnimationThread(this),
                0L, 20L, TimeUnit.MILLISECONDS);
        setVisible(true);
    }
    
    
    
    class AnimationThread implements Runnable {
        JFrame c;
        
        public AnimationThread(JFrame c) {
            this.c = c;
        }
        
        public void run() {
            c.repaint();
        }
    }
    
    class PaintSurface extends JComponent {
        int paddle_x = 0;
        int paddle_y = 360;
        
        int score = 0;
        float english = 1.0f;
        
        Ball ball;
        
        Color[] color = {Color.RED, Color.ORANGE,
        Color.MAGENTA, Color.ORANGE,
        Color.CYAN, Color.BLUE};
        int colorIndex;
        
        public PaintSurface() {
            addMouseMotionListener(new MouseMotionAdapter() {
                public void mouseMoved(MouseEvent e) …
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Ah, your game is an applet. You should convert it to a JFrame or JPanel if you wish to run it from your GUI. That is only a minimal bit of work. You'll need to do the init() work in either your constructor or call the method yourself after you have created the NotPong object. You'll also need to create a run() method that creates and starts a new Animator thread.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Read the API for Scanner . It shows basic usage right there in the javadocs. Try it out and repost your code if you are still having difficulties getting it to work.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Yes, that would be just fine I would imagine. You don't show the rest of the try block, but be sure to close the statement and connection in a finally{} clause so you don't chew up your database resources.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Also, read through the info that is in the FAQ stickied at the top of the forum. There is more than enough to get you started.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

So, to reiterate what everyone else has already told you, the answer is essentially
NO.
If you need an installer that will install java for a user if they don't already have it, take a look at http://izpack.org/.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Your handler just needs to create an instance of the game class if you don't already have one and call whatever method starts the game

Game game = new Game();
game.start();
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

Loop the outer dimension of your array and use System.arraycopy() (http://java.sun.com/javase/6/docs/api/java/lang/System.html#arraycopy(java.lang.Object,%20int,%20java.lang.Object,%20int,%20int) ) to copy each inner array.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

read a basic tutorial. And don't use Vector.

Yes, use ArrayList instead:
http://www.beginner-java-tutorial.com/java-arraylist.html

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

JFrame is a top-level component and as such can stand on it's own as a window. JPanel is a lightweight container in which other components can be placed. JPanel cannot be displayed by itself as a top-level window.

If you have a window with a single main area, using JFrame by itself can suffice. If you wish to subdivide that window into smaller component groups, you can place these components in a JPanel to manage them easier. JPanel can also be placed into components such as JScrollPane, JTabbedPane, etc to act as subforms within a window.

It's often convenient to have form classes subclass JPanel and then place them into other containers as needed. This allows you greater freedom to organize such forms or component groupings in any manner you choose.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Pot was declared illegal in the US in the 1930's, as a way to deport massive amounts of Mexican workers during a period of high unemployment.

Addressed here: http://www.daniweb.com/forums/post461975-116.html

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, if you are reducing a specific range (i.e. 256-511) by modding by 255, then yes you can get back to the number by adding the starting range value to the mod value. However, if your range exceeds 255 then you would lose the ability to reconstruct the value.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You cannot really reverse a mod operation, as only the remainder of the division operation is retained.