Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You are correct that "this" refers to the current object instance. YWhen you add a listener the parameter is typed to an interface. You can supply an object which implements that interface. The interface merely guarantees that certain methods are available on that object. Here your gui class implements the listener interfaces itself and therefore is a valid listener. You do not need the "insGui" variable at all in your case.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Okay, num_reasons_why_cpp_better_than_JAVA++; thanks anyway, Ezzaral.

Well, you are welcome to that opinion of course, but operator overloading isn't really all that special and probably causes more confusion than it's worth. It's syntactic sugar and might save you a couple characters typing, but you can achieve the exact same functionality with methods that perform the operations and no one has to wonder what "+" or "-" does in a given context.

iamthwee commented: excellent point +11
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Why is everyone making a joke about this??

Sometimes using NATURAL ELEMENTS produces MUCH BETTER RESULTS than anything man made!!

Hrmm, perhaps because the poster is a fruitcake? All three posts by this individual seem to indicated that perhaps he has soaked his own head in salt water for an extended period.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Currently reading Robert Jordan's Wheel of Time series. Just finished the first book and it's good so far.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

haha ha... ya..... just realized I had jdk1.5.0_10 and not jdk1.5_04

That might make it harder to find in the path :)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, if you have jdk 1.5_04 installed in that path, it should work just fine. I assume you have verified that location?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

if any one on here has a job on rune scape i'll do it i'm all ways need to make money

and if you want to right click on a mac right bloody click the itas he same as the windows soft waer i have had ma mini mac for about a year now iand i worked it all out in the 1st day and about the rune scape map have you ever eard of google then screen shot it its a lot easyer thats how i got it wokning

Sounds to me like you need to stay off Runescape and put a little more time into school.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

No, operator overloading is not possible in Java. The only thing you can do is add methods for the operations you need.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

basically, his program runs but it does nothing. The only thing that shows up is the menu options.

His program? I thought this was your program? And of course it doesn't do what it is supposed to: most of the switch cases have only fragments of code in them (which also goes against the assignment that each of those options should call a method to do their work.

You can't possibly expect someone to just write this to make it work for you, so ask your questions and state what you are having difficulty with.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

What errors are you getting and what is your question? Please be specific and use code tags around code you post.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

In this experiment, people take turns playing and you can delete or add players, Seem to have a couple of issues left, not sure how to work out. One of the problems is the display, the other is a class interface. Need any help or suggestions I can get. Thank you in advance!!

<snipped>

What are the issues specifically? Display and "a class interface" aren't much to go on. State what is wrong and your expectations of it.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Pls Help Me On Doing My Project. A Simple Game Using Java And I Need The Program. As Soon As Possible Thanks A Lot For Who Can Help Me.

Giving you the code for your project is not helping you at all. You won't learn a thing by turning in code that someone else wrote. Perhaps failing would be a good lesson if you won't make any effort on your assignments.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I am also doing inventoy program 5 but my issue is that i have an double array.
an honestly i can think of a way to get the info to diplay one at a time because of this. i dont know if i would be better of swiching to a singal array or if i can do a if loop some how.
...<snipped>

Please post questions as a new thread and be sure to place code tags around all code that is posted. See the announcement at the top of the forum if you do not know how to use the code tags. Also, the coding conventions published by Sun are worth a read http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

When a client connects, just add the client output stream to a collection (ArrayList should be just fine) which you can then loop through to broadcast the message along to all clients.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If even one method is declared as abstract then the class must be abstract and cannot be directly instantiated. There may be a lot of other functionality in the class, but declaring a method abstract means "this behavior must be specified by a subclass". To instantiate, you must at the very least implement the methods that are declared as abstract in a subclass and thus provide that "missing" behavior of the method. Abstract classes let you code a lot of common functionality into a base class and leave only the specific differences in implementation to be supplied.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

thanks again. i do appreciate it. do have a code like that. so i can look on tht and develop mine? i just got five days. please. please my email is <snipped email> u can add me so tht we chat now. thank u very much

No, I do not have any code for that in particular. Just go through the tutorial and perhaps this one too http://www.apl.jhu.edu/~hall/java/Java2D-Tutorial.html.

Here's a tiny bit of code to get you started

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Ellipse2D;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class PaintPanel extends JPanel{
    
    public PaintPanel() {
    }

    protected void paintComponent(Graphics g) {
        Graphics2D g2D = (Graphics2D)g;
        // paint background
        g2D.setBackground(Color.WHITE);
        g2D.clearRect(0,0,getWidth(), getHeight());
        
        // paint shape
        g2D.setColor(Color.BLUE);
        drawEllipse(g2D);
    }
    
    private void drawEllipse(Graphics2D g2D){
        int shapeWidth = 150;
        int shapwHeight = 75;
        Ellipse2D.Double ellipse = new Ellipse2D.Double( (getWidth()-shapeWidth)/2, (getHeight()-shapwHeight)/2, shapeWidth, shapwHeight);
        g2D.draw(ellipse);
    }
    
    public static void main(String[] args) {
        PaintPanel panel = new PaintPanel();
        JFrame frame = new JFrame("Paint");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(panel);
        frame.setBounds(100,100,300,300);
        frame.setVisible(true);
    }   
}
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, the easiest place to start is the Java 2D graphics tutorial: http://java.sun.com/docs/books/tutorial/2d/index.html

Start with just getting a couple of shapes to draw on a JPanel. Pehaps add buttons to draw a circle, square, etc. They can be of fixed size to begin with. Then go on to add mouse listeners that let the user click and drag to stretch the size of whatever shape they selected. Approach it by steps and you shouldn't have too much difficulty.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Post your code then and describe what problems you are having. Be sure to place code tags around the code you include.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, according to this http://hudzilla.org/phpwiki/index.php?title=Avoid_overusing_function_calls it is, and zend.com has the following to say on it

Function calls carry a high overhead. You can get a bump in performance if you eliminate a function. Compiled languages, such as C and Java, have the luxury of replacing function calls with inline code. You should avoid functions that you only call once. One technique for readable code is to use functions to hide details. This technique is expensive in PHP.

in this page about optimizing php http://www.zend.com/zend/trick/trick-optimizing-php.php

iamthwee commented: Interesting links +11
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Hi All,

I am trying to parse an xml file. Not using any of the regex or parsers, simply using only java code. Any suggestions? Thanks

Ok, so you won't use an XML parser for some reason that you won't explain. Your last post asked how to do it with regex - so I took the time to write some code for you to get you started with it and you completely ignored it. Now you want someone to tell you how to parse it without XML parser or regex. Did I miss anything there?

Well, speaking for myself, just forget it. Learn to use the String API on your own to parse the data. Good luck.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

JFreeReport is pretty decent and free.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

why not? Clear separation of concerns is where it's at. Mixing business logic with display logic is bad as it makes for code that's hard to expand and maintain.

Yeah, I understand what they were going for, but I still just don't like looking at things like loops that have been pressed into a tag format and, being far more used to looking at Java than tags, it seem far clearer and more flexible to have scriplets right there rather than packaged off in a tag library. The only JSP we've used here is a couple of minimal internal DB front ends and our primary focus is desktop development, so honestly we haven't put any effort into redesigning them "properly". At best they are "hacks" to meet a few internal web dev needs that took time we could not afford to waste away from primary development. If web development beyond a CRUD front end was needed, we would take a more organized and proper approach to it. So really my personal dislike of "everything must be tags" stems from that - just a personal thing born of minimal web development and a greater comfort with Java code.

And as JSPs that are well designed (so with no Java code at all) can be maintained (at least in large part) by people in the web development shop who have no or limited Java experience that's a big bonus.

I know that is the hoped for result, but I often wonder just …

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Just read the API for ArrayList. The methods are quite clear. If you don't understand Collections at all, there is a lot of info here: Java Collections Framework

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If you are comfortable with Java, PHP is really pretty easy to learn. You'll still have to get used to things like state management and passing variables through GET, POST, and SESSION, but you face those in JSP as well as PHP.

Both are just fine for what you want, but finding a host that serves JSP may be a little more work. PHP hosting seems a lot more common to me, but then I haven't looked around a lot so that could just be a misperception.

Personally, I don't like the new "everything must use tags - no Java in JSP pages" mantra they have gone to with the latest JSP spec. Being comfortable with Java, I prefer seeing the code - not tags for things like loops.

That's why I switched to using PHP for my personal web dev stuff.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It really depends on how that piece of info relates to Customer. Is it specific to each customer and applicable to all customers? Then add it.

Is it only applicable to a certain kind of customer and has no meaning in the context of most customers? Then extend Customer.

Is it unrelated to innate Customer attributes but requires some data from Customer and it's just a convenient place to "stick" that piece of info? It should be in some other class and pull the info as needed from a Customer that is passed in as a parameter.

That's about the only general advice I could give without knowing more specifics of the relationships.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Better yet, I think I will learn more if I just write it without using regex. Any ideas?

Well, if you absolutely cannot use an XML parser (I am assuming because of class assignment restrictions?), then regex is your next best choice. Straight parsing might be possible if you are certain that each data element will always be on a separate line, such as your example above, but if it is not then you should stick with regex.

Even with regex there can be tricky spots with XML because of it's nested nature. The code below will show you what I mean and perhaps give you a starting point to work from

String in = "<person> Sue Smith "+
                    "<age> 32 </age> "+
                    "<sex> female </sex> "+
                    "</person> "+
                    "<person> John "+
                    "<child> "+
                    "<name>Jim</name> "+
                    "<age> 2</age> "+
                    "</child> "+
                    "<age> 45 </age> "+
                    "<sex> female </sex> "+
                    "</person>";
        Pattern personPattern = Pattern.compile("<person>(.+?)</person>",Pattern.CASE_INSENSITIVE);
        Pattern namePattern = Pattern.compile("<person>(.+?)<",Pattern.CASE_INSENSITIVE);
        Pattern agePattern = Pattern.compile("<age>(.+?)<",Pattern.CASE_INSENSITIVE);
        Matcher personMatcher = personPattern.matcher(in);
        while (personMatcher.find()){
            System.out.println("person match:");
            Matcher nameMatcher = namePattern.matcher(personMatcher.group(0));
            while (nameMatcher.find()){
                System.out.println("Name: "+nameMatcher.group(1));
            }
            Matcher ageMatcher = agePattern.matcher(personMatcher.group(0));
            while (ageMatcher.find()){
                System.out.println("Age: "+ageMatcher.group(1));
            }
        }

If you run that (in a test class main() is fine), you will see that it catches 2 ages for John because there is a <child> element with an <age> tag within his <person> element. Your regex parsing needs to take that into account to separate that age from the child age. Good luck!

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You could use regex to extract all of those things, but really an XML parser would be a lot easier and more appropriate to the task. An XML DOM parser is what I would recommend you use. See the XML tutorial here:http://java.sun.com/xml/tutorial_intro.html and specifically this section XML and the Document Object Model (DOM).

masijade commented: They always insist on regex. +4
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

This is the Java programming language forum - there is a separate forum for Javascript and you would probably get quicker help over there.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

sorry i don't know that. hey can u help me in understanding thid question. i am not geting any thing wat's the output. plssssssssss

As I already stated - no, you need to make the effort on your homework yourself, post your code with your questions. If you have been paying attention at all in class then you should have some understanding of the question. You didn't even post the algorithm that was supposed to be run - this is only a fragment of a question.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

No, read the announcement at the top of the forum - we do not do homework for you.

Post code that you are having difficulty with and specific questions about it. The forum is to help those who are making an honest attempt at solving their issue. It's not for those who just want the work done for them.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Okay, I've let it go and tried to end all with this since there's no specified function I just figured I'd do this but still getting problems

public static int i(int i)
        {
                if (i == 0)
                {
                      return i;
                      System.out.println("i is = " + i);
                }
                else if (i != 0)
                {
                      return i;
                      System.out.println("i is = " + i);
                }
        }

??? That makes even less sense than the first method. If "i" is zero or if it is not zero, return "i"? What is it that the method is intended to do?

The "unreachable statement" error you are surely getting are from the println() statements being after the return statements. Once the method has returned the value, code after that point will not be executed. Move the statements before the returns and they will be fine.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Friend.... according to me .NET is 80 per cent and SAP 20 per cent... If want... consider my opinion

And do you actually have any basis for that outside your imagination?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

This method actually won't compile either

public static int i(int i)
        {
                if (i == 0)
                {
                return i;
                }
        }

because there is no guaranteed return. If the i==0 check is false, there is no return. You need to return something if your check fails

public static int i(int i)
        {
                if (i == 0)
                {
                      return i;
                }
                else
                {
                      return -1; // or whatever you need if i != 0
                }
        }

Also, I can't figure out what the purpose of such a method is. Always name methods with something descriptive of what it is doing - "i" does not tell anyone anything about the purpose of the method.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Yes, the draw() method encapsulates how to draw the chart and the Graphics2D parameter is what to draw the chart on. In that way, your method can draw onto anything that can supply a graphics context to it and is not limited to a graphics context from one particular source.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Your displayComputerInfo() method is calling methods on Computer as if they are static, because you typed Computer instead of computer - different case. Gotta watch case-sensitivty in Java :)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I like pty's idea, over the summer I thought I'd look into java/c++ so I DL some ebooks on Java. Problem is can't really concentrate on a computer screen, and reading stuff like that from a book is hella confusing (me audio/visual learner it would seem).

Honestly, if that is the case you probably need to drop any thoughts of working in development at all. The ability to learn new things constantly from the available resources (i.e. the internet, books, etc) is one of the few underpinnings all development jobs (perhaps even all IT jobs) rely on. You don't just learn a couple of things from a class and go on to a career using those few things covered - you learn all the time and the day you stop is the day you are done with that career.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Try IzPack, it's a free Java installer that will let you create distributions like that.
http://izpack.org/

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It still sounds like int division is all you need. Take a look at the following and run it yourself it you want to verify the result:

int totalChapters = 1189;
    int chaptersRead= 1100;
    int timesBookRead = chaptersRead / totalChapters;  // yields 0
    System.out.println("times read = "+timesBookRead);
    chaptersRead = 1200;
    timesBookRead = chaptersRead / totalChapters;  // yields 1
    System.out.println("times read = "+timesBookRead);
    chaptersRead = 1189*3+24;
    timesBookRead = chaptersRead / totalChapters;  // yields 3
    System.out.println("times read = "+timesBookRead);
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, your explanation is a little difficult to follow, but it sounds like int division by 1189 is all you are needing

// assuming that show is an int or long
b = show/1189;

Does that yield the result you are trying to achieve?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You could use the following for the countdown

class ButtonCountdown implements ActionListener {
        int count=0;
        JButton button = null;
        
        public ButtonCountdown(final JButton button, int count){
            this.count = count;
            this.button = button;
        }
        public void actionPerformed(ActionEvent e) {
            if (count>0){
                button.setText(String.valueOf(--count));
            } else {
                button.setText("Done!");
            }
        }
    }

and then start it like so after you have the UI all set up

Timer koTimer = new Timer(1000, new ButtonCountdown(ko, 5));
koTimer.start();
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You need to set up a Swing Timer to handle the countdown on the button. See the following on timers:How to Use Timers.

The behavior you are getting right now is because you are sleeping in the thread that is creating the UI. Create the UI first and after it is set visible, start the Timer task that updates the label on the button (and it's behavior if needed).

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Also, when looping a collection for deletion it's easier to loop from end to beginning, i.e. from size()-1 to 0. Element shifts from deletion won't affect your indexing if you do that.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Two secrets to keep your marriage brimming:
1. Whenever you're wrong, admit it!
2. Whenever you're right, shut up!

++

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

:)
The airports would be really crowded, if 10% of the people would do that head-shaven-thingy!

Ugh, yeah that is scary to think about =)

I'm figuring many of them have a long chain of such turning away from the 90% though - so it recursively dwindles to just a few fruitcakes there in the long run.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Mysuggestion would be to walk away from the 90% who don't and join the 10% who do.

You are going to end up at the airport in a robe, head shaved, and handing out pamphlets if you live by that suggestion empirically... or drinking Kool-Aid with a large group in South America...

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Hi every body,
I am a masters student in computer science and i am looking for a project that is working good. I need the code for it. If anybody has it, please send it to me...or atleast suggest me where i could find one. The project shlould be at masters level.
Thank you

If you are begging for a working project to be just handed to you at the masters level, then your name belies you - you aren't so "awesome".

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Just move the monthly payment call out of your loop and print it before the rest. Having it in the loop, you are actually changing the monthly payment on each iteration, which I don't believe you want to do.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You don't need to "implement" that class then. You just need to declare an object of that type and use whatever methods you need on it.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, is the "other classname" an interface? The declaration expects you to have an interface name there, which your class implements. When you say "call " an external class, what exactly are you trying to do?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You have no guaranteed return statement in doMath(). If op falls through all of the cases in your switch, the method would not return a value. Add a default return value after the switch and it will be fine

static int doMath(char op,int numa, int numb){
        
        switch (op)
        
        {
            case '+':
                return numa + numb;
                
            case '-':
                return numa - numb;
                
            case '*':
                return numa * numb;
                
            case '/':
                return numa / numb;
        }
        return 0;  // or another default if you prefer
    }