TRYING TO CREATE A SIMPLE FORM. HELP HELP HELP!!!!  
Author Message
Newtboy2000





PostPosted: 2003-11-19 2:43:00 Top

java-programmer, TRYING TO CREATE A SIMPLE FORM. HELP HELP HELP!!!! trying to make a simple form, just an empty window with no button.

ive tried this


import javax.swing.*;
import java.awt.*;
import java.util.List;
import java.util.*;

public class Canvas
{

private static Canvas canvasSingleton;


public static Canvas getCanvas()
{
if(canvasSingleton == null) {
canvasSingleton = new Canvas("BlueJ Shapes Demo", 300, 300,
Color.white);
}
canvasSingleton.setVisible(true);
return canvasSingleton;
}


}



but it doesnt work :( any ideas guys?


 
Alex Hunsley





PostPosted: 2003-11-19 11:53:00 Top

java-programmer >> TRYING TO CREATE A SIMPLE FORM. HELP HELP HELP!!!! Newtboy2000 wrote:

> trying to make a simple form, just an empty window with no button.
>
> ive tried this
[snip code]

For a start, from what I can see you're trying to use java.awt.Canvas,
but your class is also called Canvas. Give your class a unique name that
doesn't clash with existing java classes, e.g. call it SimpleForm.
Secondly, a canvas can't just exist on its own as a top level window.
If you're wanting to create a window, make a new JFrame object, and call
show() on that.
For example:

import javax.swing.*;

public class JFrameTester {

public static void main(String[] args) {

JFrame myFrame = new JFrame("My JFrame");
myFrame.setSize(250, 250);
myFrame.setLocation(300,200);
myFrame.getContentPane().add("Center", new JTextArea(10, 40));
myFrame.show();
}
}


To get more picky on code design, as a side note: a method called
getCanvas() shouldn't have a side effect like causing a canvas to be
shown. getCanvas should do what the name says and not much else - it
should just get the canvas.


alex