Frame help

Please can someone help me with my programme. I am trying to get the code to compile so a frame is displayed. Could you have a look at my code and advise me further, thank you

package components;

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

class schoolgamescompetition

publicstaticvoid main (String args[]);

{

JFrame frame =new JFrame("FrameDemo");

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.getContentPane().add(emptyLabel, BorderLayout.CENTER);

frame.pack();

frame.setVisible(true);

}

[1020 byte] By [ultimate_novicea] at [2007-11-27 7:53:55]
# 1

> Please can someone help me with my programme. I am

> trying to get the code to compile so a frame is

> displayed. Could you have a look at my code and

> advise me further, thank you

>

> > package components;

>

> import javax.swing.*;

> import java.awt.*;

> import java.awt.event.*;

>

> class schoolgamescompetition

>

> public static void main (String args[]);

>

> {

>

> JFrame frame = new JFrame("FrameDemo");

> frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

> frame.getContentPane().add(emptyLabel,

> BorderLayout.CENTER);

> frame.pack();

> frame.setVisible(true);

>

> }

>

Try this:

public static void main (String args[]); ? whats the semi colomn doing there?

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

public class Demo extends JFrame{

JLabel emptyLabel;

public Demo(){

Container c = getContentPane();

JPanel p = new JPanel();

c.add(p);

emptyLabel = new JLabel("A label");

p.add(emptyLabel);

pack();

setVisible(true);

}

public static void main (String[] args){

new Demo();

}

}

deAppela at 2007-7-12 19:35:10 > top of Java-index,Java Essentials,New To Java...
# 2

Thanks for such a swift reply however i am still facing issues. please bear with me as i have only just started this programming langauge.

As my programme is called schoolgamescompetition.java how do i incorportae the code you gave me in to it? would it look as follows?

class schoolgamescompetition

public static void main (String args[])

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

public class Demo extends JFrame{

JLabel emptyLabel;

public Demo(){

Container c = getContentPane();

JPanel p = new JPanel();

c.add(p);

emptyLabel = new JLabel("A label");

p.add(emptyLabel);

pack();

setVisible(true);

}

public static void main (String[] args){

new Demo();

}

}

This still doesnt compile like that. I am sorry for having limited knowledge, i desperatly want to learn

thanks again

ultimate_novicea at 2007-7-12 19:35:10 > top of Java-index,Java Essentials,New To Java...
# 3

np,

try this:

[code]

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

public class schoolgamescompetition extends JFrame {

JLabel emptyLabel;

public schoolgamescompetition(){

Container c = getContentPane();

JPanel p = new JPanel();

c.add(p);

emptyLabel = new JLabel("A label");

p.add(emptyLabel);

pack();

setVisible(true);

}

public static void main (String[] args){

schoolgamescompetition sgc = new schoolgamescompetition();

}

}]/code]

Message was edited by:

deAppel

deAppela at 2007-7-12 19:35:10 > top of Java-index,Java Essentials,New To Java...
# 4

wow, thank you very much for that, it was evry kind of you! is there a way to set the size of the frame to remain a constant?

Also i have another question (the last one so dont worry)! what i want to know is; that frame will require buttons, do you suggest that when im doing my assignment i build the structure first such as frames and buttons and then do the coding to suit?

thanks for your time

ultimate_novicea at 2007-7-12 19:35:10 > top of Java-index,Java Essentials,New To Java...
# 5

np,

I suppose that could be a way to do it.

Anyway, added a sample button so feel free to play with it :)

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

public class schoolgamescompetition extends JFrame implements ActionListener{

JLabel emptyLabel;

JButton someButton;

public schoolgamescompetition(){

Container c = getContentPane();

JPanel p = new JPanel();

c.add(p);

emptyLabel = new JLabel("A label");

p.add(emptyLabel);

someButton = new JButton("Click here");

someButton.addActionListener(this);

p.add(someButton);

//pack();

setSize(100,100);

setResizable(true);

setVisible(true);

}

public static void main (String[] args){

schoolgamescompetition sgc = new schoolgamescompetition();

}

public void actionPerformed(ActionEvent e){

System.out.println("what your button should do..");

}

}

deAppela at 2007-7-12 19:35:10 > top of Java-index,Java Essentials,New To Java...