Hot answers tagged

28

Yes, it is entirely realistic - not many people seem to be doing it yet but I think that is only a matter of time (Clojure is pretty new after all!) I've personally written an open-source game in Clojure which runs as a Swing application (https://github.com/mikera/ironclad) so have some experiences to share which may be useful. On average you probably want ...


22

This is all very subjective as multiple different technologies will be able to serve your needs. Like others, I'll probably just recommend the technology I'd personally prefer for such a project, which would be JavaFX. Reasons I would recommend JavaFX are: In-built properties and binding make it easy to wire up parts of your GUI for automatic updates. ...


18

Maybe you're too young to remember when programming without layout managers was more common. Either you had to fix your screen at one size, which worked great unless you actually needed to share your application with someone who used a different screen resolution, or you had to deal with scaling that looked really bad. Part of the problem is what you might ...


13

You question is three-fold: 1. How many classes are too many? While there are some guides on some metrics like how long should a method be or how many parameters can a method have, there are no such metrics as to how many classes should a system have as a maximum. IMHO it's not so much the amount of classes that create complexity as it is the fact of ...


9

Other toolkits have equivalent concepts (e.g., Tk has geometry managers) as well, and they are absolutely central to having a GUI that is not fixed at one exact size. That matters when: you have fonts that can change in size for accessibility reasons, or you have different sizes of screens, or you have resizable windows, or you have variable amounts of ...


7

You seem to have the dependency between your Model and your View the wrong way around. A Model does not know about the existence of a View, at most the model knows that some other component in the system might want to know about changes to the model. In the MVC pattern, either the Controller informs the View that it should update itself, or the View asks ...


7

When the run() method of that new thread finishes, aka the thread finished it's job. Does it delete itself? Or does it keep existing in the memory? It mostly deletes itself. The native thread (OS resource) is typically1 destroyed, and the thread stack memory segments (OS resource) are typically deleted. The thread's thread-locals map, the runnable and ...


7

There are actually multiple ways to reduce the size of .jar files. If you really need to reduce the size of .jar file without dropping some content, I would recommend trying the following two automated tools. Compression Perhaps the easiest way is to use a different tool to create the .jar file than the standard jar distributed with the Java SDK. KZIP is ...


6

What I would like to be able to do is jave a simple JFrame and then for each component (like JLabel) simply specify X and Y coordinates where I want it to be situated -- done deal. You can do that with null layout: jPanel.setLayout(null); jLabel.setBounds(5, 5, 200, 300); jPanel.add(jLabel); jFrame.add(jPanel);


6

You're asking the wrong question. It's not "better to have everything crammed into the main class", nor is it "better to have a lot of classes". When we distance ourselves from such attempts at generating rigid rules to cover all cases, we arrive at a much better approach: abide by widely-accepted design principles, such as those embodied by SOLID, and we ...


5

Go with a Model-view-presenter pattern instead. You can view a good MVP example in Swing here via the mvp4j project. While not Swing, I'd also check out the MVP articles over at the GWT Google Developers site for further insight on this pattern and how to apply it in Java; the same design principals stand regardless of the framework and GWT is very similar ...


5

Consider using MigLayout. It's a comprehensive layout manager that I haven't had any issues with. To get an initial taste of what it's capable of and how easy it is to use, look at the sample application linked to from the home page. Make sure you try resizing the window to see how the user interface is able to adapt to the size of the screen. The core ...


3

Between your two options having the view know about your "logic" class would be the better method. This would allow you to create or modify your view without having to change your logic classes. If you put your view inside of your "logic" classes it dramatically limits your flexibility. As people mentioned in the comments read up on the MVC pattern as ...


3

Your design doesn't really violate the Observer pattern, because the pattern does not specify how subscribers get registered with the publisher. But you are violating the Single Responsibility Principle for those middle panels, because they are given the added responsibility of helping in getting the message tray subscribed. A better design would be to use ...


3

Java language "philosophy" is WORA: Java is ...intended to let application developers "write once, run anywhere" (WORA), meaning that code that runs on one platform does not need to be recompiled to run on another. Explanation for default given in Swing tutorial (Available Look and Feels) looks consistent with above: CrossPlatformLookAndFeel — this is ...


3

Swing listeners are the typical example for inner classes, possibly even the reason that language feature was added. So go ahead and implement it like that. From the design perspective, the action listener behaviour is really part of the form.


3

All you need might be a conditional breakpoint. Both Netbeans and Eclipse allow you to edit properties of a breakpoint by right-clicking it and add a condition (a piece of code) that the debugger will evaluate every time it reaches the breakpoint, and stop only of the condition is true. In your case the condition would be some string that identifies the ...


3

While the new JavaFX versions look very impressive, I doubt it is worth doing a full migration unless you are willing to invest a lot of time / effort / money in a complete overhaul of the GUI. Swing may have its quirks and is showing its age but also it has some advantages: Very strong cross-platform capability, currently much better than JavaFX It's ...


3

What does it mean to say that, class JButton or class JRadioButton is-a class Container? The reason why all Swing components are derived from java.awt.Container is mostly for practical reasons which are internal to the implementation of Swing. AWT and Swing usually will not be mixed. But internally, a Swing component might realize itself using more than one ...


3

Using SwingUtilities.invokeLater() is not merely advantageous, it's essential, but to understand why you need to understand Swing's threading model. Updates to the GUI, via Swing, must occur on the Event Dispatch Thread (EDT), and code that does anything else (e.g. accessing some resource such as a database) should use one or more other threads. ...


2

Swing is a great GUI framework, probably the most purely OO GUI framework out there, so while it is not a core part of Java, it is an excellent thing to learn if you want to build quality applications. There is plenty of chances to implement design patterns such as decorator, MVC etc. The alternatives are SWT, and C#.


2

The widgets that you require can be found in both Swing or SWT. The documentation contains examples of components (Swing) or widgets (SWT) so it will be fairly easy to identify them. Swing is GUI library included in JDK and built from scratch. SWT is an external one and the components are based on native ones. As for MVC, they both have support for it. In ...


2

Well, Swing need layout manager because its supposed to be cross platform, and thus will render components of different size on different platform. By using math rule to line elements it make it much more portable. By the way, if you want good control over the placement while still remaining fluid, you can check GroupLayout. Its not perfect, but it give you ...


2

Swing developers should know the basic layouts and master at least one powerful layout. MigLayout is one such tool. The problem then becomes, "When should I use a powerful layout?" The answer is "When no simpler one will do." Use simple layouts when possible. Nest simple layouts for more complex effects. Isolate complex layouts, such as GroupLayout and ...


2

I did a lot of Swing programming in the late 90's, but I don't do very much nowadays, so I don't know if it's still an issue or not. It used to be the case that if you used a native look and feel, you'd occasionally run into layout issues when you ran it on another platform, due to slightly different control proportions and such. Using the default metal ...


2

I refrain from including validation in my data model objects. I make them very simple POJOs that don't have any knowledge about the content of the values, business logic that drives them, and the state of the application. I've create verification classes that are separate from both the controller and the data model. These are used during the import of data,...


2

There's functional reactive programming. The idea is to turn time-varying entities into first-class objects. Suppose we're dealing with a mouse cursor, and we want to draw an icon 10 pixels to the right of the cursor. Imagine that there was a type TimeVarying<T> that represents a value that changes over time. TimeVarying always magically contains the ...


2

In general, SOLID principles are usually met (See Snowman's answer) But since you mentioned the Android SDK, I will go a little into detail on how SOLID principles coming too short in this particular API. Single responsibility principle. The View class is responsible for positioning drawing event processing handling a huge load of other callbacks. So, ...


Only top voted, non community-wiki answers of a minimum length are eligible