First time using GUI's

Confused about classes when using GUI's

Page 1 of 1

4 Replies - 896 Views - Last Post: 05 November 2008 - 06:49 AM Rate Topic: -----

#1 markhazlett9  Icon User is offline

  • Coding is a lifestyle
  • member icon

Reputation: 60
  • View blog
  • Posts: 1,666
  • Joined: 12-July 08

First time using GUI's

Post icon  Posted 04 November 2008 - 10:47 PM

Hello everyone,

I'm just learning Gui's for the first time and I can't seem to figure them out. I'm just starting with a very simple window, a text box and a button. I'm not doing listeners yet but just trying to display it and i'm stuck... here is my code...

import javax.swing.*;


public class BasicGui 
{
	public static void main(String[] args)
	{	
		SimpleWindow OneWindow = new SimpleWindow();

	}
}
	public class SimpleWindow extends JFrame
	{
		private JPanel Panel;
		private JLabel Label;
		private JTextField TextField;
		private JButton Button;
		
		public Window
		{
			//Create the default window sizes
			final int WINDOWWIDTH = 900;
			final int WINDOWHEIGHT = 850;
			
				
			//create a window
			JFrame Window = new JFrame();
			
			//Set the title for the window
			window.setTitle("Web Browser");
			
			//Set the window Size
			window.setSize(WINDOWWIDTH, WINDOWHEIGHT);
			
			//set what happens when the user closes the window
			window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			
			BuildPanel();
			
			add(Panel);
			
			//Display the window
			window.setVisible(true);
		}
		
		
		
		private void BuildPanel()
		{
			//create a label to display instructions
			Label = new JLabel("TextBox");
			
			//create a 100 character text field
			TextField = new JTextField(100);
			
			//create a Go button
			Button = new JButton("Go");
			
			//create the JPanel Object and let the panel field reference it
			Panel = new JPanel();
			
			Panel.add(Label);
			Panel.add(TextField);
			Panel.add(Button);
		}
		
	}


I can't compile it. I believe it's with my classes but i'm not too sure. Any help would be greatly appreciated

Is This A Good Question/Topic? 0
  • +

Replies To: First time using GUI's

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: First time using GUI's

Posted 04 November 2008 - 10:56 PM

public class SimpleWindow extends JFrame

you cannot have a public class inside a class... it has to be private

public Window

what is that... a constructor ? It should be for SimpleWindow not for window.. and it cannot be public
Was This Post Helpful? 0
  • +
  • -

#3 markhazlett9  Icon User is offline

  • Coding is a lifestyle
  • member icon

Reputation: 60
  • View blog
  • Posts: 1,666
  • Joined: 12-July 08

Re: First time using GUI's

Posted 04 November 2008 - 11:09 PM

View Postpbl, on 4 Nov, 2008 - 09:56 PM, said:

public class SimpleWindow extends JFrame

you cannot have a public class inside a class... it has to be private

public Window

what is that... a constructor ? It should be for SimpleWindow not for window.. and it cannot be public



Right on thanks pbl for your input... I changed some things around. The public window was a constructor yes. However i'm still getting some compilation errors. These 3 lines...

SimpleWindow OneWindow = new SimpleWindow();


private class SimpleWindow extends JFrame


and...

private SimpleWindow


Any Suggestions?
Was This Post Helpful? 0
  • +
  • -

#4 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: First time using GUI's

Posted 04 November 2008 - 11:38 PM

View Postmarkhazlett9, on 4 Nov, 2008 - 10:09 PM, said:

View Postpbl, on 4 Nov, 2008 - 09:56 PM, said:

public class SimpleWindow extends JFrame

you cannot have a public class inside a class... it has to be private

public Window

what is that... a constructor ? It should be for SimpleWindow not for window.. and it cannot be public



Right on thanks pbl for your input... I changed some things around. The public window was a constructor yes. However i'm still getting some compilation errors. These 3 lines...

SimpleWindow OneWindow = new SimpleWindow();


private class SimpleWindow extends JFrame


and...

private SimpleWindow

repost your corrected code

Any Suggestions?


Repost your code

This post has been edited by pbl: 05 November 2008 - 07:15 AM

Was This Post Helpful? 0
  • +
  • -

#5 Onker  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 51
  • Joined: 15-July 08

Re: First time using GUI's

Posted 05 November 2008 - 06:49 AM

Post your updated code version, and if possible the compilation errors as well.
What system are you using for your work also, some are slightly more informative/intuitive than others.

If this is for a class, I'm curious as to which text you're using also. A lot of this semesters classes in a large number of universities have shifted away from Lewis & Loftus Java book to something else. If you can snag a copy of the Lewis & Loftus book, you can find a lot of very very good examples of Java code in there. I <3 my L&L book.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1