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
Volguus
Mar 3, 2009

supermikhail posted:

Oh, right. The only condition I'd like to monitor is that the textfield shouldn't be empty on losing focus when the user selects another entry from the list. I don't need the program to panic each time I completely rewrite the text.

I guess if nothing comes up, I could store the list's row on focusLost, check if it's empty and return to it.

Oh ok, i see now.

Wouldn't it be better to have an "Edit" button besides the list that would popup a dialog with the item information that the user can fill/update? It would make checking for invalid entries much easier. And (I believe) it would be somewhat more user friendly, in the sense that it provides the user with a clear action that they must take in order to update the data. And if the only thing a user can do is update some text, JOptionPane provides an easy way to get a text only dialog.
But i guess your way could work too, even if to me it sounds a bit clunky.

Adbot
ADBOT LOVES YOU

supermikhail
Nov 17, 2012


"It's video games, Scully."
Video games?"
"He enlists the help of strangers to make his perfect video game. When he gets bored of an idea, he murders them and moves on to the next, learning nothing in the process."
"Hmm... interesting."
I had a dialog in the previous version, and that seemed too slow there. The entries can have a lot of information which could be hard to display in the list, but right now I can arrow down the list pretty fast and see the information in a side-pane. Most of the editing is pretty secure, only the textfield is a bit of a snag.

Volguus
Mar 3, 2009

supermikhail posted:

I had a dialog in the previous version, and that seemed too slow there. The entries can have a lot of information which could be hard to display in the list, but right now I can arrow down the list pretty fast and see the information in a side-pane. Most of the editing is pretty secure, only the textfield is a bit of a snag.

Could a JTable be of any help then? You do have editors in a table. And can reject data easily enough.

LtSmash
Dec 18, 2005

Will we next create false gods to rule over us? How proud we have become, and how blind.

-Sister Miriam Godwinson,
"We Must Dissent"

I'm kinda stumped with a java project and could use some help. I've been moderately active in the Skyrim modding scene and stumbled into becoming the maintainer for a java API for manipulating skyrim plugin files. A number of other patchers have been written using this API and the problem is that when I fix a bug in the library the patcher authors have to rebuild and upload new versions of their programs. As its a hobby lots of patcher authors disappear from time to time so their patchers essentially stay broken.

In the starter patcher project the library's jar is packed into the distributable jar. I assume its possible to change it so the library is external and the patcher can look in a specific place for it. Then when I fix a bug a user could just keep using their existing patcher jars and update the library. How would I go about doing this? I'm using netbeans if it matters. Also are there limits on what changes I can make to the library without breaking existing programs?

Gravity Pike
Feb 8, 2009

I find this discussion incredibly bland and disinteresting.
Asking end-users to understand the process to the point where they suck a jar in the right place seems... messy. I don't think I understand the issue here well enough.

Are you providing a library that modders include in their own projects? Or simply an interface that they interact with? Is there anything that would cause their projects to run worse after one of your bugfixes than it did before?

LtSmash
Dec 18, 2005

Will we next create false gods to rule over us? How proud we have become, and how blind.

-Sister Miriam Godwinson,
"We Must Dissent"

Gravity Pike posted:

Asking end-users to understand the process to the point where they suck a jar in the right place seems... messy. I don't think I understand the issue here well enough.

Are you providing a library that modders include in their own projects? Or simply an interface that they interact with? Is there anything that would cause their projects to run worse after one of your bugfixes than it did before?

The library is a java API to make programs that generate patches based on the other mods the user has installed. The program I got into it with is one that reads all the mod added weapons and armors and makes enchanted versions that match vanilla enchanted items (since doing it by hand is a huge pain and nobody does it). So no matter what mods a user has the patcher will create a tailored plugin for them. The library I've taken over maintaining handles reading and writing the actual plugin files and exposing the contents as java objects.

The issue is the skyrim plugin files are rather sketchily understood so the library doesn't always do the right thing when a mod does something unexpected. I can fix the library but since its packed into each patcher a modder makes then those patchers have to be rebuilt for my fixes to apply. But modders come and go so quite a few patcher programs haven't been updated with bugfixes in over a year. Depending on the bug it means the patcher doesn't work at all if certain other mods are installed, or worse look fine but end up making corrupt plugins.

Patcher programs are already at the high end of the user competency scale and require being installed in the right place anyway. It should be possible to make the patchers look for the library up one directory level and then in the /library/ folder or something, right?

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
It might be worth looking at how other modding tools solve the same problem.

WeiDU (used for modding Infinity-engine games), for example, when you install a mod, it checks the version of the modtool used against the version used to install any existing mods - and if they don't match, it reinstalls all the mods using the newest version of the modtool. It can even repack the new version of the modtool into the setup program for the older mods. It seems like that should in principle be possible here as well.

Max Facetime
Apr 18, 2009

Compatibility is tricky and a big topic. Oracle has documentation explaining binary compatibility in Java, but this Eclipse wiki article Evolving Java-based APIs 2 goes really into the details. See also part 1 for a more general discussion of what compatibility looks like from both an API client's point of view and the API provider's viewpoint.

My Rhythmic Crotch
Jan 13, 2011

This thread is huge so apologies if this has already been covered but, has anyone ever had any luck re-configuring log4j to behave differently on a pre-built jar? It would look something like this:
code:
java -Dlog4j.debug -Dlog4j.configuration=log4j.xml -jar target/something.jar some_arg_1 some_arg_2
log4j.xml looks like this:
code:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="socket" class="org.apache.log4j.net.SocketAppender">  
    <param name="Port" value="4560" />  
    <param name="RemoteHost" value="localhost" />  
    <param name="ReconnectionDelay" value="60000" />  
    <param name="Threshold" value="DEBUG" />
</appender> 

  <root> 
    <param name="level" value="DEBUG">
    <appender-ref ref="socket">
  </root>
  
</log4j:configuration>
I'm spooling up a SimpleSocketServer to listen for the logs, like so:
code:
java -classpath ~/.m2/repository/log4j/log4j/1.2.12/log4j-1.2.12.jar 
	org.apache.log4j.net.SimpleSocketServer 4560 log4j-server.properties
(Edit: line break inserted in that command) The SimpleSocketServer appears to be working, as I can see that it's waiting for a client.

Is this even doable, or am I going to have to bake socket logging into the application? Thanks for any thoughts.

Kilson
Jan 16, 2003

I EAT LITTLE CHILDREN FOR BREAKFAST !!11!!1!!!!111!

My Rhythmic Crotch posted:

This thread is huge so apologies if this has already been covered but, has anyone ever had any luck re-configuring log4j to behave differently on a pre-built jar? It would look something like this:

Does the jar have a log4j configuration file in it? I would just extract what's in there, change what you want, then repack the jar with the new file.

Or you should be able to do it programmatically, which I've only done minimally before but I know the documentation is decent enough for that.

edit: Also, I've never done socket logging, so I'm not sure about anything related to that.

Beached Whale
Jun 27, 2009

The world as will and idea
Does anyone know of a good Java based email server that integrates well with Eclipse and outputs sent emails as a .html file, rather than a serialized .jmsg? We currently use JES, which is fantastic for all intents and purposes, but I've found it annoying to have to run a self-made script every time I want to convert an email from .jmsg to .html. If there's something out there that is similar in functionality but outputs .html that would be fantastic.

My Rhythmic Crotch
Jan 13, 2011

Kilson posted:

Does the jar have a log4j configuration file in it? I would just extract what's in there, change what you want, then repack the jar with the new file.

Or you should be able to do it programmatically, which I've only done minimally before but I know the documentation is decent enough for that.

edit: Also, I've never done socket logging, so I'm not sure about anything related to that.
Well, I am a huge dummy, the application is not using log4j :saddowns:

HFX
Nov 29, 2004

My Rhythmic Crotch posted:

Well, I am a huge dummy, the application is not using log4j :saddowns:

Is it using the even more awesome logback? However, I think by default both look jar local before looking at the local directory.

LtSmash
Dec 18, 2005

Will we next create false gods to rule over us? How proud we have become, and how blind.

-Sister Miriam Godwinson,
"We Must Dissent"

Max Facetime posted:

Compatibility is tricky and a big topic. Oracle has documentation explaining binary compatibility in Java, but this Eclipse wiki article Evolving Java-based APIs 2 goes really into the details. See also part 1 for a more general discussion of what compatibility looks like from both an API client's point of view and the API provider's viewpoint.

Ugh. That's a mess but thanks for the info.

My Rhythmic Crotch
Jan 13, 2011

HFX posted:

Is it using the even more awesome logback? However, I think by default both look jar local before looking at the local directory.
Negative, just java.util.logging

Lord Windy
Mar 26, 2010
Hey guys, ages ago I tried making a really involved game but due to my lack of experience/knowledge I could never work out how to manage memory correctly (trying to track millions of integers and strings, it turns out that quickly turns into gigs of ram when you don't save it to the hard disk and load when needed :P). At the time I just abandoned it because the only way I knew how to store data was in text files.

I decided to give another crack at it after I've worked on some simpler crap and I've realised I could just use a database like any business would. I found JDBC and it looks ideal, but I'm a little confused by how it works.

If I use MySQL or Java DB, will it just work normally when I distribute the JAR to windows/linux/mac computers or will I need to include something? And is one better than the other, or are they both the same. I hope this isn't too dumb of a question, I'm still pretty new when it comes to Java/Programming in general.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

Lord Windy posted:

Hey guys, ages ago I tried making a really involved game but due to my lack of experience/knowledge I could never work out how to manage memory correctly (trying to track millions of integers and strings, it turns out that quickly turns into gigs of ram when you don't save it to the hard disk and load when needed :P). At the time I just abandoned it because the only way I knew how to store data was in text files.

I decided to give another crack at it after I've worked on some simpler crap and I've realised I could just use a database like any business would. I found JDBC and it looks ideal, but I'm a little confused by how it works.

If I use MySQL or Java DB, will it just work normally when I distribute the JAR to windows/linux/mac computers or will I need to include something? And is one better than the other, or are they both the same. I hope this isn't too dumb of a question, I'm still pretty new when it comes to Java/Programming in general.

I'd go with SQLite if you want an easy to distribute self contained database to use in your application. I think it's sort of the de facto standard for this kind of thing.

Zaphod42
Sep 13, 2012

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

Lord Windy posted:

Hey guys, ages ago I tried making a really involved game but due to my lack of experience/knowledge I could never work out how to manage memory correctly (trying to track millions of integers and strings, it turns out that quickly turns into gigs of ram when you don't save it to the hard disk and load when needed :P). At the time I just abandoned it because the only way I knew how to store data was in text files.

I decided to give another crack at it after I've worked on some simpler crap and I've realised I could just use a database like any business would. I found JDBC and it looks ideal, but I'm a little confused by how it works.

If I use MySQL or Java DB, will it just work normally when I distribute the JAR to windows/linux/mac computers or will I need to include something? And is one better than the other, or are they both the same. I hope this isn't too dumb of a question, I'm still pretty new when it comes to Java/Programming in general.

Are you really sure that the game absolutely requires installing a database on client machines? That's probably going to have some drawbacks, although I guess I'm not sure of how minor you can make a DB install. Still, seems like overkill. Could you do it server side? Why millions of integers and strings?

I mean if Skyrim or Dwarf Fortress gets by without a database I don't know why you'd have to have one, unless you're making a simulation.

That said, yeah, JDBC should just talk to MySQL (though you'll have to use the mysql configuration stuff) but you'll have to have MySQL running as a service and everything on the target machine.

Zaphod42 fucked around with this message at 22:40 on Mar 7, 2014

Max Facetime
Apr 18, 2009

LtSmash posted:

Ugh. That's a mess but thanks for the info.

Yeah. Always adding to an API and never taking out or changing anything that's been out in the open for some time is reasonably safe if you also test that old no-longer maintained dependent projects don't break, but since you are also in essence a consumer of these old projects' "APIs" it starts getting interesting. You may be looking at providing one customized version of the library per each misbehaving plugin.

This doesn't have to be as bad as it sounds!

These one-off versions don't have to be public APIs you have to maintain, because they don't provide anything that the real public API doesn't already provide. This frees you to do things that you couldn't do with the public API. At the extreme one such version could contain a complete recompiled version of the plugin it targets, even.

Lord Windy
Mar 26, 2010

Zaphod42 posted:

Are you really sure that the game absolutely requires installing a database on client machines? That's probably going to have some drawbacks, although I guess I'm not sure of how minor you can make a DB install. Still, seems like overkill. Could you do it server side? Why millions of integers and strings?

I mean if Skyrim or Dwarf Fortress gets by without a database I don't know why you'd have to have one, unless you're making a simulation.

That said, yeah, JDBC should just talk to MySQL (though you'll have to use the mysql configuration stuff) but you'll have to have MySQL running as a service and everything on the target machine.

I did not realize that I had to install a database if I wanted to use it. A game I like, Aurora, was programmed in VB.net and uses an Access database for everything so I figured it would be easy just to do something similar with Java. I just assumed MySQL or Java DB would be a single database file that you could use JDBC to interface with.

There would likely be no issue with me just using text files ala Dwarf Fortress. It was just an idea I had last night that seemed very elegant that anyone could edit if they liked.

Volguus
Mar 3, 2009

Lord Windy posted:

I did not realize that I had to install a database if I wanted to use it. A game I like, Aurora, was programmed in VB.net and uses an Access database for everything so I figured it would be easy just to do something similar with Java. I just assumed MySQL or Java DB would be a single database file that you could use JDBC to interface with.

There would likely be no issue with me just using text files ala Dwarf Fortress. It was just an idea I had last night that seemed very elegant that anyone could edit if they liked.

H2 or HSQLDB are single file databases. Sqlite is a good choice as well, though for java probably one of the former ones would be more appropriate. JavaDB uses a folder to store its files (and it can have quite a few) and MySQL is a server (that the user would need to install and configure beforehand).

There's nothing wrong with using a database to store user data or preferences or ... whatever else you need, just know what you're getting yourself into and what you will be asking from users when they want to install your tool. A MySQL server for a single user program may be a bit too much to ask.

Lord Windy
Mar 26, 2010
H2 might be the way to go if I want to keep going down the path of a database. It looks like you can embed the database into the application itself through a 1.5mb jar file so the end user doesn't need to install anything.

But I did some reading up on Java and file loading, and an 8kb BufferedInputStream is surprisingly fast. 500ms to read a 100mb file. So I might write down what I want to do and make up a pro/con list.

lamentable dustman
Apr 13, 2007

🏆🏆🏆

The answer is XML obviously.

Lord Windy
Mar 26, 2010
I'm not reinventing the wheel with XML, sorry.

Gravity Pike
Feb 8, 2009

I find this discussion incredibly bland and disinteresting.

lamentable dustman posted:

The answer is XML obviously.

Is jokes!

XML is the wrong answer to basically every problem. The correct answer is probably "json," if you were tempted to use XML, but might be "a binary representation," if storage efficiency outweighs extensibility and human-readability.

Volguus
Mar 3, 2009

Gravity Pike posted:

Is jokes!

XML is the wrong answer to basically every problem. The correct answer is probably "json," if you were tempted to use XML, but might be "a binary representation," if storage efficiency outweighs extensibility and human-readability.

Ha, kids these days. Taking the one XML flaw (size) to the other extreme.
Json is mighty fine for a large number of applications, especially those that send data to the browser as the browser can right away start using the objects. But when you need things like validation or just simply documentation of your structure, json does everything in its power to get in your way, to the point of being better to just give up. Yes, there is such a thing as json schema (i now just googled it), but you have to put in serious effort to enforce it. Validation against an XML schema is done automatically by every XML parsing library out there. XML schema can and does serve as the contract between the consumer and the producer. No point in looking at your crap if it's not even valid.

Plus, with things like xpath and xslt one can extract information or transform it (respectively) without even needing to "look" at the XML. Makes working with XML easy and painless.

Point is: there are very many valid reasons to use XML over json (or yaml or other structured text formats). XML is the right answer to a ton of problems.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
"Serious effort" being "choosing to use a tool that enforces the schema", right? The same as what you have to do with XML?

It seems unusual to look at the mere existence of a non-validating parser as a downside of some sort. If I were to write an XML parser that didn't validate schemas it wouldn't somehow make XML worse.

Gravity Pike
Feb 8, 2009

I find this discussion incredibly bland and disinteresting.

rhag posted:

Validation :words:

That's a valid point (:D), although it's not enough to sway my distaste for xml. There are enough json validation options that I never really find myself missing it.

rhag posted:

Plus, with things like xpath and xslt one can extract information or transform it (respectively) without even needing to "look" at the XML. Makes working with XML easy and painless.

Since I work in the real world, what xml libraries do you use? Compared to, say, Guava Gson, I've never found xml libraries anything close to "easy and painless."

Volguus
Mar 3, 2009

Gravity Pike posted:

That's a valid point (:D), although it's not enough to sway my distaste for xml. There are enough json validation options that I never really find myself missing it.


Since I work in the real world, what xml libraries do you use? Compared to, say, Guava Gson, I've never found xml libraries anything close to "easy and painless."

I'm usually fine with the standard java libraries. Don't remember the time when i really needed to switch to something else (because feature X was not there for example). Now, easy or hard i suppose is subjective, I personally don't find this code hard:
code:
        JAXBContext context = JAXBContext.newInstance(MyElementRoot.class);
        Marshaller marshaller = context.createMarshaller();        
        StringWriter writer = new StringWriter();
        marshaller.marshal(rootElement, writer);
        return writer.toString();	
Creates an XML from a tree of objects starting at rootElement.

Or this one:
code:
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(xsltSource);
transformer.transform(xmlInput, myResult);
transforms xml to something else via xslt.

Yes, you'd have to write previously the entire document model for the first example to work, but you have to do that anyway if you don't want to work with the document nodes themselves (and that's true for json as well). And yes you'd have to write the xslt document for the second example to work.
With a json library, maybe you'd have fewer lines of code to accomplish the first task (minimum 2 i'd guess), but the second task would be impossible (possible via code of course, but that's not the point here).
This is not me arguing that XML is better than json or the other way around, but that XML has its use cases and json has its own. It is, in my opinion, better to be able to use both and to decide (based on the problem at hand) when to use which.

Plus all these transformations really don't even appear in the code (they shouldn't). Both a web service or a spring controller or a jee endpoint would have the marshalling and unmarshalling done for them (for both json and xml). So at the end of the day the developer only needs to work with objects and not worry about the format they got in or how they'll look when going out.

-Blackadder-
Jan 2, 2007

Game....Blouses.
I'm need some general help. I have a project where I'm using WindowBuilder. I already have a JFrame and some buttons, but I'm trying to figure out how to make a new window appear when I click on one of the buttons and then have WindowBuilder to read from a text file and display the contents in the aforementioned new window.

Woodsy Owl
Oct 27, 2004

-Blackadder- posted:

I'm need some general help. I have a project where I'm using WindowBuilder. I already have a JFrame and some buttons, but I'm trying to figure out how to make a new window appear when I click on one of the buttons and then have WindowBuilder to read from a text file and display the contents in the aforementioned new window.

I'm assuming that the other window you'd like to appear when you select the button is some different JFrame? For the button, you need to add some action listener which contains behavior that will create an instance of the other frame you'd like to display. You can pass whatever details you need to to the other frame by the frame's constructor. It'd look a little like this:

Java code:

...

/*
 * This example uses an anonymous class instance to define the behavior
 * of the button when clicked.
 */
button.addActionListener (new AbstractAction() {

    /*
     * This method will be invoked when the button is clicked.
     */
    @Override
    public void actionPerformed (ActionEvent arg0) {

        /*
         * Create an anonymous instance of the frame that's gonna read
         * and display whatever from the text file. The path of the text
         * file is passed to the frame through it's constructor as a String.
         * This assumes that the frame's constructor makes the frame initially
         * visible.
         */
        new TextFileReaderFrame("C:\\readme.txt");
        
    }

   });

...
WindowBuilder can help you design the frames but you're gonna have to test their behavior manually by building and executing your project or using test cases or implementing a main method or whatever.

edit: Also it's a bad idea to hard-code path names. You can give ClassLoader a try to load project resources.

Woodsy Owl fucked around with this message at 10:24 on Mar 14, 2014

My Rhythmic Crotch
Jan 13, 2011

Does anyone know of a Maven plugin which can generate "generic" documents? Basically all I want is to create a small XML document containing a list of certain classes. It would not end up in the jar, the XML file is needed for integrating into another system.

FAT32 SHAMER
Aug 16, 2012



I'm trying to build a GUI that has you enter elements to be stored in a deque, however I'm having some problems. I'm using the NetBeans GUI maker, for reference.

I need to use a list of commands to add and remove elements to the deque and then check the size and if it's empty or not. The best way I could come up with separating the command from the element being added is to split the inputted string in two, then set String command = tokens[0] and String element = tokens[1]. I'm not sure why, but when the element gets added to the deque, it seems to be replacing the previously added element or creating a totally new deque. Also, before i decided to set command = tokens[0] and element = tokens[1], size and isempty both worked as commands, but only spat out 0 and true, but now when I try to use them in the GUI they don't do anything at all. All this code is in the Button1ActionPerformed listener




Java code:
package DEQ;

import java.util.LinkedList;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 */
public class GUI extends javax.swing.JFrame
{

    /**
     * Creates new form GUI
     */
    public GUI()
    {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents()
    {

        jInternalFrame1 = new javax.swing.JInternalFrame();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextArea2 = new javax.swing.JTextArea();
        jButton1 = new javax.swing.JButton();
        jTextField2 = new javax.swing.JTextField();
        jInternalFrame2 = new javax.swing.JInternalFrame();
        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jInternalFrame1.setVisible(true);

        jLabel2.setText("Command Result: ");

        jLabel3.setText("Command:");

        jTextField1.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                jTextField1ActionPerformed(evt);
            }
        });
        jTextField1.addKeyListener(new java.awt.event.KeyAdapter()
        {
            public void keyPressed(java.awt.event.KeyEvent evt)
            {
                jTextField1KeyPressed(evt);
            }
        });

        jTextArea2.setColumns(20);
        jTextArea2.setRows(5);
        jScrollPane2.setViewportView(jTextArea2);

        jButton1.setText("Enter");
        jButton1.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jInternalFrame1Layout = new javax.swing.GroupLayout(jInternalFrame1.getContentPane());
        jInternalFrame1.getContentPane().setLayout(jInternalFrame1Layout);
        jInternalFrame1Layout.setHorizontalGroup(
            jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jInternalFrame1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jInternalFrame1Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField2))
                    .addGroup(jInternalFrame1Layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton1))
                    .addComponent(jScrollPane2))
                .addContainerGap(26, Short.MAX_VALUE))
        );
        jInternalFrame1Layout.setVerticalGroup(
            jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jInternalFrame1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1))
                .addContainerGap(27, Short.MAX_VALUE))
        );

        jInternalFrame2.setVisible(true);

        jLabel1.setText("Available Commands:");

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jTextArea1.setText("addfront element\naddrear element\nremovefront\nremoverear\nisempty\nsize");
        jScrollPane1.setViewportView(jTextArea1);

        javax.swing.GroupLayout jInternalFrame2Layout = new javax.swing.GroupLayout(jInternalFrame2.getContentPane());
        jInternalFrame2.getContentPane().setLayout(jInternalFrame2Layout);
        jInternalFrame2Layout.setHorizontalGroup(
            jInternalFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jInternalFrame2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jInternalFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 212, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(49, Short.MAX_VALUE))
        );
        jInternalFrame2Layout.setVerticalGroup(
            jInternalFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jInternalFrame2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(17, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jInternalFrame1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jInternalFrame2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(49, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jInternalFrame2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addComponent(jInternalFrame1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 9, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>                        

    private void jTextField1KeyPressed(java.awt.event.KeyEvent evt)                                       
    {                                           
  
    }                                      

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)                                         
    {                                             
        LinkedList que = new LinkedList();
        String input = jTextField1.getText().toString();
        
        String delims = "[ ]+";
        String[] tokens = input.split( delims );
        String command = tokens[0];
        String element = tokens[1];
        
        
        if( command.equals( "addfront" ) )
        {
            que.addFirst( element );
            jTextField2.setText( element );
            jTextField2.selectAll();
            jTextArea2.append( que + "\n" );
        }
        else if( command.equals( "addrear" ) )
        {
            que.addLast( element );
            jTextField2.setText( element );
            jTextField2.selectAll();
            jTextArea2.append( que.toString() + "\n" );
        }
        else if( command.equals( "removefront" ) )
        {
            que.removeFirst();
            jTextArea2.append( que.toString() + "\n" );
        }
        else if( command.equals( "removerear" ) )
        {
            que.removeLast();
            jTextArea2.append( que.toString() + "\n" );
        }
        else if( command.equals( "isempty" ) )
        {
            que.isEmpty();
            String str = String.valueOf( que.isEmpty() );
            jTextField2.setText( str );
        }
        else if( command.equals( "size" ) )
        {
            jTextField2.setText( String.valueOf( que.size() ) );
        }
        else
        {
            jTextField2.setText( "Invalid Entry, try again." );
        }
        
        jTextField1.selectAll();
        jTextArea2.setCaretPosition( jTextArea2.getDocument().getLength() );
        jTextField1.setText( "" );
    }                                        

    private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt)                                            
    {                                                
        jButton1ActionPerformed( evt );        // TODO add your handling code here:
    }                                           

    /**
     * @param args the command line arguments
     */
    public static void main(String args[])
    {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see [url]http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html[/url] 
         */
        try
        {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels())
            {
                if ("Nimbus".equals(info.getName()))
                {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex)
        {
            java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex)
        {
            java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex)
        {
            java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex)
        {
            java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable()
        {
            public void run()
            {
                new GUI().setVisible(true);
            }
        });
        
        
    }

    // Variables declaration - do not modify                     
    private javax.swing.JButton jButton1;
    private javax.swing.JInternalFrame jInternalFrame1;
    private javax.swing.JInternalFrame jInternalFrame2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextArea jTextArea2;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    // End of variables declaration                   
}

Now, when I print the deque to command line instead of to jTextArea, it prints out the correct format
Java code:
import java.util.LinkedList;
import java.util.Scanner;

public class Test
{
    public static void main(String[] args)
    {
        LinkedList list = new LinkedList();
        Scanner input = new Scanner(System.in);
        
        System.out.println( "how much stuff do you want to enter?\n");
        int number = input.nextInt();
        
        
        for( int i = 0; i <= number; i++ )
        {
            System.out.println( "Please enter some stuff:" );
            String stuff = input.nextLine();
            list.addFirst( stuff );
        }
        System.out.print( list + "\n" );
        System.out.print(list.isEmpty() );
    }
}

I'm sure I'm doing one tiny thing wrong and that's what's loving it up but I'm not really sure what it is.

Spatial
Nov 15, 2007

Are you sure you didn't mean to post that in the coding horrors thread?

FAT32 SHAMER
Aug 16, 2012



Spatial posted:

Are you sure you didn't mean to post that in the coding horrors thread?

Yeah, it's pretty bad :ohdear:.

FAT32 SHAMER
Aug 16, 2012



Welp I figured it out: I didn't make the LinkedList variable a class-wide private variable so every time the method was executed it was creating a new variable.

Gaze that abortion of code and shame me

Woodsy Owl
Oct 27, 2004

Tusen Takk posted:

Gaze that abortion of code and shame me

Nah man, sometimes you just gotta prototype out your idea and then you can go back and polish your code. Don't sweat it.

FateFree
Nov 14, 2003

Tusen Takk posted:

Gaze that abortion of code and shame me

Your code would have been ten times more readable if you just gave your labels and inputs actual names instead of label1, label2. Aren't you just forcing yourself to memorize what these things mean when you modify your code? Think about how much easier it would be if they were named commandTextField and commandLabel.

And use imports for cryin out loud haha. You'll remove 30% of your code if you remove javax.swing everywhere.

Edit: nevermind looks like you are using something to auto generate terrible code.

FateFree fucked around with this message at 14:17 on Mar 15, 2014

Boot and Rally
Apr 21, 2006

8===D
Nap Ghost
I also have a NetBeans questions, I am a total JAVA newb, I am sure it will show.

I have selection of JAR files I have acquired from the internet and I wish to add to my Library in NetBeans such that I can use them all from one location for any project I desire. I've done the usual (right click) -> Properties -> Libraries and added the JAR files to the Run and Compile Sections. This does nothing, NetBeans doesn't find the classes and the program errors (cannot find symbol).

---EDIT: this doesn't work, it looks like it does, but it doesn't.
If I manually copy everything from where I want them to the netbeanscrap/project/src/ folder it does work. This seems insane to me, it means I will have 6+ billion copies of my JAR files floating around for every project that I have to constantly monitor and update whenever I change the original jar file.
-----

Is there a way to add something to the netbeans library that actually adds it to the library, without having to copy it to each project directory? I mean such that it can find the class I am looking for and adds the appropriate import line (the internet claims it should do this already).

Edit 2:

If I manually add the imports it seems to work. I am still not sure why NetBeans doesn't do this and why autocomplete doesn't work. Everything I've read indicates that it should.

Edit 3: I solved my problem by not using poo poo code from other people.

Boot and Rally fucked around with this message at 02:41 on Mar 17, 2014

Adbot
ADBOT LOVES YOU

supermikhail
Nov 17, 2012


"It's video games, Scully."
Video games?"
"He enlists the help of strangers to make his perfect video game. When he gets bored of an idea, he murders them and moves on to the next, learning nothing in the process."
"Hmm... interesting."
I wrote a thing:
code:
@Override
    protected void processKeyEvent(KeyEvent e) {
        if (e.getID() == KeyEvent.KEY_PRESSED && isEditable()) {
            int keyCode = e.getKeyCode();
            String keyText = KeyEvent.getKeyText(keyCode);
            switch (keyText) {
                case "Left":
                case "Right":
                case "Home":
                case "End":
                    super.processKeyEvent(e);
                    return;
            }
[...]
For this overcomplicated program I'm making I couldn't find the keycodes for numpad left and right, but I discovered that they have the same text as the regular arrows. So, this is my best idea right now. I suspect just reading the keycodes wouldn't work if I moved to a different computer (arrow right is 39 here and numpad right is 227).

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