Jump to content
  • Advertisement

Elehisie

Member
  • Content Count

    74
  • Joined

  • Last visited

Community Reputation

133 Neutral

About Elehisie

  • Rank
    Member
  1. ever heard of setActionCommand("command") method? instead of doing that, you can have a single actionPerformed handle handle all of the buttons in a JFrame. trust me... i have over 90 buttons for a quizz thingy and all of those need to do the same thing: parse a string to a certain var. so i just set the same action command for all of them :P and the same actionperformed handle handles my exiter button, and all other buttons... all i have to do is to search the command in a list object, get its index and use the index in a switch statement. sweet.
  2. ive always been pretty hands on and "ill do it myself"... and often i came up with better solutions, over a time... but this time ive been feeling like "reinventing the wheel" all the time to tell you the truth... I know I CAN do a robust engine... but at what cost? i guess that pretty much settles it :) im gonna go for the engine this time, at least until i can make a living out of games ... then i can make my own engine from scratch and i guess its not a bad decision, right? if i learn to accept the engines limitations... thx guys! I guess the decisive opinions were about reinventing the wheel and *using it* rather than *fighting it*
  3. ive been coding my game engine in java, and its been a looooong road. mainly cuz i have to get paid to live, and so i got stuck in a dilema: keep my current paying job (3D modeling in a big industry and pretty good paycheck) or go for hunting an investor so i can dedicate myself exclusevely to my game. why quit my job? cuz based on the current progress I can make on my free time, its gonna take MANY YEARS until the game release :P well i ran into a few engines... they all seemed to lack something, then I found Kaneva, and it pretty much seems to be IT. my personal gold mine. then... with kaneva i can start the "game-making" right now, instead of making up the engine first. it has all i wanted to add, looks pretty stable and they offer big advantages for an affordable price. im stuck with this doubt: if i gofor it, i have a pretty good start out right now, but ill always be stuck in what the engine has to offer, when if i make my own engine, I mod it freely, adapt it if needed be, but it takes freaking LONG. so how many of you guys coded from scratch and how many went for ready-made engines?
  4. your source file can also contain non-public classes that are not nested in other classes (default to protected). [\quote] exactly.... i have loads of "protected static" things Son of Cain: I have the Deitel book... Didnt like it very much actually. Ive found out that the docs in java.sun.com are better in some points. Deitel pretty much explains what he likes to use, in the way he likes to use... Quote:Delphi is a RAD tool, so it has several disadvantages compared to OOP with Java or C++dont call me "dude" :P Im a girl!! GIRL!! but yeah... ive always beens a Delphi freak... cuz their IDE is so.... "lemme do everything for you".... but one day I went for Java ... never got really serious in C... but when i went for Java, I divorced from Delphi :P I saw the light :P ive always missed a few things from the borland-like IDE... (deugging can be awfull when youre usin notepad to type your java files... try counting lines up to 55 to find where the error came from....) tried JCreator (java tool from borland) and it stinks.... then I found out about Eclipse, and it was love at first sight! LOL :)
  5. ive been thru a lot of the tuts in java.sun.com, and they are all very basic (and i mean too very basic) or really not deep enough (imo). ---> well im gonna search for some good designing resources later :) (when im not at paying job) for now, i really appreciate the attention, guys! (and that "best practice" thing really explains why some code ive been running into looks so incomplete)
  6. Quote:Hmm, sounds to me like your not too familiar with the whole point of OO programming. I have good knowledge of OO programming... but as i said, my OO backgrounds come from Delphi. the bad part is the "lybrary building" part in delphi is very automated, as it automatically picks which part goes in which file, and you dont have a lot of freedom when building, and this "lack of freedom" from delphi killed my ability to "design well" in Java, when i have to define those things on my own, and i have enough freedom to design as I want. besides, im an electronics engineer. i didnt have good programming skills subjects at university, as it wasnt oriented in software building... so all my programming knowledge, or at least 95% of it comes from teaching myself. the result is that even if i have good knowlegde of OO design, I dont use any "academic approach" when designing. (which i recognize as very bad, and am trying to change). but most of time, if it compiles, im satisfied with it. i dont build code for any company atm... i code for my own fun, more likely, and i have fun building games :P whenever a "professional programmer" sees my codes s/he will act like: "ewwwwww does that sh*t even compile??" :P Quote:I'm afraid to ask, but... How many classes do you have? And of them, how many are nested classes? hmm i wont show the code here,ok? this app is more or less some "experiment" for my mmorpg. like: ive come up with code that works in the manner i want it to work, but it recently looks ugly, is disorganized, and its really not presentable in the programming community. but after all, it runs, and it has shown good performance so far. but when i go for a final version, i want to look "properly" I currently have: 4 classes, 2 of them have no more than 4 nested classes, and the nested classes have no nested classes. in those 4 classes i have at least 8 methods in each, plus 3 or 4 methods that arent in any class, as they are "common" to 2 classes. I have 3 GUI-generating methods that return JComponents,and display on the same JForm, due to run-time changes in the GUI. all of them implement "ActionListener" and theres is only one "ActionPerformed" method thats common for everything that implements "ActionListener". the same goes to the other listeners I have: "focusGained", "focusLost", "valueChanged" and "propertyChange" listeners. as i know that Swing has issues around "thread safety" and I do run at least 2 threads at a time, i run mostly everything thru the event dispatching thread. but only one of the threads displays a GUI (made of swing components), the others are server conenctions listeners/parsers, and display the stuff they need on a JTextArea, when needed be. well... i know this will be scary for you guys, but my "import" section goes like: import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; import java.awt.print.*; import java.io.*; import java.nio.*; import java.nio.channels.*; import java.nio.charset.*; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeEvent; import java.util.*; import java.text.*; import java.util.AbstractList; and yeah, i do know its getting too big!
  7. this may sound odd for some... (but as im natively a pascal coder...) yeah thats right, my very first language was pascal, followed by delphi, c, c++, java. i took a look into C#, but never went into it. in pascal, youd want to create "unit" files when your code was longer than 3000lines. (the compiler was unable to compile more than 3000 lines at a time). in delphi, it would automatically put every form source in a different file, and even if you wanted, you couldnt have it in the same one. and you would create .dll files when you have different projects running the same routines. in C in general from what ive seen, it really depends on the programmer... ive encountered a few whod split everything, and some whod always make huge single files... now that you know my backgrounds, re-read the title: when is it the right time to split a single .java into packages and interfaces? what i mean is: how better for performance would it be? (not thinking about team related stuff, as im the only coder in my team haha) my only real reason to go thru the trouble of splitting the code: - its a damn long file right now, where i tried to follow a logical sequence for ordering variables, objects, swing components, classes and methods, but as it does a lot of nearly-unrelated tasks atm... IE: accessing files in disk, communicating with a server, warning pop-ups for the users, generating parts of the GUI from users responses in real time, not to mention a complex GUI, with a few different JFrames, and many different "states" of the main JFrame, according to what task the user may be executing... and a HUGE "import" part... importing many many many many packages... you have to admit that to have all that in the same file is ugly-coding... and... well its becoming hard to manage. as in: when i have to scroll up to this *specific* part of the code, finding variables, blah blah... but i do have some static methods, and i use a single "action performed" method to manage all gazillions of buttons, and this is managed by a "command list"... now, having them in packages: - will performance be the same? - will i need to add all package files into the "instalation" dir (like needing to have a few .jar files in the same dir as the main executable) - is there any REAL advantage of having a few different packages rather than a single file? (the organizing part wont count as advantage, ok? cuz despite it being hard to manage, its not impossible to have an organized code in a huge file) -would it be faster to have the fired actions for the buttons run from different packages rather than iterating thru a list using a switch?
  8. Elehisie

    [java] Vectors in Java?

    hey guys! my question fo rtoday seem to be kinda related to this, so here it goes: the constructor for JTable takes only (Object[][] rowData, String[]columnNames) or (Vector rowData, Vector columnNames) as arguments. my problem is... im trying to build a table for a txt file in disc. I open the file, and for every line in the file I want to make a row in the table. the file is of the form: thing11,thing12,thing13,thing14 thing21,thing22,thing23,thing24 so the table should display: thing11|thing12|thing13|thing14 thing21|thing22|thing23|thing24 so, in plain text, what I do is: - open the entire file and coping it over to a DefaultListModel type var. - get every element from the list (which corresponds to every line in the file) and split it in a String[] so I can get the values in an indexeable manner. - then i copy the String[] onto a Vector (named row), and this one holds the values for every column, for only 1 row. so far so good. - then i made a second Vector, to hold all the rows. (named data) - then for every line in the file, I add an element in the tableData Vector. then I build the table: JTable table = new JTable(data, columnNames); it all works swiftly... except... as Vectors are actually POINTERS, not variables, the data Vector will show the same things in every element, which reflects the last change in the object which the rowValues Vector point at, menaing: the last line of the freaking file. so if my damn file has 12 lines, the table WILL show perfectly on screen, but will contains 12 times the last line in the file. ive tried to substitute the row Vector into a number of other kinds of indexed variables, like arrays, lists, objects, etc... and it works to the point that the data Vector manages to be filled with contents. However, for a type mismnatch or some other stupid reason, I get a fatal exception when trying to build the table, for the constructor gets unable to split the elements in data into the same number of columns given by the columnNames Vector. do you guys think of a workaround for this? like: i tried to use a String() with the contents for every cell separated by commas, as it shows like that when i convert the tableData Vector into String(), and i still get the same exception when building the table. the only way to build the table nicely is using those vectors, but then, how to make every line of the table reflect a line from the file? heres the chunk of code: (please pay attention to the stuff I write as output (System.ou.println()) and the pasted actual output from the command prompt when i run the routine) Vector columnNames = new Vector(); columnNames.add("Data"); columnNames.add("Designer"); columnNames.add("Livro"); columnNames.add("Ano-Modelo"); columnNames.add("UPC"); columnNames.add("Folha"); String[] splittedData = {""}; System.out.println(allLines.getSize()+" linhas"); int counter = 0; int counter2 = 0; Vector data = new Vector(); Vector row = new Vector(); row.add("Data"); row.add("Designer"); row.add("Livro"); row.add("Ano-Modelo"); row.add("UPC"); row.add("Folha"); for (counter=0; counter < allLines.getSize();counter++) { splittedData = allLines.elementAt(counter).toString().split(","); for(counter2=0;counter2<6;counter2++) //get only the last elements of splittedData { switch(counter2) { case 0: row.setElementAt((splittedData[(splittedData.length-1)-counter2]).toString(),counter2); break; case 1: row.setElementAt((splittedData[(splittedData.length-1)-counter2]).toString(),counter2); break; case 2: row.setElementAt((splittedData[(splittedData.length-1)-counter2]).toString(),counter2); break; case 3: row.setElementAt((splittedData[(splittedData.length-1)-counter2]).toString(),counter2); break; case 4: row.setElementAt((splittedData[(splittedData.length-1)-counter2]).toString(),counter2); break; case 5: row.setElementAt((splittedData[(splittedData.length-1)-counter2]).toString(),counter2); break; } } data.add(row); System.out.println(counter+" "+data.elementAt(counter)); } //TODO: setup table //JTable table = new JTable(data, columnNames); for (counter=0;counter < data.size();counter++) { System.out.println("data contents: "+counter+" "+data.elementAt(counter)); } ------------------- cut here 8< --------------------- goddamn output: 2 linhas 0 [29/11/2005, 08, 1A2B, 5A, Camila Paschini, 2005] 1 [30/11/2004, 1.1, 1A1A, 54, Alberto Gil, 2006] data contents: 0 [30/11/2004, 1.1, 1A1A, 54, Alberto Gil, 2006] data contents: 1 [30/11/2004, 1.1, 1A1A, 54, Alberto Gil, 2006]
  9. Elehisie

    [java] A noob Java question...

    i personally like to not draw on the JFrame directly... and when it comes to repaint events, JFrame is again kinda buggy, as in not being thread-safe... so youll want to use some eventlisteners to actually draw on screen, to make sure you alwyas draw from the event-dispatching thread...
  10. cool game :D those bunnys look like the bunny from sam and max kinda...
  11. Elehisie

    [java] string manipulation

    hmm that does look more clever... i started with q and b as separators for debugging reasons... then they just stayed there... OBS: "hmm so thats how split works...."
  12. Elehisie

    [java] string manipulation

    ah ^^ i see it now thx thx! ^_^ -- i never find this "right to the point topics" when im searching java.sun.com ...
  13. hello guys! Im writing some code to handle a gazillion buttons from my swing gui. so... i set the "ActionCommand" property in each of the buttons in a way that i can see right away which button was pressed. so far so good. I get strings of the form: "qxby" where x can go from 1 to as many "questions" there are and y can be only 1, 2 or 3. q refers to "question". every "question" is composed of 3 radio buttons (yes, no, maybe). and b refers to the radiobuttons, as answers for the questions... so if you click on "maybe" radio button that goes with the "question number 28" the string will be: "q28b3" i want to store all answers in a list, making the index in the list match the number of the question. ok? so answer[5] is the answer for the 6th question, and i can get its value by doing: answer.getElementAt(5). so far so good... its just im having trouble indexing right. why? cuz there must be as many positions in the list as questions, but i have a lot more radiobuttons, for every question has 3 radiobuttons. so every time a radiobutton is clicked, i need to store an answer. but the index of the answer list aint the same as the radiobutton's index. are you following? i also have a "commandslist" which i use to index the radiobuttons. the commands list goes as: 0 q1b1 1 q1b2 2 q1b3 3 q2b1 4 q2b2 . . . and the answer list would go like: 0 Y --> answer for first question, meaning Yes, or the radiobutton b1 1 Y 3 N 4 M . . . so i cant use the same var to index both lists, as one has far more elements than the other. i guess you get the idea. so, to make sure i get the proper index, and store the answer in the right position in the answer list, I want to read the number of the question from the ActionCommand string. so, inside the ActionPerformed method, i can get my "event.getActionCommand()" and it will read something like "q29b2" so... whats left to do: strip the "garbage" from that string, making it "29" so i can properly convert it to a int. like: removed --> q / 29 / b2<-- removed how would my event.getActionCommand().subString(xxxxx) statement go? i figure i need 2 of them? i suck on string manipulation and if there are better ways to do it.. be my guest :D
  14. hi all! ok... lets say I have a JFrame, with a JScrollPanel in it. In the JScrollPanel, I put a few JRadiobuttons. Theres a button called "save" too. I grouped the radiobuttons and all. how do I check to see which one of the radiobuttons is selected when the user presses the "save" button? I made an event handler on the button, through which I want to check the state on everyone of the radiobuttons. it seems pretty simple, but the question is... how do I get to the state of thge radiobuttons? cuz I made a method to create the gui for me: private static void createAndShowGUI(boolean isWeld) {//code here } and all the component declarations are inside that method. so how do I get to it? I mean... is there some way to refer to a component inside a component properly, maybe something of the kind: myFrame.myScrollPanel.radioButton1.isSeleted(); that i can use from OUTSIDE of the method createAndShowGUI ?? god i think its confusing... hehe
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!