Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

really basic GUI question  RSS feed

 
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);
}
 
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 ]
 
look! it's a bird! it's a plane! It's .... a teeny tiny ad
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!