Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

really basic GUI question

 
Larry Reynolds
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to start writing a program and for now would be happy to get a window to display. I know that I can't create the window in a static method, not sure what to do to call the createGUI method, here's part of the code: Thanks again.

mport javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.*;

public class TestGrid {
public static void main(String[] args)
{
GridSquare[][] squares = new GridSquare[10][8];
setUpGrids(squares);

}
public void createGUI(){
JFrame frame = new JFrame("HelloWorldSwing");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JLabel label = new JLabel("Hello World");
frame.getContentPane().add(label);

frame.setSize(300,300);
frame.setVisible(true);
}
 
rob armstrong
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import javax.swing.*;

public class ClassNameHere extends JFrame
{
public static void main(String[] args)
{
new ClassNameHere();
}
public ClassNameHere()
{
this.setSize(200,100); //Sizing
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setTitle("Title of Window); //Top of the Box
this.setVisible(true); //make visible or you can't see it
}
}



Give that a try!
roba
 
Larry Reynolds
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It worked great! Thanks for your help.
[ January 08, 2006: Message edited by: Larry Reynolds ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic