Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

hooah posted:

Could you go into a little more detail? Keep in mind I've never worked with java or Eclipse before. Here's the dialog I see when I choose fix project:


I'd reckon it's either the "Add JARs" or "Add External JARs" button. Did you try either of those before your post?

edit: here ya go https://www.youtube.com/watch?v=EeYGak5DeBg

fletcher fucked around with this message at 03:42 on Dec 19, 2013

Adbot
ADBOT LOVES YOU

hooah
Feb 6, 2006
WTF?
Alright, I got the import working (turns out I had to import "kareltherobot", not add any external stuff), but I can't figure out the right name to extend. I've tried Karel, KarelJRobot, and kareltherobot. Here's my project directory:

Woodsy Owl
Oct 27, 2004

hooah posted:

Alright, I got the import working, but I can't figure out the right name to extend. I've tried Karel, KarelJRobot, and kareltherobot. Here's my project directory:


You've got to import the package by it's package name and follow it by a .* or a specific class. For example:
Java code:
//This is going to import all the classes for use in your project.
import kareltherobot.*;
or
Java code:
//This is going to import only these classes for use in your project.
//If you've got to use another class from the package then you're going
//to have to explicitly import it like below.
import kareltherobot.Robot;
import kareltherobot.World;
import kareltherobot.WhateverOtherClassYouNeed;

hooah
Feb 6, 2006
WTF?

Woodsy Owl posted:

You've got to import the package by it's package name and follow it by a .* or a specific class. For example:
Java code:
//This is going to import all the classes for use in your project.
import kareltherobot.*;
or
Java code:
//This is going to import only these classes for use in your project.
//If you've got to use another class from the package then you're going
//to have to explicitly import it like below.
import kareltherobot.Robot;
import kareltherobot.World;
import kareltherobot.WhateverOtherClassYouNeed;

Yeah, import kareltherobot.*; is what I did.

Woodsy Owl
Oct 27, 2004

hooah posted:

Yeah, import kareltherobot.*; is what I did.

What's the error that you're receiving?

hooah
Feb 6, 2006
WTF?

Woodsy Owl posted:

What's the error that you're receiving?

I have a line that says public class OurKarelProgram extends kareltherobot{. The problem is that I can't figure out what to put after extends that will satisfy Eclipse. Anything I put there gets underlined, and the mouse-over pop-up says "[whatever] cannot be resolved to a type". I've tried Karel, KarelJRobot, and kareltherobot.

Woodsy Owl
Oct 27, 2004

hooah posted:

I have a line that says public class OurKarelProgram extends kareltherobot{. The problem is that I can't figure out what to put after extends that will satisfy Eclipse. Anything I put there gets underlined, and the mouse-over pop-up says "[whatever] cannot be resolved to a type". I've tried Karel, KarelJRobot, and kareltherobot.

Oh okay. The keyword 'extends' makes your class an extension of the particular class. So, the 'extends' keyword needs to be followed by a class, not a package. What it means is that your class becomes an extension of the class; your class has the same methods and constructors as the extended class, and you can add your own methods to your class to 'extend' the method.

Java code:
//A Person is an object representing a person's name.
class Person {
	String name;	//the name of the person
	
	Person (String name) {
		//the 'this' keyword is a reference to the current
		//instance that is being constructed by this
		//constructor method call.
		this.name = name;
	}
}


//A SuperHero is a Person, plus a super-power.
//We use 'extends Person' here because it saves us the
//effort of rewriting the name jazz. SuperHero can use
//all the methods in the Person class, because it is a
//person, in fact.
class SuperHero extends Person {
	String superPower;
	
	SuperHero (String name, String superPower) {
		//We need to call the Person constructor,
		//we do this with the super() keyword
		super(name);    

		//Lets store the superPower here for this
		//SuperHero object instance
		this.superPower = superPower;
	}
	
}
Hope this helps!

edit: Depending on what the task/assignment is, you might not even need to use the 'extends' keyword.

Woodsy Owl fucked around with this message at 15:30 on Dec 19, 2013

hooah
Feb 6, 2006
WTF?

Woodsy Owl posted:

Oh okay. The keyword 'extends' makes your class an extension of the particular class. So, the 'extends' keyword needs to be followed by a class, not a package. What it means is that your class becomes an extension of the class; your class has the same methods and constructors as the extended class, and you can add your own methods to your class to 'extend' the method.

Hope this helps!

edit: Depending on what the task/assignment is, you might not even need to use the 'extends' keyword.

That helps conceptually, but not really specifically, since evidently the Karel distribution I grabbed isn't quite the same as the one used in the Stanford lectures, so I don't know which class I should be extending. Hmm.

As an aside, do you need the this. in a method, or can you leave the data member naked as in C++?

Zaphod42
Sep 13, 2012

If there's anything more important than my ego around, I want it caught and shot now.

hooah posted:

That helps conceptually, but not really specifically, since evidently the Karel distribution I grabbed isn't quite the same as the one used in the Stanford lectures, so I don't know which class I should be extending. Hmm.

As an aside, do you need the this. in a method, or can you leave the data member naked as in C++?

Here's a page I found on Karel for java

http://programmingjava.net/2-basic-karel-program/

http://programmingjava.net/3-improve-karel-using-methods/

Looks like that's the same library you're using? Yeah, if the Stanford library is named differently than yours then the extends won't work. Unfortunately that means the rest of the API might be different too, so you may want to go back and try to find a better stanford karel library and get that working. Although... this page here references Stanford. Hmm. Maybe they are the same.

You generally don't need to use "this." in a method, class field variables have full class scope. However, if you have a variable with a name like myVar, and then in a method you declare "int myVar = 10;" you're going to now have no way to refer to the class level variable myVar, since they're the same name. This is called shadowing, and the way you can get around it is by saying "this.myVar". The other case where you need this. is if you're passing yourself as a reference ( myMethod(this); ) or some other special cases. It isn't usually needed, no.

Looks like this should work

Java code:
import stanford.karel.*;
public class MyKarel extends Karel {
    public void run() {
        move();
        putBeeper();
        move();
    }
}

Zaphod42 fucked around with this message at 17:00 on Dec 19, 2013

hooah
Feb 6, 2006
WTF?

Zaphod42 posted:

Here's a page I found on Karel for java

http://programmingjava.net/2-basic-karel-program/

http://programmingjava.net/3-improve-karel-using-methods/

Looks like that's the same library you're using? Yeah, if the Stanford library is named differently than yours then the extends won't work. Unfortunately that means the rest of the API might be different too, so you may want to go back and try to find a better stanford karel library and get that working. Although... this page here references Stanford. Hmm. Maybe they are the same.

You generally don't need to use "this." in a method, class field variables have full class scope. However, if you have a variable with a name like myVar, and then in a method you declare "int myVar = 10;" you're going to now have no way to refer to the class level variable myVar, since they're the same name. This is called shadowing, and the way you can get around it is by saying "this.myVar". The other case where you need this. is if you're passing yourself as a reference ( myMethod(this); ) or some other special cases. It isn't usually needed, no.

Looks like this should work

Java code:
import stanford.karel.*;
public class MyKarel extends Karel {
    public void run() {
        move();
        putBeeper();
        move();
    }
}

I'm not sure if it's the same library. The one I got was from Pace University; the link from that Java tutorial is dead. The first thing I tried doing while watching the lecture video was saying import standford.karel.*;, and Eclipse couldn't resolve the stanford import. I used the contact link on the Stanford site to ask if there's somewhere to download the Karel project or if they could make heads or tails of the error their Eclipse distro was giving me, but based on their automated response, I'm not hopeful.

Zaphod42
Sep 13, 2012

If there's anything more important than my ego around, I want it caught and shot now.

hooah posted:

I'm not sure if it's the same library. The one I got was from Pace University; the link from that Java tutorial is dead. The first thing I tried doing while watching the lecture video was saying import standford.karel.*;, and Eclipse couldn't resolve the stanford import. I used the contact link on the Stanford site to ask if there's somewhere to download the Karel project or if they could make heads or tails of the error their Eclipse distro was giving me, but based on their automated response, I'm not hopeful.

I'm confused. You said you were doing Stanford's intro to programming course. Stanford sent you to Pace?

You can't use somebody else's library without some kinda documentation. If the links are dead then don't use that. What are you doing this for anyways? Trying to learn java? There's infinity tutorials out there, pick a new one that's better documented and better maintained. Trying to follow along with a different library probably won't work well, especially if you're new. You'll just keep getting bogged down and lost.

FateFree
Nov 14, 2003

rhag posted:

What do you mean by cannot perform? Has that index table indexes created for the indexName and indexValue fields? Such as CREATE INDEX IDX1 on Index (indexName,indexValue) ? Is customerId a primary key on the other tables? Or has an index made for it?

However you look at it though, the existence of the Index table doesn't look good. Changing the database may not help in this case. Changing the developers may.

We are running a Teradata database. It is not meant to be an operational database, it will never be an operational database, and trying to make it perform like an operational database will never work. This was big corporation political fuckery that cannot be unfucked so it needs to be taken as a constant. (It is so bad that we are now storing our ENTIRE data model as a json object in one table, thus we have no indexes because we essentially have no data model). I can go on for days about how terrible this situation is but it will not help as this is the situation and no one will change it.

So the problem is that we have a JSON blob as our entire database and no way to query it, thus the terrible index table was born. Even that has been tuned to poo poo by Teradata's experts and its not good enough. So whats are some alternative choices for an indexing application? We would really like something thats already built and open sourced - our best choice at the moment is Lucene because it can handle fuzzy searching on some of these index values like email and first name. Are there any other options that might work?

Volguus
Mar 3, 2009

FateFree posted:

We are running a Teradata database. It is not meant to be an operational database, it will never be an operational database, and trying to make it perform like an operational database will never work. This was big corporation political fuckery that cannot be unfucked so it needs to be taken as a constant. (It is so bad that we are now storing our ENTIRE data model as a json object in one table, thus we have no indexes because we essentially have no data model). I can go on for days about how terrible this situation is but it will not help as this is the situation and no one will change it.

So the problem is that we have a JSON blob as our entire database and no way to query it, thus the terrible index table was born. Even that has been tuned to poo poo by Teradata's experts and its not good enough. So whats are some alternative choices for an indexing application? We would really like something thats already built and open sourced - our best choice at the moment is Lucene because it can handle fuzzy searching on some of these index values like email and first name. Are there any other options that might work?

Ouch, this is worse than I thought. Even a DBA cannot save you now (probably). What I would do (before bringing the experts, paying them a bazillion bucks to "fix it"), i would try a NoSQL document store database. MongoDB, cassandra may be good things to try, especially since you are already storing json documents in the database. Personally i have no experience with these though, but plenty of people over the internets do. Who knows, it may work.

If nothing works, i would seriously consider going to Teradata and just make them fix it. I assume you have a contract with them, take advantage of it as much as you can.

hooah
Feb 6, 2006
WTF?

Zaphod42 posted:

I'm confused. You said you were doing Stanford's intro to programming course. Stanford sent you to Pace?

You can't use somebody else's library without some kinda documentation. If the links are dead then don't use that. What are you doing this for anyways? Trying to learn java? There's infinity tutorials out there, pick a new one that's better documented and better maintained. Trying to follow along with a different library probably won't work well, especially if you're new. You'll just keep getting bogged down and lost.

I'm doing Stanford's free online course, yes. They didn't provide any sort of Karel anything, so I went looking for something to grab, and found the Pace one.

Since it looks like the Stanford course isn't going to work (at least not the first however many lectures until he moves on past Karel), what tutorials do you recommend? I'm looking to learn Java between semesters so I can go into my second semester with a little more of a varied background than just C++.

Woodsy Owl
Oct 27, 2004

hooah posted:

I'm doing Stanford's free online course, yes. They didn't provide any sort of Karel anything, so I went looking for something to grab, and found the Pace one.

Since it looks like the Stanford course isn't going to work (at least not the first however many lectures until he moves on past Karel), what tutorials do you recommend? I'm looking to learn Java between semesters so I can go into my second semester with a little more of a varied background than just C++.

If you've got a bit of a background in programming already (it sounds like you've done some C++) then I would suggest you work through the beginning of the official Oracle Java Tutorials. I would suggest you start at Lesson: Language Basics so you can see how Java syntax differs from C++.

hooah
Feb 6, 2006
WTF?

Woodsy Owl posted:

If you've got a bit of a background in programming already (it sounds like you've done some C++) then I would suggest you work through the beginning of the official Oracle Java Tutorials. I would suggest you start at Lesson: Language Basics so you can see how Java syntax differs from C++.

Thanks. I also grabbed the videos mentioned in the OP.

Volguus
Mar 3, 2009

hooah posted:

Thanks. I also grabbed the videos mentioned in the OP.

Packt have a sale until Jan 5th on all ebooks. https://www.packtpub.com/ebookbonanza
Maybe one from there can help.

Posting Principle
Dec 10, 2011

by Ralp
Be very very careful with Packt, most of those books aren't worth $5.

Volguus
Mar 3, 2009

Posting Principle posted:

Be very very careful with Packt, most of those books aren't worth $5.

Oh, I didn't know that. I got https://www.packtpub.com/spring-security-3-1/book some time ago and it was fine. I can only advise then to check out reviews of a book before buying it.

greenchair
Jan 30, 2008
Hey I've got a couple of newbie questions. I'm not really good with all my vocabulary so hopefully these are understandable.

1. So it seems like java classes can implement multiple interfaces, but what about when dealing with "question mark notation"? For example, I can have a Class like :
public class Dog implements Animal, Guard.
Where a class, Dog, is implementing two interfaces Animal, and Guard, But I don't seem to be able to do something like this:
ArrayList<? extends Animal, Guard> .

What I'd really like to be able to do is something like:
ArrayList<? extends Dog, implements Guard, Animal> (Then I could fill in the list with GermanShepard, PitBull (Sub Classes of Dog) types etc.
Does that make sense? Is there any way to do it?

2. Can an object reclassify its self? Say I have a super class, Person, and two sub-classes Male, and Female. Would it be possible for Male to have a method mTF() that would change it to a female? So I could Instantiate John as a male, call the mTF function, and then John would then be a Female?

Thanks

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

greenchair posted:

Hey I've got a couple of newbie questions. I'm not really good with all my vocabulary so hopefully these are understandable.

1. So it seems like java classes can implement multiple interfaces, but what about when dealing with "question mark notation"? For example, I can have a Class like :
public class Dog implements Animal, Guard.
Where a class, Dog, is implementing two interfaces Animal, and Guard, But I don't seem to be able to do something like this:
ArrayList<? extends Animal, Guard> .

What I'd really like to be able to do is something like:
ArrayList<? extends Dog, implements Guard, Animal> (Then I could fill in the list with GermanShepard, PitBull (Sub Classes of Dog) types etc.
Does that make sense? Is there any way to do it?

By question mark notation, you're talking about Generics.

No, you cannot do those things per se. You could have an interface that extends both Guard and Animal, and have your GermanShepherd class implement that. For your latter example, you're probably not going to be able to easily match your model to Java, since it does not support multiple inheritance in the way you are thinking.

quote:

2. Can an object reclassify its self? Say I have a super class, Person, and two sub-classes Male, and Female. Would it be possible for Male to have a method mTF() that would change it to a female? So I could Instantiate John as a male, call the mTF function, and then John would then be a Female?

Thanks

No. In Java, a person is either male or female, and cannot transition at runtime. Such a concept does not exist, and all runtimes are cisgender oppressors.

:biotruths:

Edit: \/\/\/ listen to this guy instead

Volmarias fucked around with this message at 21:57 on Dec 20, 2013

Sedro
Dec 31, 2008

greenchair posted:

Hey I've got a couple of newbie questions.
You can 'and' together interfaces at a generic type declaration
Java code:
interface Animal {}
interface Guard {}
public class Dog implements Animal, Guard {}

// this method accepts any `T` which implements both of these interfaces
public <T extends Animal & Guard> List<T> func(T animalWithGuard) {
    ArrayList<T> list = new ArrayList<T>();
    list.add(animalWithGuard);
    return list;
}

func(new Dog());
You can't use this at an instance declaration, it has to be a bound type parameter (either on a class or a function).

Java doesn't support gender changes. Born a male, always a male. You can however create an identical clone of John who is a female.
Java code:
class Male {
    Female mTF() {
        return new Female(this.name, this.age, ... );
    }
}

Volguus
Mar 3, 2009
Or, you know, you can store the sex as a member of the Human (or Person or whatever) class and change it as often as you'd like. Don't abuse inheritance. Is a powerful tool, but one that can lead to a complete mess when used improperly.

In this case, we can see clearly that a Person has a sexual identity (just like it has a name, address, etc.). The person is not male or female. Before subclassing always ask yourself: Is Foo Bar, or does Foo have Bar? The answer to that question pretty much can tell you if you should or shouldn't inherit Foo from Bar.

Zaphod42
Sep 13, 2012

If there's anything more important than my ego around, I want it caught and shot now.
^^^^ Listen to this man.

greenchair posted:

What I'd really like to be able to do is something like:
ArrayList<? extends Dog, implements Guard, Animal> (Then I could fill in the list with GermanShepard, PitBull (Sub Classes of Dog) types etc.
Does that make sense? Is there any way to do it?

I think you're making it way harder than it needs to be.

How familiar with OOP, inheritance, and generics are you?

Why not just create new interface SubDog extends Dog implements Guard, Animal, then all your objects extend SubDog.

ArrayList<SubDog>

Although logically Dog would implement Guard, Animal or... yeah probably reorganize your class hierarchy.

greenchair
Jan 30, 2008
Thanks that's really helpful! Are there any languages that would support the "mTF()" type thing? I was thinking that the reason It'd be useful is that the Male and Female subclasses would have different methods, or perhaps different implementations of an abstract superclass method.

Zaphod42
Sep 13, 2012

If there's anything more important than my ego around, I want it caught and shot now.

greenchair posted:

Thanks that's really helpful! Are there any languages that would support the "mTF()" type thing? I was thinking that the reason It'd be useful is that the Male and Female subclasses would have different methods, or perhaps different implementations of an abstract superclass method.

See Static vs Dynamic typing, such as Duck Typing.

http://en.wikipedia.org/wiki/Type_system

http://en.wikipedia.org/wiki/Duck_typing

TL;DR: Yes.

greenchair
Jan 30, 2008
I'm pretty new to OOP so it's also very likely that I should just rethink my strategy too.

ed. Thanks for those links I'll check them out!

greenchair fucked around with this message at 22:43 on Dec 20, 2013

carry on then
Jul 10, 2010

by VideoGames

(and can't post for 10 years!)

The difficulty is in the fact that each type may have properties or methods which do not exist in the other. To use a better example, if both Circle and Triangle extend Shape, but Circle has center and radius, while Triangle has point1, point2, point3, how could you possibly do a circleToTriangle() without programmer insight?

While duck typing systems let you stuff a triangle into a variable which before held a circle, true conversions like that aren't really possible in the language itself.

Fedaykin
Mar 24, 2004
I want to run a program using

Process proc = Runtime.getRuntime().exec("program");

and then move the program's frame to a specific location on the screen. How can I do this?

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
If you have no control over that program and can't make any assumptions about its behavior, you might be able to cobble together something via the AWT Robot:

http://docs.oracle.com/javase/7/docs/api/java/awt/Robot.html

If it was a program I'd written I might just add some command-line arguments for positioning the window.

Fedaykin
Mar 24, 2004
So I need to take a screenshot and then write an algorithm to find that window and move it with the awt robot? There isn't an easier way?

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
I was kind of assuming that the window was starting out in a consistent position, which would allow you to simply use the Robot to blindly drag the window into the desired position, but I recognize that this approach may not always be feasible. Perhaps you could elaborate upon what you are trying to accomplish?

Fedaykin
Mar 24, 2004

Internet Janitor posted:

If it was a program I'd written I might just add some command-line arguments for positioning the window.
I am trying to write a bot that solves the gnomine minesweeper game that comes with ubuntu.

Here is the man for gnomine
http://csurs7.csr.uky.edu/cgi-bin/man/man2html?gnomine+6

when I try to run 'gnomine -a X -b Y'
It says 'Unknown option -a'
???

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Fedaykin posted:

I am trying to write a bot that solves the gnomine minesweeper game that comes with ubuntu.

Here is the man for gnomine
http://csurs7.csr.uky.edu/cgi-bin/man/man2html?gnomine+6

when I try to run 'gnomine -a X -b Y'
It says 'Unknown option -a'
???

Is that the man page for the actual version you have installed on your system?

DholmbladRU
May 4, 2006
I am attempting to generate KML files using the JAK KML library. I have successfully done so however when this code was migrated from Tomcat -> IIS platform it stopped functioning. IIS is using java 1.6 while tomcat was on 1.7, but all the .jars for JAK are compiled with 1.6 I believe.

The problem I am having is the file size for the .kml files are 0 when the code is finished executing. I am calling KML.marshal(new file('file.kml'). The kml.document does contain the placemarks I am attempting to write to the file. And it doesnt seem to be a permissions issue with the directory because I am able to write to it with .txt files or if I use a bufferedwriter.


In the working environment kml.marshal() returns true in the non working it returns false..

DholmbladRU fucked around with this message at 22:47 on Dec 30, 2013

Woodsy Owl
Oct 27, 2004
Regarding Swing app development: what is the common practice for implementing behavior (ActionEvents and so on) for Swing components; in the JFrame's class, or in a parent class that instantiates one of the JFrames and adds necessary action listeners to it on instantiation? It's my very first Swing app so I'm not sure what the design standard is, but I'm partial to the second option because I'll be bringing together multiple classes (JFrames and helper classes) to implement the behavior of my application and I want to abstract the behavior away from the JFrames. Essentially I want the JFrame instantiation to handle building the window (adding components to itself), but the behavior methods of the components will be defined outside of the JFrame's class. I think this is efficient because I'm leaving the design part of the application inside the JFrames and then defining the behavior/usage part in my application class.

Am I on the right track here? Or is there no real standard and it's really just subjective and relative to the task at hand and the programmer/designer? Is it totally a design decision?

edit: Also, are there any LookAndFeels that I should be avoiding due to some community hatred? I quite like working with the Nimbus LAF, but I could see how some people could be irritated by it...

Woodsy Owl fucked around with this message at 11:32 on Dec 31, 2013

Volguus
Mar 3, 2009

Woodsy Owl posted:

Regarding Swing app development: what is the common practice for implementing behavior (ActionEvents and so on) for Swing components; in the JFrame's class, or in a parent class that instantiates one of the JFrames and adds necessary action listeners to it on instantiation? It's my very first Swing app so I'm not sure what the design standard is, but I'm partial to the second option because I'll be bringing together multiple classes (JFrames and helper classes) to implement the behavior of my application and I want to abstract the behavior away from the JFrames. Essentially I want the JFrame instantiation to handle building the window (adding components to itself), but the behavior methods of the components will be defined outside of the JFrame's class. I think this is efficient because I'm leaving the design part of the application inside the JFrames and then defining the behavior/usage part in my application class.

Am I on the right track here? Or is there no real standard and it's really just subjective and relative to the task at hand and the programmer/designer? Is it totally a design decision?

edit: Also, are there any LookAndFeels that I should be avoiding due to some community hatred? I quite like working with the Nimbus LAF, but I could see how some people could be irritated by it...

Swing has been ... deprecated in the last few years in favour of the new and shiny javafx. There is no "standard" per se, but the design should follow the same principles as anywhere else: avoid tight coupling, components should do one thing and one thing only, delegate as much as possible, etc.

What you can do:
  • if you can, use a framework of some kind, that will provide this sort of structure for free. SAF used to be that one, but now is dead. Some people point to netbeans framework, though i personally never used it. It will, however, provide you with a good toolkit of ready-made components to use for free.

  • if you cannot (or won't) use a framework, one way to design your application is like this:
    • Use guice (for light CDI) and guava (for a lot of utilities, namely EventBus in particular).
    • Use javax.swing.Action (or extend from AbstractAction) to inject into components their behaviour.
    • Let the Frame make itself (add the menu, toolbar, main panel, status bar, etc.), but all from injectable components. Shouldnt have to use "new".
    • Pass to the buttons, menu items, etc. the corresponding actions, which will provide the label, icon, and most importantly actionPerformed .
    • You can perform the action there or use EventBus to post an event from the actionPerformed, and listen to that event wherever interested.
    • Can use services to actually do things (perform calculations, retrieve/put data, etc.).

JavaFX has some very limited CDI in it, that one gets with building the UI via their xml files. I personally found it inadequate and took the same approach as with swing (guice+guava+services+actions).

Late edit.
Regarding look and feels: most people prefer the applications they run look and feel consistent with the other ones on their desktop. I too get annoyed at the lovely app that the dev with too much time on their hands decided for no good reason to make it "pretty", essentially making it "stand out", often breaking the guidelines for that particular platform.

Therefore, i recommend you use the system look and feel. Swing has a good windows xp replication, im not so sure on windows 7/8. So, your app will look a bit weird no matter what. But at least try to follow the ui guidelines for that platform as much as you can (the order of the OK, Cancel button on dialogs, should you have an Apply button somewhere, should you have a toolbar, etc.). Usually that's quite a bit of coding, and most people don't bother.

At the end of the day: whatever you do, it doesn't matter since somebody probably was worse. Hey, at least you cared enough to ask around :).


Volguus fucked around with this message at 01:22 on Jan 4, 2014

Smarmy Coworker
May 10, 2008

by XyloJW
I'm getting null pointers in Java in the weirdest spots and can't figure it out.

Here's the trace:
code:
java.lang.NullPointerException
	serv.functions.StringToIntArray(functions.java:35)
	org.apache.jsp.serv.eval_jsp._jspService(eval_jsp.java:91)
	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:403)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:347)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	org.apache.catalina.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:108)
Here's the code:
Java code:
	public static int[] StringToIntArray ( String text ) {
		String[] tArray = text.split(", ");
		// Each integer will be separated with this regex. This should be made clear on the page.
		
		if ( tArray.length < 1 ) {
			// If no information has been entered into the form it is possible for an array size of 0.
			// In that case, it is better to push an array with the number 0 so that it is caught and
			// failed by CheckDig.
			int[] test = {0};
			return test;
		}
		
		int[] numArray = new int[tArray.length];
		
		for ( int x=0 ; x < tArray.length ; x++ ) {
			int i = Integer.parseInt(tArray[x]);
			numArray[x] = i;
		}
		
		return numArray;
	}
Line 35 is the blank line beneath the first comment so this isn't a very helpful thing.

Can anyone point out where the problem might be occurring?

FateFree
Nov 14, 2003

Are you sure its not just the first line and the argument text isn't null? I'd bet thats the problem.

Adbot
ADBOT LOVES YOU

pigdog
Apr 23, 2004

by Smythe
Make sure the compiled version of the code is actually the latest, so the line numbers match the source. I, too, would guess the problem happens if text is null.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply