-
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
-
Code:
public class GuiQuiz {}
{
-
:| 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
-
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();
}
}
-
very strange, I still can't get it to work ;/ thanks anyway
-
Hmmmm. Are you using the JDK to compile this?
-
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();
}
}
-
I am indeed, I selected to install it when I installed slackware linux.
-
Try the code I just posted above there... that gets a lot closer to compiling with javac for me
-
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
lol this is a nightmare, thank you so much for spending your time helping me.
-
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
-
thanks for your help sjalle works great now, I guess I just confused myself or something.
thanks again,
mr.gizm0
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
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
|
Bookmarks