3 Replies - 547 Views - Last Post: 26 July 2012 - 03:35 PM Rate Topic: -----

#1 Diablovodkashot  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 07-August 11

BASIC GUI HELP

Posted 26 July 2012 - 07:18 AM

Hey guys,

I have been following this tutorial http://www.dreaminco...torial-in-java/

and i have been using netbeans to do it, anyone care to tell me why it is compiling with loads of errors and nothing happens, please keep in mind its my first program using netbeans i normally use cmd but i don't think you can use it with this tutorial.

Attached is my source:
import javax.swing.*;
import java.awt.*;

//Main Class
public class gui1 {
	//Variables
	static JFrame frame1;
	static Container pane;
	static JButton btnConnect, btnDisconnect;
	static JLabel lblServer, lblUsername, lvlPassword, lblPort;
	static JTextField txtServer, txtUsername, txtPassword, txtPort;
	static Insets insets;

	public static void main (String args[]){
		//create the frame
		frame1 = new JFrame("Same GUI Application");
		//Set the Size
		frame1.setSize(800,200);
		//Prepare Panel
		pane = frame1.getContentPane();
		insets = pane.getInsets();
		//Apply the null layout.
		pane.setLayout(null);

		//Creating the Component ( Controls)
		btnConnect = new JButton("Connect");
		btnDisconnect = new JButton("Disconnect");
		lblServer = new JLabel("Remote Host:");
		lblUsername = new JLabel("Username:");
		//lblPassword = new JLabel("Password:");
		lblPort = new JLabel("Port #:");
		txtServer = new JTextField(10);
		txtUsername = new JTextField (10);
		txtPassword = new JTextField (10);
		txtPort = new JtextField (5);

		//Placing the Component
		pane.add(lblServer);//Adds that component to the panel
		pane.add(lblUsername);
		//pane.add(lblPassword);
		pane.add(lblPort);
		pane.add(txtServer);
		pane.add(txtUsername);
		pane.add(txtPassword);
		pane.add(txtPort);
		pane.add(btnConnect);
		pane.add(btnDisconnect);

lblServer.setBounds(insets.left + 5, insets.top + 5, lblServer.getPreferredSize().width, lvlServer.getPreferredSize().height);
txtServer.setBounds (lblServer.getX() + lblServer.getWidth() + 5, insets.top + 5, txtServer.getPreferredSize().width, txtServer.getPreferredSize().height);

lblUsername.setBounds (txtServer.getX() + txtServer.getWidth() + 5, insets.top + 5, lblUsername.getPreferredSize().width, lblUsername.getPreferredSize().height);
txtUsername.setBounds (lblUsername.getX() + lblUsername.getWidth() + 5, insets.top + 5, txtUsername.getPreferredSize().width, txtUsername.getPreferredSize().height);

//lblPassword.setBounds (txtUsername.getX() + txtUsername.getWidth() + 5, insets.top + 5, lblPassword.getPreferredSize().width, lblPassword.getPreferredSize().height);
//txtPassword.setBounds (lblPassword.getX() + lblPassword.getWidth() + 5, insets.top + 5, txtPassword.getPreferredSize().width, txtPassword.getPreferredSize().height);

lblPort.setBounds (txtUsername.getX() + txtUsername.getWidth() + 5, insets.top + 5, lblPort.getPreferredSize().width, lblPort.getPreferredSize().height);
txtPort.setBounds (lblPort.getX() + lblPort.getWidth() + 5, insets.top + 5, txtPort.getPreferredSize().width, txtPort.getPreferredSize().height);

btnConnect.setBounds (txtPort.getX() + txtPort.getWidth() + 5, insets.top + 5, btnConnect.getPreferredSize().width, btnConnect.getPreferredSize().height);

	//Place disconnect button (start a new line!)
btnDisconnect.setBounds (insets.left + 15, lblServer.getY() + lblServer.getHeight() + 5, btnDisconnect.getPreferredSize().width, btnDisconnect.getPreferredSize().height);

	//Makes it Visible
	frame1.setVisible(true);
	}

}


Is This A Good Question/Topic? 0
  • +

Replies To: BASIC GUI HELP

#2 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2198
  • View blog
  • Posts: 5,226
  • Joined: 10-September 10

Re: BASIC GUI HELP

Posted 26 July 2012 - 07:49 AM

Post your errors, copied and pasted in code tags if there are a lot of them.
Was This Post Helpful? 0
  • +
  • -

#3 Diablovodkashot  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 07-August 11

Re: BASIC GUI HELP

Posted 26 July 2012 - 03:24 PM

Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous ctor sym type: <any>
at gui1.main(gui1.java:35)
Java Result: 1
BUILD SUCCESSFUL (total time: 5 seconds)

this is my error in netbeans not really fully worked netbeans since i have only just moved from cmd but when i run this in cmd i get 13 errors shall i post them?
Was This Post Helpful? 0
  • +
  • -

#4 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2198
  • View blog
  • Posts: 5,226
  • Joined: 10-September 10

Re: BASIC GUI HELP

Posted 26 July 2012 - 03:35 PM

Line 35 jtextField should be JTextField
Line 49 lvlServer should be lblServer

These are simple typos that NetBeans should be pointing out to you. Learn how to use it.

Fix those errors and you program will compile and run.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1