yet, not what I was having in mind..
I'm an experienced MS Visual Basic developer and I can find tons of directories hosting source codes for simple applications (eg. planet-source-code.com).
Whenever I try looking something like that for Java, all I can find are applets but no standalone applications...
> yet, not what I was having in mind..
What did you have in mind then?
> I'm an experienced MS Visual Basic developer and I
> can find tons of directories hosting source codes for
> simple applications (eg. planet-source-code.com).
I don't see the relation between experienced MS Visual Basic and people who find tons of directories hosting source codes for simple applications.
> Whenever I try looking something like that for Java,
> all I can find are applets but no standalone
> applications...
Then you're not looking hard enough. The link Kaj posted is no applet.
Copied the following app from http://java.sun.com/docs/books/tutorial/uiswing/
/**
* CelsiusConverter.java is a 1.4 application that
* demonstrates the use of JButton, JTextField and
* JLabel. It requires no other files.
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class CelsiusConverter implements ActionListener {
JFrame converterFrame;
JPanel converterPanel;
JTextField tempCelsius;
JLabel celsiusLabel, fahrenheitLabel;
JButton convertTemp;
public CelsiusConverter() {
//Create and set up the window.
converterFrame = new JFrame("Convert Celsius to Fahrenheit");
converterFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
converterFrame.setSize(new Dimension(120, 40));
//Create and set up the panel.
converterPanel = new JPanel(new GridLayout(2, 2));
//Add the widgets.
addWidgets();
//Set the default button.
converterFrame.getRootPane().setDefaultButton(convertTemp);
//Add the panel to the window.
converterFrame.getContentPane().add(converterPanel, BorderLayout.CENTER);
//Display the window.
converterFrame.pack();
converterFrame.setVisible(true);
}
/**
* Create and add the widgets.
*/
private void addWidgets() {
//Create widgets.
tempCelsius = new JTextField(2);
celsiusLabel = new JLabel("Celsius", SwingConstants.LEFT);
convertTemp = new JButton("Convert");
fahrenheitLabel = new JLabel("Fahrenheit", SwingConstants.LEFT);
//Listen to events from the Convert button.
convertTemp.addActionListener(this);
//Add the widgets to the container.
converterPanel.add(tempCelsius);
converterPanel.add(celsiusLabel);
converterPanel.add(convertTemp);
converterPanel.add(fahrenheitLabel);
celsiusLabel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
fahrenheitLabel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
}
public void actionPerformed(ActionEvent event) {
//Parse degrees Celsius as a double and convert to Fahrenheit.
int tempFahr = (int)((Double.parseDouble(tempCelsius.getText()))
* 1.8 + 32);
fahrenheitLabel.setText(tempFahr + " Fahrenheit");
}
/**
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event-dispatching thread.
*/
private static void createAndShowGUI() {
//Make sure we have nice window decorations.
JFrame.setDefaultLookAndFeelDecorated(true);
CelsiusConverter converter = new CelsiusConverter();
}
public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
Good luck.