Quote:
I've read the layout manager section already but I still found it difficult to get them the way I want.
How are you trying to set up the GUI? Can you post a picture of the desired layout?
Quote:
In my opinion, it's more interesting to write a GUI.
If you disagree, please say so.
Oh, I agree, but it significantly increases the learning curve because not only do you have to learn Java syntax, but you also have to learn the intricacies of GUI coding.
Quote:
I've learned php for about a year so I know the basics about programming (quite similar syntax) and I wanted to make something that looked like a "program", it's hard to explain.
Coming from a PHP background means that you will have to unlearn some habits in order to do proper Java coding. I'm not that familiar with PHP but I believe that as a scripting language, it's a little looser with type checking. I know that OOP capabilities are now part of PHP, and I'm not sure how much of this you are using, but they are a cornerstone of Java programming (and thus one of my reasons for recommending against use of static type unless absolutely necessary).
Quote:
I assume that a command line application only uses the print function to show things?
If so, I don't see the point of it because I already know the basics.
But do you know the basics of OOPs, the use of Java interfaces, the use and structure of generic types, design patterns such as the observer pattern and the MVC pattern, etc...? I see these things as more important than GUI programming.
Quote:
Do you have any recommandations about the parts I posted?
It may seem like overkill, but I try to put a little MVC in any GUI if at all possible. The sooner you learn how to do this, the better off you'll be. You may be using Swing now, but in the future, your GUI may be something completely different, and so if you learn to separate out the logic portion of your program from the GUI, you will learn to create programs that are more flexible, robust, and potentially longer-lived than otherwise.
Other recommendations:
1) Go through the Sun Swing tutorials for the best overall education in Swing programming. It is pretty well written and has lots of decent sample code.
2) Specifically, I would again recommend against use of static variables unless you know why it should be static in a particular place. Using non-static classes will make your code more reusable and flexible.
3) I would avoid making your class fields public and allow other classes to directly manipulate them, but instead strive to keep them private. Instead have your constructors do more, have your classes hold public methods that allow outside classes to interact with the class but in a limited and controlled way.
4) Gear your Swing code towards creating JPanels more than JFrames or JApplets. JPanels can be placed anywhere -- into JFrames, JApplets, JDialogs, JOptionPanes, other JPanels,... -- and so creating them from the start will improve the flexibility of your Swing coding. You don't have a class that overrides JFrame, and that's a good thing (there's usually no need for that, despite the sample codes that show this).
5) Do all Swing coding on the event dispatch thread or EDT. This is Swing's main thread that handles GUI painting and user interaction (i.e., keyboard and mouse). You would do this initially by calling your GUI creation code from within something like so (see the tutorials for details)
Code:
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
Converter converter = new Converter();
// assuming Converter and XxxConverter objects have the public methods below
converter.addToTabbedPane(new DistanceConverter().getPanel());
converter.addToTabbedPane(new TemperatureConverter().getPanel());
// assuming that Converter has a getPanel() method that returns a JPanel
JPanel converterPanel = converter.getPanel();
converterPanel.setPreferredSize(new Dimension(500, 500));
JFrame frame = new JFrame("Conversion Program");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPanel().add(converterPanel);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
});
edit: I'm at work and do not have access to a Java compiler. Above code may have mistakes.