learning swing at the moment and was following a tutorial off the sun website, made mine with eclipse instead of netbeans. but all I get when I try to run it is the following in the Console window:
gap= 4
gap= 0

Not sure what is going on here. I am pretty sure it is something small as I followed the tutorial bang on, any help would be great. Thanks

package learn;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class CelsiusConverterGUI extends JFrame {
	public CelsiusConverterGUI() {

	private void button1ActionPerformed(ActionEvent e) {
	    //Parse degrees Celsius as a double and convert to Fahrenheit.
	    int tempFahr = (int)((Double.parseDouble(tempTextField.getText()))
	            * 1.8 + 32);
	    fahrenheitLabel.setText(tempFahr + " Fahrenheit");


	private void initComponents() {
		celsiusLabel = new JLabel();
		fahrenheitLabel = new JLabel();
		tempTextField = new JTextField();
		button1 = new JButton();

		//======== this ========
		setTitle("Celsius Converter");
		Container contentPane = getContentPane();

		//---- celsiusLabel ----
		celsiusLabel.setText("Celsius ");
		celsiusLabel.setFont(celsiusLabel.getFont().deriveFont(celsiusLabel.getFont().getStyle() | Font.BOLD));

		//---- fahrenheitLabel ----
		fahrenheitLabel.setFont(fahrenheitLabel.getFont().deriveFont(fahrenheitLabel.getFont().getStyle() | Font.BOLD));

		//---- button1 ----
		button1.setFont(button1.getFont().deriveFont(button1.getFont().getStyle() | Font.BOLD));
		button1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {

		GroupLayout contentPaneLayout = new GroupLayout(contentPane);
						.addComponent(button1, GroupLayout.DEFAULT_SIZE, 124, Short.MAX_VALUE)
						.addComponent(tempTextField, GroupLayout.DEFAULT_SIZE, 124, Short.MAX_VALUE))
					.addGroup(contentPaneLayout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
						.addComponent(celsiusLabel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
						.addComponent(fahrenheitLabel, GroupLayout.DEFAULT_SIZE, 66, Short.MAX_VALUE))
					.addGap(23, 23, 23)
						.addComponent(tempTextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
					.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))

	private JLabel celsiusLabel;
	private JLabel fahrenheitLabel;
	private JTextField tempTextField;
	private JButton button1;
9 Years
Discussion Span
Last Post by BestJewSinceJC

Yes , I thought it was strange without a main so I tried inserting the public void main... a few different ways but still could not get it to work - could you tell me how you would incorporate a main method into this program? Thanks for the help


> few different ways
And what were they ?

>how you would incorporate a main method into this program?
By writing:

public static void main(String [] args)

Yes, I put that in underneath where i declare my main class with the proper curly brackets, didn't work. I put it in at the bottom and tried to get the main to call the class I had just made and a few other ways but couldn't figure out the proper way. I knew the code just did not know where to put it or what to write in my main function...

private JLabel celsiusLabel;
private JLabel fahrenheitLabel;
private JTextField tempTextField;
private JButton button1;

public static void main(String [] args){
    new CelsiusConverterGUI();

"Made mine with eclipse instead of netbeans"

What do you mean by that? I'd suggest you don't follow any tutorials meant to be used with netbeans if you're using Eclipse. The sun tutorials are good but if you look at all of the examples they provide, they provide the full code. You should try doing some simple tasks on whatever tutorial you happen to be viewing and make sure you can perform simple tasks yourself. For example, make sure you can make a button do something when it is clicked.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.