DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 12 of 12

Hybrid View

  1. #1
    Join Date
    Apr 2005
    Posts
    6

    Swing Curley Brackets Problem

    Hi all, I decided to have a go at writing a gui for today for a quiz program, in swing, and I can't get my head around the errors I've tried every combination of extra brackets possible and none seem to many any difference. I Just want the gui to appear for now, but i'm getting this error
    g@(gizywig) javac test.java
    test.java:20: '{' expected
    public class GuiQuiz()
    ^
    test.java:57: '}' expected
    ^
    2 errors
    and I cant for the devil of me work it out, if someone could point me in the right direction I would be very grateful. here's my source code:


    Code:
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    
    public class GuiQuiz extends JFrame
    {
    	
    	private JLabel MenuLabel;
    	private JLabel QuestionsLabel;
    	private JTextArea Display;
    	private JScrollPane jScrollPane1;
    	private JTextArea jTextArea2;
    	private JScrollPane jScrollPane2;
    	private JButton BeginQuiz;
    	private JPanel contentPane;
    
    	public class GuiQuiz()
    	{
    	
    		setTitle("SwingQuiz");
    		setLocation(new Point(2, 5));
    		setSize(new Dimension(471, 535));
                    MenuLabel.setBounds(75,11,80,18);
    		MenuLabel = new JLabel();
    		QuestionsLabel = new JLabel();
    		Display = new JTextArea();
    		jScrollPane1 = new JScrollPane();
    		jTextArea2 = new JTextArea();
    		jScrollPane2 = new JScrollPane();
    		BeginQuiz = new JButton();
    		contentPane = (JPanel)this.getContentPane();
             	MenuLabel.setText("Menu Selection");
    		QuestionsLabel.setText("Questions");
                    BeginQuiz.setText("Begin Quiz");
    		jScrollPane1.setViewportView(Display);
    		jScrollPane2.setViewportView(jTextArea2);
    		contentPane.setLayout(null);
    		contentPane.MenuLabel.setBounds(75,11,80,18);
    		contentPane.QuestionsLabel.setBounds(270,13,60,18);
    		contentPane.jScrollPane1.setBounds(228,40,214,265);
    		contentPane.jScrollPane2.setBounds(29,341,403,160);
    		contentPane.BeginQuiz.setBounds(58,36,133,42);
    
    this.setVisible(true);
    }
    public static void main(String args[])
    {
    new GuiQuiz();
    }
    }
    thanks alot mr.gizm0

  2. #2
    Join Date
    Aug 2004
    Location
    Dublin, Ireland
    Posts
    63
    Code:
    public class GuiQuiz {}
    	{
    VBForums.com & DevX.com Super Moderator
    Microsoft MVP : Visual Developer - Visual Basic
    My Website

  3. #3
    Join Date
    Apr 2005
    Posts
    6
    :| are you sure you can use that syntax?

    g@(gizywig) javac test2.java
    test2.java:17: ';' expected
    public test2 GuiQuiz{}
    ^
    1 error
    thanks for trying to help me anyway

  4. #4
    Join Date
    Aug 2004
    Location
    Dublin, Ireland
    Posts
    63
    This compiles fine for me...

    Code:
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    
    public class GuiQuiz extends JFrame
    {
    	
    	private JLabel MenuLabel;
    	private JLabel QuestionsLabel;
    	private JTextArea Display;
    	private JScrollPane jScrollPane1;
    	private JTextArea jTextArea2;
    	private JScrollPane jScrollPane2;
    	private JButton BeginQuiz;
    	private JPanel contentPane;
    
    	public class GuiQuiz {}
    	{
    	
    		setTitle("SwingQuiz");
    		setLocation(new Point(2, 5));
    		setSize(new Dimension(471, 535));
    		MenuLabel.setBounds(75,11,80,18);
    		MenuLabel = new JLabel();
    		QuestionsLabel = new JLabel();
    		Display = new JTextArea();
    		jScrollPane1 = new JScrollPane();
    		jTextArea2 = new JTextArea();
    		jScrollPane2 = new JScrollPane();
    		BeginQuiz = new JButton();
    		contentPane = (JPanel)this.getContentPane();
    		MenuLabel.setText("Menu Selection");
    		QuestionsLabel.setText("Questions");
    		BeginQuiz.setText("Begin Quiz");
    		jScrollPane1.setViewportView(Display);
    		jScrollPane2.setViewportView(jTextArea2);
    		contentPane.setLayout(null);
    		contentPane.MenuLabel.setBounds(75,11,80,18);
    		contentPane.QuestionsLabel.setBounds(270,13,60,18)  ;
    		contentPane.jScrollPane1.setBounds(228,40,214,265)  ;
    		contentPane.jScrollPane2.setBounds(29,341,403,160)  ;
    		contentPane.BeginQuiz.setBounds(58,36,133,42);
    
    		this.setVisible(true);
    	}
    		public static void main(String args[])
    		{
    			new GuiQuiz();
    		}
    	}
    VBForums.com & DevX.com Super Moderator
    Microsoft MVP : Visual Developer - Visual Basic
    My Website

  5. #5
    Join Date
    Apr 2005
    Posts
    6
    very strange, I still can't get it to work ;/ thanks anyway

  6. #6
    Join Date
    Aug 2004
    Location
    Dublin, Ireland
    Posts
    63
    Hmmmm. Are you using the JDK to compile this?
    VBForums.com & DevX.com Super Moderator
    Microsoft MVP : Visual Developer - Visual Basic
    My Website

  7. #7
    Join Date
    Apr 2005
    Posts
    6
    I am indeed, I selected to install it when I installed slackware linux.

  8. #8
    Join Date
    Aug 2004
    Location
    Dublin, Ireland
    Posts
    63
    Sorry. Brainfade. Try this...

    Code:
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    
    public class GuiQuiz extends JFrame
    {
    	
    	private JLabel MenuLabel;
    	private JLabel QuestionsLabel;
    	private JTextArea Display;
    	private JScrollPane jScrollPane1;
    	private JTextArea jTextArea2;
    	private JScrollPane jScrollPane2;
    	private JButton BeginQuiz;
    	private JPanel contentPane;
    
    	GuiQuiz ()
    	{
    		setTitle("SwingQuiz");
    		setLocation(new Point(2, 5));
    		setSize(new Dimension(471, 535));
    		MenuLabel.setBounds(75,11,80,18);
    		MenuLabel = new JLabel();
    		QuestionsLabel = new JLabel();
    		Display = new JTextArea();
    		jScrollPane1 = new JScrollPane();
    		jTextArea2 = new JTextArea();
    		jScrollPane2 = new JScrollPane();
    		BeginQuiz = new JButton();
    		contentPane = (JPanel)this.getContentPane();
    		MenuLabel.setText("Menu Selection");
    		QuestionsLabel.setText("Questions");
    		BeginQuiz.setText("Begin Quiz");
    		jScrollPane1.setViewportView(Display);
    		jScrollPane2.setViewportView(jTextArea2);
    		contentPane.setLayout(null);
    		contentPane.MenuLabel.setBounds(75,11,80,18);
    		contentPane.QuestionsLabel.setBounds(270,13,60,18);
    		contentPane.jScrollPane1.setBounds(228,40,214,265);
    		contentPane.jScrollPane2.setBounds(29,341,403,160);
    		contentPane.BeginQuiz.setBounds(58,36,133,42);
    
    		this.setVisible(true);
    	}
    	public static void main(String args[])
    	{
    		new GuiQuiz();
    	}
    }
    VBForums.com & DevX.com Super Moderator
    Microsoft MVP : Visual Developer - Visual Basic
    My Website

  9. #9
    Join Date
    Aug 2004
    Location
    Dublin, Ireland
    Posts
    63
    Try the code I just posted above there... that gets a lot closer to compiling with javac for me
    VBForums.com & DevX.com Super Moderator
    Microsoft MVP : Visual Developer - Visual Basic
    My Website

  10. #10
    Join Date
    Apr 2005
    Posts
    6
    still not working, but thanks again lol, is this correct "contentPane.jScrollPane2.setBounds" i tried what you suggested and i got alot of errors which had ^'s point at contentPane so I removed contentPane and then it compiled from that I try and run and I get

    g@(gizywig) java GuiQuiz
    Exception in thread "main" java.lang.NullPointerException
    at GuiQuiz.<init>(GuiQuiz.java:22)
    at GuiQuiz.main(GuiQuiz.java:47)
    cat -n reveals 22 is
    MenuLabel.setBounds(75,11,80,18);
    and 47 is
    new GuiQuiz();
    lol this is a nightmare, thank you so much for spending your time helping me.

  11. #11
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    Im not sure what the trouble was here, but this:

    Code:
    contentPane.MenuLabel.setBounds(75,11,80,18);
    contentPane.QuestionsLabel.setBounds(270,13,60,18)  ;
    contentPane.jScrollPane1.setBounds(228,40,214,265)  ;
    contentPane.jScrollPane2.setBounds(29,341,403,160)  ;
    contentPane.BeginQuiz.setBounds(58,36,133,42);
    implies that the components are properties of the
    contentpane, which they are not.

    I removed those and shifted the component creation around a little, and now
    it works,..... well it compiles ans displays ...

    Code:
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    
    public class GuiQuiz
        extends JFrame {
    
      private JLabel MenuLabel=new JLabel();
      private JLabel QuestionsLabel=new JLabel();
      private JTextArea Display;
      private JScrollPane jScrollPane1=new JScrollPane();
      private JTextArea jTextArea2= new JTextArea();
      private JScrollPane jScrollPane2= new JScrollPane();
      private JButton BeginQuiz= new JButton();
    
    
      public GuiQuiz() {
        setTitle("SwingQuiz");
        setLocation(new Point(2, 5));
        setSize(new Dimension(471, 535));
        MenuLabel.setBounds(75, 11, 80, 18);
    
        MenuLabel.setText("Menu Selection");
        QuestionsLabel.setText("Questions");
        BeginQuiz.setText("Begin Quiz");
        jScrollPane1.setViewportView(Display);
        jScrollPane2.setViewportView(jTextArea2);
        getContentPane().setLayout(null);
        getContentPane().add(MenuLabel);
        getContentPane().add(jScrollPane1);
        getContentPane().add(jScrollPane2);
        getContentPane().add(BeginQuiz);
    
        MenuLabel.setBounds(75, 11, 80, 18);
        QuestionsLabel.setBounds(270, 13, 60, 18);
        jScrollPane1.setBounds(228, 40, 214, 265);
        jScrollPane2.setBounds(29, 341, 403, 160);
        BeginQuiz.setBounds(58, 36, 133, 42);
    
        this.setVisible(true);
      }
    
      public static void main(String args[]) {
        new GuiQuiz();
      }
    }
    eschew obfuscation

  12. #12
    Join Date
    Apr 2005
    Posts
    6
    thanks for your help sjalle works great now, I guess I just confused myself or something.
    thanks again,

    mr.gizm0

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links